12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $TOG: Editor.c /main/24 1999/10/14 16:38:25 mgreess $
- **********************************<+>*************************************
- ***************************************************************************
- **
- ** File: Editor.c
- **
- ** Project: Text Editor widget
- **
- ** Description:
- ** -----------
- ** This is the main source file for the Text Editor widget.
- **
- *******************************************************************
- * (c) Copyright 1996 Digital Equipment Corporation.
- * (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company.
- * (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
- * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
- * (c) Copyright 1996 Novell, Inc.
- * (c) Copyright 1996 FUJITSU LIMITED.
- * (c) Copyright 1996 Hitachi.
- * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
- ********************************************************************
- **
- **************************************************************************
- **********************************<+>*************************************/
- /*-------------------------------------------------------------
- ** Include Files
- */
- #include <ctype.h>
- #if defined(__hpux) || defined(__osf__) || defined(USL)
- # include <wchar.h>
- #elif defined(__uxp__)
- # include <widec.h>
- # include <wctype.h>
- #elif defined(sun)
- # if (_XOPEN_VERSION==3)
- # include <wctype.h>
- # else
- # include <wchar.h>
- # endif
- # include <libintl.h>
- #elif defined(linux)
- # include <wctype.h>
- # define NO_putwc
- #elif defined(CSRG_BASED)
- # include <wctype.h>
- # include <wchar.h>
- #endif /* linux */
- #include <sys/wait.h>
- #include "signal.h"
- #include <string.h>
- #include <limits.h> /* For LINE_MAX definition */
- #include <sys/errno.h> /* For Error handling */
- #include "EditorP.h"
- #include <Dt/Dnd.h>
- #include "X11/Xutil.h"
- #include <X11/StringDefs.h>
- #include <X11/keysymdef.h>
- #include <Xm/Form.h>
- #include <Xm/MessageB.h>
- #include <Xm/MwmUtil.h>
- #include <Xm/TextF.h>
- #include <Xm/LabelG.h>
- #include <Xm/SeparatoG.h>
- #include <Xm/PushBG.h>
- #include <Xm/ToggleBG.h>
- #include <Xm/RowColumn.h>
- /* Need the following for _DtOkString */
- #include <Dt/DtP.h>
- #include <Dt/DtMsgsP.h>
- #include <Dt/HourGlass.h>
- #include "DtWidgetI.h"
- /*
- * Private functions borrowed from Motif.
- */
- extern XmTextLineTable _XmTextGetLineTable(Widget widget, int *total_lines);
- extern char * _XmStringSourceGetString(XmTextWidget tw,
- XmTextPosition from,
- XmTextPosition to,
- #if NeedWidePrototypes
- int want_wchar);
- #else
- Boolean want_wchar);
- #endif /* NeedWidePrototypes */
- /*-------------------------------------------------------------
- ** Public Interface
- **-------------------------------------------------------------
- */
- /******** Public Function Declarations ********/
- /******** End Public Function Declarations ********/
- /*-------------------------------------------------------------
- ** Forward Declarations
- **-------------------------------------------------------------
- */
- /******** Static Function Declarations ********/
- static void ClassInitialize(void);
- static void Initialize(
- Widget rw,
- Widget nw,
- ArgList al,
- Cardinal *num_args) ;
- static void VariableInitialize(
- DtEditorWidget new);
- static void ValidateResources(
- DtEditorWidget new,
- DtEditorWidget request);
- static Widget CreateText(
- DtEditorWidget parent);
- static void extractFontMetrics(
- DtEditorWidget w,
- XmFontList fontlist,
- int *height,
- int *width);
- static void getFontMetrics(
- DtEditorWidget w);
- static void Destroy(
- Widget widget);
- static void SetStatusLine(
- DtEditorWidget ew,
- Boolean statusLineOn);
- static Widget CreateStatusLine(
- DtEditorWidget parent);
- static Boolean SetValues(
- Widget cw,
- Widget rw,
- Widget nw);
- static void _DtEditorGetCenterToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetChangeAllButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetChangeButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetChangeFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetColumns(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetCurrentLineLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetCursorPosition(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetFindButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetFindFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetFormatAllButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetFormatParagraphButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetJustifyToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetLeftAlignToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetLeftMarginFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetMaxLength(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetMisspelledListLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetRightAlignToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetRightMarginFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetRows(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetScrollLeftSide(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetScrollTopSide(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetTextBackground(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetTextForeground(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetTopCharacter(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void _DtEditorGetLineCountLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value );
- static void FixWordWrap( /* XXX Word Wrap workaround */
- Widget w, /* XXX Word Wrap workaround */
- Boolean wrapOn); /* XXX Word Wrap workaround */
- static void BackwardChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void BackwardPara(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void BackwardWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void BeginningOfFile(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void BeginningOfLine(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ClearSelection(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void CopyClipboard(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void CutClipboard(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeleteNextChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeleteNextWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeletePrevChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeletePrevWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeleteToEOL(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeleteToSOL(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void DeselectAll(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void EndOfFile(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void EndOfLine(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ForwardChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ForwardPara(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ForwardWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void GoToLine(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void GoToLine_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void Help(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void InsertString(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void KeySelect(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void NewlineAndBackup(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void NewlineAndIndent(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void NextPage(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void PageLeft(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void PageRight(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void PasteClipboard(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void PreviousPage(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ProcessCancel(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ProcessDown(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ProcessShiftDown(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ProcessShiftUp(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ProcessUp(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void QuoteNextChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void QuoteNextChar_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void SelectAll(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ToggleInsertMode(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void ToggleInsertMode_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void UndoEdit(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void UndoEdit_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params);
- static void Call_TextSelectCallback(
- DtEditorWidget editor);
- static void Call_TextDeselectCallback(
- DtEditorWidget editor);
- static void Editor_SetSelectionProc(
- XmTextSource source,
- XmTextPosition left,
- XmTextPosition right,
- Time set_time );
- static void CallHelpCallback(
- DtEditorWidget editor,
- int reason);
- static void HelpEditWindowCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static void HelpStatusCurrentLineCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static void HelpStatusTotalLinesCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static void HelpStatusMessageCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static void HelpStatusOverstrikeCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static void RegisterDropZone(
- DtEditorWidget w );
- static void UnregisterDropZone(
- DtEditorWidget w );
- static void SetInfoDialogTitle(
- DtEditorWidget editor );
- static int FormatText (
- AdjRecPtr pAdjRec );
- static void AdjustParaCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static void AdjustAllCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data );
- static DtEditorErrorCode DoAdjust(
- DtEditorWidget editor,
- int leftMargin,
- int rightMargin,
- unsigned int alignment,
- XmTextPosition start,
- XmTextPosition end);
- static void SetFormatDialogTitle(
- DtEditorWidget editor);
- static void ResetFormatDialog(
- DtEditorWidget editor);
- static void CreateFormatDialog(
- DtEditorWidget editor);
- static void GetAdjustSettings(
- DtEditorWidget pPad,
- DtEditorFormatSettings *formatSettings);
- static void UpdateOverstrikeIndicator(
- DtEditorWidget widget,
- Boolean overstrikeOn );
- /******** End Static Function Declarations ********/
- /****************************************************************
- *
- * Compatability routines
- *
- ****************************************************************/
- #if defined(NO_putwc)
- static wint_t putwc(wint_t wc, FILE *stream)
- {
- int rc = putc((int) wc, stream);
- return (wint_t) rc;
- }
- static wint_t getwc(FILE *stream)
- {
- int rc = getc(stream);
- return (wint_t) rc;
- }
- #endif /* NO_putwc */
- /****************************************************************
- *
- * Translations and Actions
- *
- ****************************************************************/
- /*
- * The following are the translations which DtEditor places (overrides)
- * on the scrolled text widget. If the DtNtextTranslations resource is
- * set, it will also be added (in override mode) to the text widget.
- */
- static char EditorTranslationTable[] = "\
- ~s ~c ~m ~a <Key>Return: newline-and-indent()\n\
- ~s m<Key>osfBackSpace: I-undo-edit()\n\
- ~s c<Key>osfBackSpace: delete-previous-word()\n\
- s<Key>osfBackSpace: delete-to-start-of-line()\n\
- ~s ~c <Key>osfInsert: I-toggle-insert-mode()\n\
- <Key>osfUndo: I-undo-edit()\n\
- c<Key>g: I-go-to-line()\n\
- c<Key>q: I-quote-next-character()\n\
- c<Key>z: I-undo-edit()";
- /*
- * The following are DtEditor's actions. A few are internal only (_I
- * suffix) and will be called by the default translations DtEditor places
- * on the text widget (see previous comment). The rest will only be called
- * from an application with XtCallActionProc(). The main difference is
- * the internal ones will be passed a text widget ID, while the public
- * ones will be passed a DtEditor ID.
- */
- static XtActionsRec EditorActionTable[] = {
- {"I-go-to-line", (XtActionProc)GoToLine_I},
- {"I-toggle-insert-mode", (XtActionProc)ToggleInsertMode_I},
- {"I-undo-edit", (XtActionProc)UndoEdit_I},
- {"I-quote-next-character", (XtActionProc)QuoteNextChar_I},
- {"backward-character", (XtActionProc)BackwardChar},
- {"backward-paragraph", (XtActionProc)BackwardPara},
- {"backward-word", (XtActionProc)BackwardWord},
- {"beginning-of-file", (XtActionProc)BeginningOfFile},
- {"beginning-of-line", (XtActionProc)BeginningOfLine},
- {"clear-selection", (XtActionProc)ClearSelection},
- {"copy-clipboard", (XtActionProc)CopyClipboard},
- {"cut-clipboard", (XtActionProc)CutClipboard},
- {"delete-next-character", (XtActionProc)DeleteNextChar},
- {"delete-next-word", (XtActionProc)DeleteNextWord},
- {"delete-previous-character", (XtActionProc)DeletePrevChar},
- {"delete-previous-word", (XtActionProc)DeletePrevWord},
- {"delete-to-end-of-line", (XtActionProc)DeleteToEOL},
- {"delete-to-start-of-line", (XtActionProc)DeleteToSOL},
- {"deselect-all", (XtActionProc)DeselectAll},
- {"end-of-file", (XtActionProc)EndOfFile},
- {"end-of-line", (XtActionProc)EndOfLine},
- {"forward-character", (XtActionProc)ForwardChar},
- {"forward-paragraph", (XtActionProc)ForwardPara},
- {"forward-word", (XtActionProc)ForwardWord},
- {"go-to-line", (XtActionProc)GoToLine},
- {"Help", (XtActionProc)Help},
- {"insert-string", (XtActionProc)InsertString},
- {"key-select", (XtActionProc)KeySelect},
- {"newline-and-backup", (XtActionProc)NewlineAndBackup},
- {"newline-and-indent", (XtActionProc)NewlineAndIndent},
- {"next-page", (XtActionProc)NextPage},
- {"page-left", (XtActionProc)PageLeft},
- {"page-right", (XtActionProc)PageRight},
- {"paste-clipboard", (XtActionProc)PasteClipboard},
- {"previous-page", (XtActionProc)PreviousPage},
- {"process-cancel", (XtActionProc)ProcessCancel},
- {"process-down", (XtActionProc)ProcessDown},
- {"process-shift-down", (XtActionProc)ProcessShiftDown},
- {"process-shift-up", (XtActionProc)ProcessShiftUp},
- {"process-up", (XtActionProc)ProcessUp},
- {"quote-next-character", (XtActionProc)QuoteNextChar},
- {"select-all", (XtActionProc)SelectAll},
- {"toggle-insert-mode", (XtActionProc)ToggleInsertMode},
- {"undo-edit", (XtActionProc)UndoEdit},
- };
- /****************************************************************
- *
- * Defines
- *
- ****************************************************************/
- #define NL_SETN 1
- #ifdef _AIX
- #define iswctype(a,b) is_wctype(a,b)
- #define wctype(a) get_wctype(a)
- #endif /* _AIX */
- #if !(defined(sun) && (_XOPEN_VERSION==3))
- #if !(defined(__FreeBSD__))
- # define iswblank(wc) iswctype((wc),blnkclass)
- # undef getwc /* Use the libc function */
- #endif
- #if defined(__osf__) || defined(_AIX) /* __osf__ || _AIX */
- /* function prototype for wctype() was changed to meet spec1170 */
- /* digital compiler flagged warning */
- /* IBM defines wctype to get_wctype above - don't use const. */
- static char *blankString = "space";
- #elif defined(USL)
- # define wctype_t int
- #else /* __osf__ || _AIX */
- static const char *blankString = "space";
- #endif /* __osf__ || _AIX */
- static wctype_t _DtEditor_blankClass;
- #else
- # define wctype_t int
- # if defined(__uxp__)
- # if (OSMAJORVERSION < 2)
- typedef long wint_t ;
- # endif
- # define WEOF (-1)
- # endif /* uxp */
- # define iswblank(a) iswspace(a)
- # if !defined(__uxp__)
- # define iswctype(a,b) _iswctype(a,b)
- # endif
- # if defined(__uxp__)
- # define wcwidth(a) scrwidth(a)
- # else
- # define wcwidth(a) sun_wcwidth(a)
- # endif
- #endif /* not sun and not uxp */
- #define MAXTABSIZE 100 /* max legal tabsize */
- /****************************************************************
- *
- * Define misc data structures
- *
- ****************************************************************/
- static wctype_t ekinclass = 0; /* Prop value for "ekinsoku" class */
- static wctype_t bekinclass = 0; /* Prop value for "bekinsoku" class */
- static wctype_t blnkclass = 0; /* Prop value for "Blank" Class */
- /****************************************************************
- *
- * Resource List
- *
- ****************************************************************/
- static XmSyntheticResource syn_resources[] =
- {
- {
- DtNcolumns, sizeof(short),
- XtOffset (DtEditorWidget, editor.editStuff.columns),
- _DtEditorGetColumns, NULL
- },
- {
- DtNcenterToggleLabel, sizeof (XmString),
- XtOffset (DtEditorWidget, editor.formatStuff.centerToggleLabel),
- _DtEditorGetCenterToggleLabel, NULL
- },
- {
- DtNchangeAllButtonLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.searchStuff.changeAllButtonLabel),
- _DtEditorGetChangeAllButtonLabel, NULL
- },
- {
- DtNchangeButtonLabel, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.changeButtonLabel),
- _DtEditorGetChangeButtonLabel, NULL
- },
- {
- DtNchangeFieldLabel, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.changeFieldLabel),
- _DtEditorGetChangeFieldLabel, NULL
- },
- {
- DtNcurrentLineLabel, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.statusStuff.currentLineLabel),
- _DtEditorGetCurrentLineLabel, NULL
- },
- {
- DtNcursorPosition, sizeof (XmTextPosition),
- XtOffset(DtEditorWidget, editor.editStuff.cursorPos),
- _DtEditorGetCursorPosition, NULL
- },
- {
- DtNfindButtonLabel, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.findButtonLabel),
- _DtEditorGetFindButtonLabel, NULL
- },
- {
- DtNfindFieldLabel, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.findFieldLabel),
- _DtEditorGetFindFieldLabel, NULL
- },
- {
- DtNformatAllButtonLabel, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.formatAllButtonLabel),
- _DtEditorGetFormatAllButtonLabel, NULL
- },
- {
- DtNformatParagraphButtonLabel, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.formatParaButtonLabel),
- _DtEditorGetFormatParagraphButtonLabel, NULL
- },
- {
- DtNjustifyToggleLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.formatStuff.justifyToggleLabel),
- _DtEditorGetJustifyToggleLabel, NULL
- },
- {
- DtNleftAlignToggleLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.formatStuff.leftAlignToggleLabel),
- _DtEditorGetLeftAlignToggleLabel, NULL
- },
- {
- DtNleftMarginFieldLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.formatStuff.leftMarginFieldLabel),
- _DtEditorGetLeftMarginFieldLabel, NULL
- },
- {
- DtNmaxLength, sizeof(int),
- XtOffset(DtEditorWidget, editor.editStuff.maxLength),
- _DtEditorGetMaxLength, NULL
- },
- {
- DtNmisspelledListLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.searchStuff.misspelledListLabel),
- _DtEditorGetMisspelledListLabel, NULL
- },
- {
- DtNrightAlignToggleLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.formatStuff.rightAlignToggleLabel),
- _DtEditorGetRightAlignToggleLabel, NULL
- },
- {
- DtNrightMarginFieldLabel, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.formatStuff.rightMarginFieldLabel),
- _DtEditorGetRightMarginFieldLabel, NULL
- },
- {
- DtNrows, sizeof(short),
- XtOffset (DtEditorWidget, editor.editStuff.rows),
- _DtEditorGetRows, NULL
- },
- {
- DtNscrollLeftSide, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.scrollLeft),
- _DtEditorGetScrollLeftSide, NULL
- },
- {
- DtNscrollTopSide, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.scrollTop),
- _DtEditorGetScrollTopSide, NULL
- },
- {
- DtNtextBackground, sizeof(Pixel),
- XtOffset (DtEditorWidget, editor.editStuff.background),
- _DtEditorGetTextBackground, NULL
- },
- {
- DtNtextForeground, sizeof(Pixel),
- XtOffset (DtEditorWidget, editor.editStuff.foreground),
- _DtEditorGetTextForeground, NULL
- },
- {
- DtNtopCharacter, sizeof(XmTextPosition),
- XtOffset (DtEditorWidget, editor.editStuff.topCharacter),
- _DtEditorGetTopCharacter, NULL
- },
- {
- DtNtotalLineCountLabel, sizeof (XmString),
- XtOffset (DtEditorWidget, editor.statusStuff.totalLineLabel),
- _DtEditorGetLineCountLabel, NULL
- },
- };
- static XtResource resources[] =
- {
- {
- DtNautoShowCursorPosition,
- DtCAutoShowCursorPosition, XmRBoolean, sizeof (Boolean),
- XtOffset(DtEditorWidget,
- editor.editStuff.autoShowCursorPos),
- XmRImmediate, (XtPointer) True
- },
- {
- DtNbuttonFontList, DtCFontList, XmRFontList, sizeof(XmFontList),
- XtOffsetOf(struct _XmBulletinBoardRec,
- bulletin_board.button_font_list),
- XmRFontList, (XtPointer) NULL
- },
- {
- DtNblinkRate, DtCBlinkRate, XmRInt, sizeof(int),
- XtOffset(DtEditorWidget, editor.editStuff.blinkRate),
- XmRImmediate, (XtPointer) 500
- },
- {
- DtNcenterToggleLabel, DtCCenterToggleLabel,
- XmRXmString, sizeof (XmString),
- XtOffset (DtEditorWidget, editor.formatStuff.centerToggleLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNchangeAllButtonLabel, DtCChangeAllButtonLabel,
- XmRXmString, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.searchStuff.changeAllButtonLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNchangeButtonLabel, DtCChangeButtonLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.changeButtonLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNchangeFieldLabel, DtCChangeFieldLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.changeFieldLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNcolumns, DtCColumns, XmRShort, sizeof(short),
- XtOffset (DtEditorWidget, editor.editStuff.columns),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNcurrentLineLabel, DtCCurrentLineLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.statusStuff.currentLineLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNcursorPosition, DtCCursorPosition, XmRTextPosition,
- sizeof (XmTextPosition),
- XtOffset(DtEditorWidget, editor.editStuff.cursorPos),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNcursorPositionVisible, DtCCursorPositionVisible,
- XmRBoolean, sizeof (Boolean),
- XtOffset(DtEditorWidget,
- editor.editStuff.cursorPosVisible),
- XmRImmediate, (XtPointer) True
- },
- {
- DtNdialogTitle, DtCDialogTitle, XmRXmString, sizeof (XmString),
- XtOffsetOf(struct _XmBulletinBoardRec,
- bulletin_board.dialog_title),
- XmRString, (XtPointer) NULL
- },
- {
- DtNeditable, DtCEditable, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.editable),
- XmRImmediate, (XtPointer) True
- },
- {
- DtNfindButtonLabel, DtCFindButtonLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.findButtonLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNfindChangeDialogTitle, DtCFindChangeDialogTitle,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.fndChngTitle),
- XmRString, (XtPointer) NULL
- },
- {
- DtNfindFieldLabel, DtCFindFieldLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.findFieldLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNformatAllButtonLabel, DtCFormatAllButtonLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.formatAllButtonLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNformatParagraphButtonLabel, DtCFormatParagraphButtonLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.formatParaButtonLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNformatSettingsDialogTitle, DtCFormatSettingsDialogTitle,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.formatStuff.formatDialogTitle),
- XmRString, (XtPointer) NULL
- },
- {
- DtNinformationDialogTitle, DtCInformationDialogTitle,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.warningStuff.infoDialogTitle),
- XmRString, (XtPointer) NULL
- },
- {
- DtNinsertLabel, DtCInsertLabel, XmRXmString, sizeof (XmString),
- XtOffset (DtEditorWidget, editor.statusStuff.ins),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNjustifyToggleLabel, DtCJustifyToggleLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.formatStuff.justifyToggleLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNlabelFontList, DtCFontList, XmRFontList, sizeof(XmFontList),
- XtOffsetOf(struct _XmBulletinBoardRec,
- bulletin_board.label_font_list),
- XmRFontList, (XtPointer) NULL
- },
- {
- DtNleftAlignToggleLabel, DtCLeftAlignToggleLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.leftAlignToggleLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNleftMarginFieldLabel, DtCLeftMarginFieldLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.leftMarginFieldLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNmaxLength, DtCMaxLength, XmRInt, sizeof(int),
- XtOffset(DtEditorWidget, editor.editStuff.maxLength),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNmisspelledListLabel, DtCMisspelledListLabel,
- XmRXmString, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.searchStuff.misspelledListLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNoverstrike, DtCOverstrike, XmRBoolean, sizeof (Boolean),
- XtOffset(DtEditorWidget, editor.editStuff.overstrikeMode),
- XmRImmediate, (XtPointer) False
- },
- {
- DtNoverstrikeLabel, DtCOverstrikeLabel,
- XmRXmString, sizeof (XmString),
- XtOffset (DtEditorWidget, editor.statusStuff.ovr),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNrightAlignToggleLabel, DtCRightAlignToggleLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.rightAlignToggleLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNrightMarginFieldLabel, DtCRightMarginFieldLabel,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget,
- editor.formatStuff.rightMarginFieldLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNrows, DtCRows, XmRShort, sizeof(short),
- XtOffset (DtEditorWidget, editor.editStuff.rows),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNscrollHorizontal, DtCScroll, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.scrollHorizontal),
- XmRImmediate, (XtPointer) True
- },
- {
- DtNscrollLeftSide, DtCScrollSide, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.scrollLeft),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNscrollTopSide, DtCScrollSide, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.scrollTop),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNscrollVertical, DtCScroll, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.scrollVertical),
- XmRImmediate, (XtPointer) True
- },
- {
- DtNshowStatusLine,
- DtCShowStatusLine, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.statusStuff.showStatusLine),
- XmRImmediate, (XtPointer) False
- },
- {
- DtNspellDialogTitle, DtCSpellDialogTitle,
- XmRXmString, sizeof (XmString),
- XtOffset(DtEditorWidget, editor.searchStuff.spellTitle),
- XmRString, (XtPointer) NULL
- },
- {
- DtNspellFilter, DtCSpellFilter, XmRString, sizeof(XmRString),
- XtOffset (DtEditorWidget, editor.searchStuff.spellFilter),
- XmRString, "spell"
- },
- {
- DtNtextBackground, DtCBackground,
- XmRPixel, sizeof(Pixel),
- XtOffset (DtEditorWidget, editor.editStuff.background),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNtextDeselectCallback,
- DtCCallback, XtRCallback, sizeof (XtCallbackList),
- XtOffset (DtEditorWidget, editor.textDeselect),
- XtRCallback, (XtPointer) NULL
- },
- {
- DtNtextForeground, DtCForeground,
- XmRPixel, sizeof(Pixel),
- XtOffset (DtEditorWidget, editor.editStuff.foreground),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNtextFontList, DtCFontList, XmRFontList, sizeof(XmFontList),
- XtOffsetOf(struct _XmBulletinBoardRec,
- bulletin_board.text_font_list),
- XmRFontList, (XtPointer) NULL
- },
- {
- DtNtextSelectCallback,
- DtCCallback, XtRCallback, sizeof (XtCallbackList),
- XtOffset (DtEditorWidget, editor.textSelect),
- XtRCallback, (XtPointer) NULL
- },
- {
- DtNtextTranslations, DtCTranslations,
- XmRTranslationTable, sizeof (XtTranslations),
- XtOffsetOf(struct _XmBulletinBoardRec,
- bulletin_board.text_translations),
- XmRImmediate, (XtPointer) NULL
- },
- {
- DtNtopCharacter, DtCTopCharacter,
- XmRTextPosition, sizeof(XmTextPosition),
- XtOffset (DtEditorWidget, editor.editStuff.topCharacter),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNtotalLineCountLabel, DtCTotalLineCountLabel,
- XmRXmString, sizeof (XmString),
- XtOffset (DtEditorWidget,
- editor.statusStuff.totalLineLabel),
- XmRImmediate, (XtPointer) DtUNSPECIFIED
- },
- {
- DtNwordWrap,
- DtCWordWrap, XmRBoolean, sizeof (Boolean),
- XtOffset (DtEditorWidget, editor.editStuff.wordWrap),
- XmRImmediate, (XtPointer) False
- },
- };
- /****************************************************************
- *
- * Public Function Declarations
- *
- ****************************************************************/
- /****************************************************************
- *
- * Class Record
- *
- ****************************************************************/
- externaldef( dteditorclassrec ) DtEditorClassRec
- dtEditorClassRec =
- {
- /* Core Part
- */
- {
- (WidgetClass) &xmFormClassRec, /* superclass */
- "DtEditor", /* class_name */
- sizeof (DtEditorRec), /* widget_size */
- ClassInitialize, /* class_initialize */
- NULL, /* class_part_initialize*/
- False, /* class_inited */
- (XtInitProc) Initialize, /* initialize */
- NULL, /* initialize_hook */
- XtInheritRealize, /* realize */
- (XtActionList)EditorActionTable,/* actions */
- (Cardinal)XtNumber(EditorActionTable), /* num_actions */
- resources, /* resources */
- XtNumber (resources), /* num_resources */
- NULLQUARK, /* xrm_class */
- True, /* compress_motion */
- XtExposeCompressMaximal, /* compress_exposure */
- False, /* compress_enterleave */
- False, /* visible_interest */
- (XtWidgetProc) Destroy, /* destroy */
- XtInheritResize, /* resize */
- XtInheritExpose, /* expose */
- (XtSetValuesFunc) SetValues, /* set_values */
- NULL, /* set_values_hook */
- XtInheritSetValuesAlmost, /* set_values_almost */
- NULL, /* get_values_hook */
- XtInheritAcceptFocus, /* accept_focus */
- XtVersion, /* version */
- NULL, /* callback private */
- XtInheritTranslations, /* tm_table */
- XtInheritQueryGeometry, /* query_geometry */
- (XtStringProc)NULL, /* display_accelerator */
- NULL, /* extension */
- },
- /* Composite Part
- */
- {
- XtInheritGeometryManager, /* geometry_manager */
- XtInheritChangeManaged, /* change_managed */
- XtInheritInsertChild, /* insert_child */
- XtInheritDeleteChild, /* delete_child */
- NULL, /* extension */
- },
- /* Constraint Part
- */
- {
- NULL, /* constraint_resources */
- 0, /* num_constraint_resource */
- sizeof(XmFormConstraintRec), /* size of constraint */
- NULL, /* initialization */
- NULL, /* constraint_destroy */
- NULL, /* constraint_set_values */
- NULL, /* extension */
- },
- /* XmManager Part
- */
- {
- XmInheritTranslations, /* default_translations */
- syn_resources, /* syn_resources */
- XtNumber(syn_resources), /* num_syn_resources */
- NULL, /* syn_cont_resources */
- 0, /* num_syn_cont_resources */
- XmInheritParentProcess, /* parent_process */
- NULL, /* extension */
- },
- /* XmbulletinBoard Part
- */
- {
- FALSE, /* always_install_accelerators */
- (XmGeoCreateProc)NULL, /* geo_matrix_create */
- XmInheritFocusMovedProc, /* focus_moved_proc */
- NULL, /* extension */
- },
- /* XmForm Part
- */
- {
- NULL, /* extension */
- },
- /* DtEditor Part
- */
- {
- 0, /* extension */
- }
- };
- WidgetClass dtEditorWidgetClass = (WidgetClass) &dtEditorClassRec;
- /*-------------------------------------------------------------
- ** Editor Procs
- **-------------------------------------------------------------
- */
- /****************************************************************
- *
- * Private Procs
- *
- ****************************************************************/
- /*-------------------------------------------------------------
- ** Function: static void ClassInitialize (void);
- **
- ** Parameters:
- **
- ** Purpose: This is the Editor class initializzation routine.
- ** It is called once, before the first instance
- ** is created.
- */
- static void
- ClassInitialize(void)
- {
- #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
- _DtEditor_blankClass = wctype(blankString);
- /*
- ** These calls determine if the particular value is True for
- ** the current locale. A value of -1 is returned if the locale
- ** does not support the charclass. If the locale supports the
- ** charclass, the return value is passed as a parameter to the
- ** iswctype call.
- */
- ekinclass = wctype("ekinsoku");
- bekinclass = wctype("bkinsoku");
- blnkclass = wctype("blank");
- #endif /* end not Sun */
- }
- /*-------------------------------------------------------------
- ** Function: static void Initialize (
- ** Widget rw,
- ** Widget nw,
- ** ArgList arg_list,
- ** Cardinal *num_args)
- **
- ** Parameters:
- **
- ** Purpose: This is the Editor widget initialize routine.
- ** It is responsible for the following:
- ** 1) Validate all resources the user passed in,
- ** 2) Override any invalid resources,
- ** 3) Initialize the internal data structures,
- ** 4) Create the edit area widget
- ** 5) Create the status area widget, if requested
- ** 6) Add any callbacks and actions
- */
- static void
- Initialize(
- Widget rw,
- Widget nw,
- ArgList arg_list,
- Cardinal *num_args)
- {
- DtEditorWidget request = (DtEditorWidget) rw,
- new = (DtEditorWidget) nw;
- /* Initialize non-resource portion of the instance structure */
- VariableInitialize (new);
- /* Validate the incoming arguments to make sure they are OK */
- ValidateResources (new, request);
- /*
- * Create & customize the scrolled text widget
- */
- M_text(new) = CreateText (new);
- XtManageChild( M_text(new)) ;
- /*
- * If the widget is not "read only" then register it as a drop zone
- */
- if ( M_editable(new) == True )
- RegisterDropZone( new );
- /*
- * Compute the width & height of the scrolled text's font. These values
- * will be used when formatting and in calculating the window manager
- * hints.
- */
- getFontMetrics(new);
- /*
- * Create the status line
- */
- SetStatusLine( new, M_status_showStatusLine(request) );
- } /* end Initialize */
- /*-------------------------------------------------------------
- ** Function: static void VariableInitialize (
- ** DtEditorWidget new )
- **
- ** Parameters: The Editor widget being created
- **
- ** Purpose: This routine:
- ** 1) Initializes the widget's instance structure
- */
- static void
- VariableInitialize(
- DtEditorWidget new)
- {
- Widget thisParent;
- /*
- * Initialize the non-resource instance fields
- */
- M_display(new) = XtDisplayOfObject( (Widget)new->core.parent );
- M_app_context(new) = XtDisplayToApplicationContext(M_display(new));
- /*
- * Empty 'for' walks up the widget tree to find a shell.
- */
- for (thisParent = new->core.parent;
- thisParent != (Widget)NULL && XtIsShell(thisParent) == False;
- thisParent = XtParent(thisParent));
- M_topLevelShell(new) = thisParent;
- /* Initialize edit area fields */
- M_loadingAllNewData(new) = False;
- M_unreadChanges(new) = False; /* There have not been any changes since */
- /* the app requested the data */
- M_deletionStart(new) = NO_DELETION_IN_PROGRESS;
- M_deletedText(new) = (char *)NULL;
- M_insertStart(new) = 0;
- M_insertionLength(new) = 0;
- M_textSelectCbCalled(new) = False;
- M_fontWidth(new) = -1;
- /* Initialize status line fields */
- M_status_statusArea(new) = (Widget)NULL;
- M_status_messageText(new) = (Widget)NULL;
- M_status_currentLine(new) = -1;
- M_status_lastLine(new) = -1;
- /* Initialize search function data */
- M_search_dialog(new) = (Widget) NULL;
- M_search_dialogMode(new) = SPELL;
- M_search_string(new) = (char *)NULL;
- M_replace_string(new) = (char *)NULL;
- M_misspelled_string(new) = (char *)NULL;
- M_misspelled_found(new) = False;
- /* Initialize format function data */
- M_format_dialog(new) = (Widget)NULL;
- /* Initialize warning dialogs data */
- M_gen_warning(new) = (Widget)NULL;
- } /* end VariableInitialize */
- /*-------------------------------------------------------------
- ** Function: static void ValidateResources (
- ** DtEditorWidget new,
- ** DtEditorWidget request )
- **
- ** Parameters: The Editor widget being created & its requested
- ** resource values
- **
- ** Purpose: This routine:
- ** 1) Validates the widget's requested resources
- */
- static void
- ValidateResources(
- DtEditorWidget new,
- DtEditorWidget request)
- {
- /*
- * Validate the requested values for the editor's resources
- */
- /*
- * Make local copies of all resource strings assigned by the application.
- */
- if (M_spellFilter(request) != (char *) NULL)
- M_spellFilter(new) = XtNewString( M_spellFilter(request) );
- /*
- * Copy the dialog titles if the application set them, otherwise,
- * get their values from the message catalog.
- */
- if (M_spellTitle(request) != (XmString) NULL)
- M_spellTitle(new) = XmStringCopy( M_spellTitle(request) );
- else
- M_spellTitle(new) = XmStringCreateLocalized(SPELL_TITLE);
- if (M_fndChngTitle(request) != (XmString) NULL)
- M_fndChngTitle(new) = XmStringCopy( M_fndChngTitle(request) );
- else
- M_fndChngTitle(new) = XmStringCreateLocalized(FIND_TITLE);
- if (E_format_dialogTitle(request) != (XmString) NULL)
- E_format_dialogTitle(new) = XmStringCopy( E_format_dialogTitle(request) );
- else
- E_format_dialogTitle(new) = XmStringCreateLocalized(FORMAT_SETTINGS);
- if (E_infoDialogTitle(request) != (XmString) NULL)
- E_infoDialogTitle(new) = XmStringCopy( E_infoDialogTitle(request) );
- else
- E_infoDialogTitle(new) = XmStringCreateLocalized(INFO_TITLE);
- /*
- * Copy the insert & overstrike label indicators if the appli-
- * cation set them, otherwise, get their value from the message
- * catalog.
- * Check for DtUNSPECIFIED because NULL is a valid value.
- */
- if (M_status_insertLabel(request) != (XmString) DtUNSPECIFIED)
- M_status_insertLabel(new) =
- XmStringCopy( M_status_insertLabel(request) );
- else
- M_status_insertLabel(new) = XmStringCreateLocalized(INS);
- if (M_status_overstrikeLabel(request) != (XmString) DtUNSPECIFIED)
- M_status_overstrikeLabel(new) =
- XmStringCopy( M_status_overstrikeLabel(request) );
- else
- M_status_overstrikeLabel(new) = XmStringCreateLocalized(OVR);
- } /* end ValidateResources */
- /*-------------------------------------------------------------
- ** Function: static Widget CreateText (
- ** DtEditorWidget parent)
- **
- ** Parameters: The parent of the text widget
- **
- ** Purpose: This routine creates the scrolled text widget which
- ** lives inside the editor widget.
- ** It is responsible for the following:
- ** 1) Creating the scrolled text widget,
- ** 2) Adding specific translations,
- ** 3) Adding our own callbacks,
- ** 4) Substituting our own set selection routine.
- */
- static Widget
- CreateText(
- DtEditorWidget parent)
- {
- register int ac; /* arg count */
- Arg al[21]; /* arg list */
- Widget text;
- /*
- * First, set up the hardwired scrolled text widget resource values.
- * (Change these and you die! Aha! Ha! Ha! Ha! [evil laugh])
- */
- ac = 0;
- XtSetArg (al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
- XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
- XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
- XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
- XtSetArg(al[ac], XmNpendingDelete, True); ac++;
- /*
- * Now, set up the resource values which can vary (passed in from
- * application or default values).
- *
- * If a synthetic resource is DtUNSPECIFIED don't set it, but let
- * it default to the scrolled text default value.
- * If it is specified, clear the data field after setting the
- * resource because the value in the field will be out of sync
- * with the real value.
- */
- XtSetArg(al[ac], XmNautoShowCursorPosition, M_autoShowCursorPos(parent));
- ac++;
- XtSetArg(al[ac], XmNblinkRate, M_blinkRate(parent)); ac++;
- if ( M_columns(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNcolumns, M_columns(parent) ); ac++;
- M_columns(parent) = (short) DtUNSPECIFIED;
- }
- if ( M_cursorPos(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNcursorPosition, M_cursorPos(parent)); ac++;
- M_cursorPos(parent) = (XmTextPosition) DtUNSPECIFIED;
- }
- XtSetArg(al[ac], XmNcursorPositionVisible, M_cursorPosVisible(parent));
- ac++;
- XtSetArg(al[ac], XmNeditable, M_editable(parent)); ac++;
-
- if ( E_textFontList(parent) != (XmFontList) NULL) {
- XtSetArg (al[ac], XmNfontList, E_textFontList(parent)); ac++;
- }
- if ( M_maxLength(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNmaxLength, M_maxLength(parent) ); ac++;
- M_maxLength(parent) = (int) DtUNSPECIFIED;
- }
- if ( M_rows(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNrows, M_rows(parent) ); ac++;
- M_rows(parent) = (short) DtUNSPECIFIED;
- }
- XtSetArg (al[ac], XmNscrollHorizontal, M_scrollHorizontal(parent) ); ac++;
- if ( M_scrollLeftSide(parent) != (Boolean)DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNscrollLeftSide, M_scrollLeftSide(parent) ); ac++;
- M_scrollLeftSide(parent) = (Boolean)DtUNSPECIFIED;
- }
- if ( M_scrollTopSide(parent) != (Boolean)DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNscrollTopSide, M_scrollTopSide(parent) ); ac++;
- M_scrollTopSide(parent) = (Boolean)DtUNSPECIFIED;
- }
- XtSetArg (al[ac], XmNscrollVertical, M_scrollVertical(parent) ); ac++;
- if ( M_topCharacter(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNtopCharacter, M_topCharacter(parent) ); ac++;
- M_topCharacter(parent) = (XmTextPosition) DtUNSPECIFIED;
- }
- XtSetArg (al[ac], XmNwordWrap, M_wordWrap(parent) ); ac++;
- /* Create text widget */
- text = XmCreateScrolledText ( (Widget) parent, "text", al, ac );
- /*
- * Now, set the foreground & background of the text widget. Could not
- * set it at create time because the scrolled window would have
- * picked it up, too.
- */
- ac=0;
- if ( M_textBackground(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNbackground, M_textBackground(parent) ); ac++;
- M_textBackground(parent) = (Pixel) DtUNSPECIFIED;
- }
- if ( M_textForeground(parent) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNforeground, M_textForeground(parent) ); ac++;
- M_textForeground(parent) = (Pixel) DtUNSPECIFIED;
- }
- if (ac)
- XtSetValues( text, al, ac);
- /* XXX Word Wrap workaround. See comments for FixWordWrap() */
- if ( M_scrollHorizontal(parent) ) /* XXX Word Wrap workaround */
- FixWordWrap(text, M_wordWrap(parent)); /* XXX Word Wrap workaround */
-
- /* Put the editor-specific translation routines in place. */
- XtOverrideTranslations(text,
- XtParseTranslationTable(EditorTranslationTable));
- /* Add any translations set by the application. */
- if ( E_textTranslations(parent) != (XtTranslations)NULL ) {
- XtOverrideTranslations(text, E_textTranslations(parent));
- }
- /*
- * Add modify verify callback
- */
- XtAddCallback(text, XmNmodifyVerifyCallback,
- (XtCallbackProc) _DtEditorModifyVerifyCB,
- (XtPointer) parent);
- /*
- * Add the Help callback
- */
- XtAddCallback( text, XmNhelpCallback, (XtCallbackProc) HelpEditWindowCB,
- (XtPointer) parent );
- /*
- * Substitute our own Set Selection routine which can
- * call the textSelect and textDeselect callback procs
- */
- if(((XmTextWidget)(text))->text.source->SetSelection !=
- Editor_SetSelectionProc) {
- M_setSelection(parent) =
- ((XmTextWidget)(text))->text.source->SetSelection;
- ((XmTextWidget)(text))->text.source->SetSelection =
- Editor_SetSelectionProc;
- }
- XtSetSensitive (text, True);
- return(text);
- } /* end CreateText */
- /*-------------------------------------------------------------
- ** Function: static int extractFontMetrics (
- ** XmFontList fontlist )
- **
- ** Purpose: Given a font list, determine the width & height
- ** of the characters.
- **
- ** This routine is lifted almost straight out of
- ** lib/Xm/TextOut.c (see LoadFontMetrics() ) so the editor will
- ** select the same font the text widget is working with.
- */
- static void
- extractFontMetrics(
- DtEditorWidget w,
- XmFontList fontlist,
- int *height,
- int *width)
- {
- XmFontContext context;
- XmFontListEntry next_entry;
- XmFontType type_return = XmFONT_IS_FONT;
- XtPointer tmp_font;
- XFontStruct *font;
- Boolean have_font_struct = False;
- Boolean have_font_set = False;
- Boolean use_font_set = False;
- XFontSetExtents *fs_extents;
- unsigned long tmp_width = 0;
- int font_descent, font_ascent;
- char* font_tag = NULL;
-
- *width = *height = 0;
- if (XmFontListInitFontContext(&context, fontlist)) {
- /*
- * Look through the font list for a fontset with the default tag.
- * If we do not find it, use the first font set we came to, otherwise,
- * use the first font struct we came to.
- */
- do {
- Boolean do_break = False;
- next_entry = XmFontListNextEntry(context);
- if (next_entry) {
- tmp_font = XmFontListEntryGetFont(next_entry, &type_return);
- if (type_return == XmFONT_IS_FONTSET) {
- /*
- * Have a font set
- */
- font_tag = XmFontListEntryGetTag(next_entry);
- if (!have_font_set){
- /*
- * Save the first fontset found in case we don't find
- * a default tag font set.
- */
- have_font_set = True; /* we have a font set. */
- use_font_set = True;
- font = (XFontStruct *)tmp_font;
- /*
- * We have a font set, so no need to consider future font
- * structs
- */
- have_font_struct = True;
- /*
- * If this is the default font set break out, we've
- * found the one we want.
- */
- if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag))
- do_break = True;
- }
- else if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag)) {
- /*
- * If this is the default font set save it & break out,
- * we've found the one we want.
- */
- font = (XFontStruct *)tmp_font;
- have_font_set = True;
- do_break = True;
- }
- if (NULL != font_tag)
- XtFree(font_tag);
- if (do_break)
- break;
- }
- else if (!have_font_struct){
- /*
- * Have a font
- */
- use_font_set = False;
- /*
- * Save the first one in case no font set is found
- */
- font = (XFontStruct *)tmp_font;
- use_font_set = False;
- have_font_struct = True;
- }
- }
- } while (next_entry != NULL);
- XmFontListFreeFontContext(context);
- /*
- * Now, extract the font metrics from the font set or font that
- * we chose.
- */
- if (use_font_set) {
- /*
- * Chose a font set
- */
- fs_extents = XExtentsOfFontSet((XFontSet)font);
- if (XmDirectionMatch(w->manager.string_direction,
- XmTOP_TO_BOTTOM_RIGHT_TO_LEFT)) {
- tmp_width = (unsigned long)fs_extents->max_ink_extent.width;
- } else {
- tmp_width = (unsigned long)fs_extents->max_logical_extent.width;
- }
- /* max_logical_extent.y is number of pixels from origin to top of
- * rectangle (i.e. y is negative) */
- font_ascent = -fs_extents->max_logical_extent.y;
- font_descent = fs_extents->max_logical_extent.height +
- fs_extents->max_logical_extent.y;
- }
- else {
- /*
- * Chose a font struct
- */
- font_ascent = font->max_bounds.ascent;
- font_descent = font->max_bounds.descent;
- if ( (!XGetFontProperty(font, XA_QUAD_WIDTH, &tmp_width)) ||
- tmp_width == 0 )
- {
- if ( font->per_char && font->min_char_or_byte2 <= '0' &&
- font->max_char_or_byte2 >= '0' )
- tmp_width = font->per_char['0' - font->min_char_or_byte2].width;
- else
- tmp_width = font->max_bounds.width;
- }
- }
- if (tmp_width <= 0) tmp_width = 1;
- *width = (int)tmp_width; /* This assumes there will be no truncation */
- *height = font_descent + font_ascent;
- }
- } /* end extractFontMetrics */
- /*-------------------------------------------------------------
- ** Function: static void getFontMetrics (
- ** DtEditorWidget w )
- **
- ** Parameters: An Editor widget
- **
- ** Purpose: Determine the height & width of the scrolled text
- ** widget's font
- **
- */
- static void
- getFontMetrics(
- DtEditorWidget w)
- {
- Arg al[10]; /* arg list */
- XmFontList fontlist;
- int width, height;
- /*
- * Get the text widget's font list
- *
- * Note, have to retrieve the fontList from the text widget rather
- * than use the DtNtextFontList resource because the text widget may
- * have rejected the font specified with DtNtextFontList. This way
- * we will get the fontList actually used by the text widget.
- */
- XtSetArg(al[0], XmNfontList, &fontlist);
- XtGetValues(M_text(w), al, 1);
- /*
- * Now, extract the height and width
- */
- extractFontMetrics( w, fontlist, &height, &width );
- M_fontWidth(w) = width;
- M_fontHeight(w) = height;
- } /* end getFontMetrics */
- /*-------------------------------------------------------------
- ** Destroy
- ** Release resources allocated for a widget instance.
- */
- static void
- Destroy(
- Widget widget )
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- /*
- * Cleanup the edit window
- */
-
- /*
- * (Nothing to be done. Unregistering it as a drop site is handled
- * automatically by the DnD library.)
- */
- /*
- * Cleanup the status line
- */
-
- if (M_status_insertLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(M_status_insertLabel(editor));
- if (M_status_overstrikeLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(M_status_overstrikeLabel(editor));
- if (E_status_currentLineLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_status_currentLineLabel(editor));
- if (E_status_totalLineCountLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_status_totalLineCountLabel(editor));
- /*
- * Cleanup the Find/Change & Spell dialogs
- */
- if (M_search_string(editor))
- XtFree(M_search_string(editor));
- if (M_replace_string(editor))
- XtFree(M_replace_string(editor));
- if (M_misspelled_string(editor))
- XtFree(M_misspelled_string(editor));
- if (M_spellFilter(editor))
- XtFree(M_spellFilter(editor));
- if (M_spellTitle(editor) != (XmString)NULL)
- XmStringFree(M_spellTitle(editor));
- if (E_misspelledListLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_misspelledListLabel(editor));
- if (M_fndChngTitle(editor) != (XmString)NULL)
- XmStringFree(M_fndChngTitle(editor));
- if (E_findFieldLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_findFieldLabel(editor));
- if (E_changeFieldLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_changeFieldLabel(editor));
- if (E_findButtonLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_findButtonLabel(editor));
- if (E_changeButtonLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_changeButtonLabel(editor));
- if (E_changeAllButtonLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_changeAllButtonLabel(editor));
- /*
- * Cleanup the Format Settings dialog
- */
- if (E_format_dialogTitle(editor) != (XmString)NULL)
- XmStringFree(E_format_dialogTitle(editor));
- if (E_format_leftMarginFieldLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_leftMarginFieldLabel(editor));
- if (E_format_rightMarginFieldLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_rightMarginFieldLabel(editor));
- if (E_format_leftAlignToggleLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_leftAlignToggleLabel(editor));
- if (E_format_rightAlignToggleLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_rightAlignToggleLabel(editor));
- if (E_format_justifyToggleLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_justifyToggleLabel(editor));
- if (E_format_centerToggleLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_centerToggleLabel(editor));
- if (E_format_formatAllButtonLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_formatAllButtonLabel(editor));
- if (E_format_formatParagraphButtonLabel(editor) != (XmString)DtUNSPECIFIED)
- XmStringFree(E_format_formatParagraphButtonLabel(editor));
- /*
- * Cleanup the Information dialog
- */
- if (E_infoDialogTitle(editor) != (XmString)NULL)
- XmStringFree(E_infoDialogTitle(editor));
- /*
- * Cleanup the Undo deletion context
- */
- _DtEditorResetUndo(editor);
- } /* end Destroy */
- /*-------------------------------------------------------------
- ** SetValues
- ** Handle changes in resource data.
- */
- static Boolean
- SetValues(
- Widget cw,
- Widget rw,
- Widget nw )
- {
- Boolean redisplay_flag = False;
- Arg al[10]; /* arg list */
- register int ac; /* arg count */
- Boolean resetSpellTitle = False,
- resetFormatTitle = False,
- resetInfoTitle = False,
- newButtonFontList = False,
- newLabelFontList = False,
- newTextFontList = False,
- NeedToFixWordWrap = False; /* XXX Word Wrap workaround*/
- DtEditorWidget current = (DtEditorWidget) cw;
- DtEditorWidget request = (DtEditorWidget) rw;
- DtEditorWidget new = (DtEditorWidget) nw;
- /*
- * XXX Need to propagate changes to Core resources, like XmNbackground,
- * to the children.
- */
- /*
- * If a synthetic resource is specified, clear the data field
- * after setting the resource because the value in the field
- * will be out of sync with the real value (contained in the
- * child widget).
- */
- /*
- * General changes, not directly affecting a child
- */
- /* Check for a new spell filter */
- if ( strcmp(M_spellFilter(request), M_spellFilter(current)) != 0 )
- {
- XtFree( M_spellFilter(current) );
- M_spellFilter(new) = XtNewString( M_spellFilter(request) );
- }
- /* Check for new font lists */
- if ( E_buttonFontList(request) != E_buttonFontList(current) )
- newButtonFontList = True;
- if ( E_labelFontList(request) != E_labelFontList(current) )
- newLabelFontList = True;
- if ( E_textFontList(request) != E_textFontList(current) )
- newTextFontList = True;
- /*
- * Check for any changes which affect the dialog titles
- */
- if (XmStringCompare(E_dialogTitle(request),E_dialogTitle(current)) == False) {
- resetSpellTitle = resetFormatTitle = resetInfoTitle = True;
- }
- if (XmStringCompare(M_spellTitle(request),M_spellTitle(current)) == False) {
- XmStringFree( M_spellTitle(current) );
- M_spellTitle(new) = XmStringCopy( M_spellTitle(request) );
- resetSpellTitle = True;
- }
- if (XmStringCompare(M_fndChngTitle(request),M_fndChngTitle(current)) == False)
- {
- XmStringFree( M_fndChngTitle(current) );
- M_fndChngTitle(new) = XmStringCopy( M_fndChngTitle(request) );
- resetSpellTitle = True;
- }
- if (XmStringCompare(E_format_dialogTitle(request),
- E_format_dialogTitle(current) ) == False)
- {
- XmStringFree( E_format_dialogTitle(current) );
- E_format_dialogTitle(new) = XmStringCopy( E_format_dialogTitle(request) );
- resetFormatTitle = True;
- }
- if (XmStringCompare(E_infoDialogTitle(request),
- E_infoDialogTitle(current) ) == False)
- {
- XmStringFree( E_infoDialogTitle(current) );
- E_infoDialogTitle(new) = XmStringCopy( E_infoDialogTitle(request) );
- resetInfoTitle = True;
- }
- /*
- * Calculate new titles for the dialogs depending upon which resources
- * changed.
- */
- if ( resetSpellTitle == True ) {
- /*
- * No need to do anything because the Spell and Find/Change dialog
- * titles are recomputed every time.
- */
- redisplay_flag = True;
- }
- if ( resetFormatTitle == True ) {
- SetFormatDialogTitle( new );
- redisplay_flag = True;
- }
- if ( resetInfoTitle == True ) {
- SetInfoDialogTitle( new );
- redisplay_flag = True;
- }
- /*
- * Check for any changes which affect the status line
- */
- if (M_status_showStatusLine(request) != M_status_showStatusLine(current)) {
- SetStatusLine( new, M_status_showStatusLine(request) );
- redisplay_flag = True;
- }
- if ( M_overstrikeMode(request) != M_overstrikeMode(current) ) {
- UpdateOverstrikeIndicator( new, M_overstrikeMode(request) );
- XtCallActionProc( (Widget) M_text(current), "toggle-overstrike",
- (XEvent *)NULL, (String *)NULL, 0 );
- redisplay_flag = True;
- }
- if ( M_status_statusArea(current) != (Widget)NULL ) {
- if (newLabelFontList == True) {
- XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
- XtSetValues( (Widget) M_status_lineLabel(current), al, 1);
- XtSetValues( (Widget) M_status_totalLabel(current), al, 1);
- XtSetValues( (Widget) M_status_totalText(current), al, 1);
- XtSetValues( (Widget) M_status_overstrikeWidget(current), al, 1);
- }
- ac=0;
- if (newTextFontList == True) {
- XtSetArg( al[ac], XmNfontList, E_textFontList(request) ); ac++;
- }
- if ( M_textBackground(request) != DtUNSPECIFIED) {
- XtSetArg( al[ac], XmNbackground, M_textBackground(request) ); ac++;
- }
- if ( M_textForeground(request) != DtUNSPECIFIED) {
- XtSetArg( al[ac], XmNforeground, M_textForeground(request) ); ac++;
- }
- if ( ac ) {
- XtSetValues( (Widget) M_status_lineText(current), al, ac);
- XtSetValues( (Widget) M_status_messageText(current), al, ac);
- }
- }
- /*
- * Check for any changes which affect the dialog boxes
- */
- /* Information dialog */
- if ( M_gen_warning(current) != (Widget)NULL ) {
- if ( newButtonFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_buttonFontList(request) );
- XtSetValues(
- XmMessageBoxGetChild(M_gen_warning(current), XmDIALOG_OK_BUTTON),
- al, 1 );
- }
- if ( newLabelFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
- XtSetValues(
- XmMessageBoxGetChild(M_gen_warning(current), XmDIALOG_MESSAGE_LABEL),
- al, 1 );
- }
- }
- /* Find/Change dialog */
- if ( M_search_dialog(current) != (Widget)NULL )
- {
- if ( newButtonFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_buttonFontList(request));
- XtSetValues( (Widget)M_search_findBtn(current), al, 1 );
- XtSetValues( (Widget)M_search_replaceBtn(current), al, 1 );
- XtSetValues( (Widget)M_search_replaceAllBtn(current), al, 1 );
- XtSetValues( (Widget)M_search_closeBtn(current), al, 1 );
- XtSetValues( (Widget)M_search_helpBtn(current), al, 1 );
- }
- if ( newLabelFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
- XtSetValues( (Widget)M_search_listLbl(current), al, 1 );
- XtSetValues( (Widget)M_search_findLbl(current), al, 1 );
- XtSetValues( (Widget)M_search_replaceLbl(current), al, 1);
- }
- if ( newTextFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_textFontList(request) );
- XtSetValues( (Widget)M_search_spellList(current), al, 1);
- XtSetValues( (Widget)M_findText(current), al, 1 );
- XtSetValues( (Widget)M_replaceText(current), al, 1 );
- }
- ac=0;
- if ( M_textBackground(request) != DtUNSPECIFIED) {
- XtSetArg( al[ac], XmNbackground, M_textBackground(request) ); ac++;
- }
- if ( M_textForeground(request) != DtUNSPECIFIED) {
- XtSetArg( al[ac], XmNforeground, M_textForeground(request) ); ac++;
- }
- if ( ac ) {
- XtSetValues( (Widget) M_findText(current), al, ac);
- XtSetValues( (Widget) M_replaceText(current), al, ac);
- }
- }
- /* Format Settings dialog */
- if ( M_format_dialog(current) != (Widget)NULL )
- {
- if ( newButtonFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_buttonFontList(request));
- XtSetValues( (Widget)M_format_leftJust(current), al, 1 );
- XtSetValues( (Widget)M_format_rightJust(current), al, 1);
- XtSetValues( (Widget)M_format_bothJust(current), al, 1 );
- XtSetValues( (Widget)M_format_center(current), al, 1 );
- XtSetValues( (Widget)M_format_paragraph(current), al, 1);
- XtSetValues( (Widget)M_format_all(current), al, 1 );
- XtSetValues( (Widget)M_format_close(current), al, 1 );
- XtSetValues( (Widget)M_format_help(current), al, 1 );
- }
- if ( newLabelFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_labelFontList(request) );
- XtSetValues( (Widget)M_format_leftLabel(current), al, 1 );
- XtSetValues( (Widget)M_format_rightLabel(current), al, 1);
- }
- if ( newTextFontList == True ) {
- XtSetArg (al[0], XmNfontList, E_textFontList(request) );
- XtSetValues( (Widget)M_format_leftMarginField(current), al, 1 );
- XtSetValues( (Widget)M_format_rightMarginField(current), al, 1);
- }
- ac=0;
- if ( M_textBackground(request) != DtUNSPECIFIED) {
- XtSetArg( al[ac], XmNbackground, M_textBackground(request) ); ac++;
- }
- if ( M_textForeground(request) != DtUNSPECIFIED) {
- XtSetArg( al[ac], XmNforeground, M_textForeground(request) ); ac++;
- }
- if ( ac ) {
- XtSetValues( (Widget) M_format_leftMarginField(current), al, ac);
- XtSetValues( (Widget) M_format_rightMarginField(current), al, ac);
- }
- }
- /*
- * Check for any changes which affect the edit area (scrolled text widget)
- */
- ac=0;
- if ( M_autoShowCursorPos(request) != M_autoShowCursorPos(current) ) {
- XtSetArg( al[ac], XmNautoShowCursorPosition, M_autoShowCursorPos(request));
- ac++;
- }
- if ( M_blinkRate(request) != M_blinkRate(current) ) {
- XtSetArg( al[ac], XmNblinkRate, M_blinkRate(request)); ac++;
- }
- if ( M_columns(request) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNcolumns, M_columns(request) ); ac++;
- M_columns(new) = (short) DtUNSPECIFIED;
- redisplay_flag = True;
- }
- /* PERF - disable redisplay for all SetValues */
- if ( M_cursorPos(request) != DtUNSPECIFIED) {
- XmTextSetCursorPosition( M_text(new), M_topCharacter(request) );
- M_cursorPos(new) = (XmTextPosition) DtUNSPECIFIED;
- }
- if ( M_cursorPosVisible(request) != M_cursorPosVisible(current) ) {
- XtSetArg( al[ac], XmNcursorPositionVisible, M_cursorPosVisible(request));
- ac++;
- }
- if ( M_editable(request) != M_editable(current) ) {
- XtSetArg( al[ac], XmNeditable, M_editable(request)); ac++;
- if( M_editable(request) ) {
- /*
- * If the widget is becoming editable, register it as a
- * drop site and...
- */
- RegisterDropZone( new );
- /*
- * ...turn back on the Change To field in the Find/Change dialog
- */
- if ( M_search_dialog(current) != (Widget)NULL ) {
- XtSetSensitive(M_search_replaceLbl(current), True);
- XtSetSensitive(M_replaceText(current), True);
- }
- }
- else
- /*
- * It's no longer available as a drop site.
- */
- UnregisterDropZone( current );
- }
- if ( M_maxLength(request) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNmaxLength, M_maxLength(request) ); ac++;
- M_maxLength(new) = (int) DtUNSPECIFIED;
- }
- if ( M_rows(request) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNrows, M_rows(request) ); ac++;
- M_rows(new) = (short) DtUNSPECIFIED;
- redisplay_flag = True;
- }
- if ( M_textBackground(request) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNbackground, M_textBackground(request) ); ac++;
- M_textBackground(new) = (XmTextPosition) DtUNSPECIFIED;
- redisplay_flag = True;
- }
- if ( newTextFontList == True ) {
- XtSetArg (al[ac], XmNfontList, E_textFontList(request) ); ac++;
- redisplay_flag = True;
- }
- if ( M_textForeground(request) != DtUNSPECIFIED) {
- XtSetArg (al[ac], XmNforeground, M_textForeground(request) ); ac++;
- M_textForeground(new) = (XmTextPosition) DtUNSPECIFIED;
- redisplay_flag = True;
- }
- /* PERF - disable redisplay for all SetValues */
- if ( M_topCharacter(request) != DtUNSPECIFIED) {
- XmTextSetTopCharacter( M_text(new), M_topCharacter(request) );
- M_topCharacter(new) = (XmTextPosition) DtUNSPECIFIED;
- }
- if ( M_wordWrap(request) != M_wordWrap(current) ) {
- XtSetArg( al[ac], XmNwordWrap, M_wordWrap(request)); ac++;
- NeedToFixWordWrap=M_scrollHorizontal(current);/*XXX Word Wrap workaround*/
- }
- if ( NeedToFixWordWrap ) /*XXX Word Wrap workaround*/
- FixWordWrap(M_text(new), M_wordWrap(request));/*XXX Word Wrap workaround*/
- if ( ac )
- XtSetValues( (Widget) M_text(new), al, ac);
- if ( E_textTranslations(request) != E_textTranslations(current) ) {
- XtOverrideTranslations(M_text(new), E_textTranslations(request));
- }
- if ( newTextFontList == True ) {
- getFontMetrics(new);
- }
- return (redisplay_flag);
- } /* end Set values */
- /**************************************************************
- **
- ** Get values routines for synthetic resources
- **
- **/
- static void
- _DtEditorGetCenterToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_centerToggleLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_centerToggleLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_center(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(CENTER);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetCenterToggleLabel */
- static void
- _DtEditorGetChangeAllButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_changeAllButtonLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_changeAllButtonLabel(editor) );
- else if (M_search_dialog(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_search_replaceAllBtn(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(CHNG_ALL_BUTTON);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetChangeAllButtonLabel */
- static void
- _DtEditorGetChangeButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_changeButtonLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_changeButtonLabel(editor) );
- else if (M_search_dialog(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_search_replaceBtn(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(CHANGE_BUTTON);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetChangeButtonLabel */
- static void
- _DtEditorGetChangeFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_changeFieldLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_changeFieldLabel(editor) );
- else if (M_search_dialog(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_search_replaceLbl(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(CHANGE_LABEL);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetChangeFieldLabel */
- static void
- _DtEditorGetColumns(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- short data;
- Arg al[1];
- XtSetArg( al[0], XmNcolumns, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetColumns */
- static void
- _DtEditorGetCurrentLineLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_status_currentLineLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_status_currentLineLabel(editor) );
- else if (M_status_statusArea(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_status_lineLabel(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(LINE);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetCurrentLineLabel */
- static void
- _DtEditorGetCursorPosition(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmTextPosition data;
- Arg al[1];
- XtSetArg( al[0], XmNcursorPosition, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetCursorPosition */
- static void
- _DtEditorGetFindButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_findButtonLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_findButtonLabel(editor) );
- else if (M_search_dialog(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_search_findBtn(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(FIND_BUTTON);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetFindButtonLabel */
- static void
- _DtEditorGetFindFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_findFieldLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_findFieldLabel(editor) );
- else if (M_search_dialog(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_search_findLbl(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(FIND_LABEL);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetFindFieldLabel */
- static void
- _DtEditorGetFormatAllButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_formatAllButtonLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_formatAllButtonLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_all(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(ALL);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetFormatAllButtonLabel */
- static void
- _DtEditorGetFormatParagraphButtonLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if(E_format_formatParagraphButtonLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_formatParagraphButtonLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_paragraph(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(PARAGRAPH);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetFormatParagraphButtonLabel */
- static void
- _DtEditorGetJustifyToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_justifyToggleLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_justifyToggleLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_bothJust(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(JUSTIFY);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetJustifyToggleLabel */
- static void
- _DtEditorGetLeftAlignToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_leftAlignToggleLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_leftAlignToggleLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_leftJust(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(LEFT_ALIGN);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetLeftAlignToggleLabel */
- static void
- _DtEditorGetLeftMarginFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_leftMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_leftMarginFieldLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_leftLabel(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(LEFT_MARGIN);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetLeftMarginFieldLabel */
- static void
- _DtEditorGetMaxLength(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- int data;
- Arg al[1];
- XtSetArg( al[0], XmNmaxLength, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetMaxLength */
- static void
- _DtEditorGetMisspelledListLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_misspelledListLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_misspelledListLabel(editor) );
- else if (M_search_dialog(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_search_listLbl(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(MISSPELLED);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetMisspelledListLabel */
- static void
- _DtEditorGetRightAlignToggleLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_rightAlignToggleLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_rightAlignToggleLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_rightJust(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(RIGHT_ALIGN);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetRightAlignToggleLabel */
- static void
- _DtEditorGetRightMarginFieldLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_format_rightMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_format_rightMarginFieldLabel(editor) );
- else if (M_format_dialog(editor) != (Widget)NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_format_rightLabel(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(RIGHT_MARGIN);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetRightMarginFieldLabel */
- static void
- _DtEditorGetRows(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- short data;
- Arg al[1];
- XtSetArg( al[0], XmNrows, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetRows */
- static void
- _DtEditorGetScrollLeftSide(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- Boolean data;
- Arg al[1];
- XtSetArg( al[0], XmNscrollLeftSide, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetScrollLeftSide */
- static void
- _DtEditorGetScrollTopSide(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- Boolean data;
- Arg al[1];
- XtSetArg( al[0], XmNscrollTopSide, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetScrollTopSide */
- static void
- _DtEditorGetTextBackground(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- Pixel data;
- Arg al[1];
- XtSetArg( al[0], XmNbackground, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetTextBackground */
- static void
- _DtEditorGetTextForeground(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- Pixel data;
- Arg al[1];
- XtSetArg( al[0], XmNforeground, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetTextForeground */
- static void
- _DtEditorGetTopCharacter(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmTextPosition data;
- Arg al[1];
- XtSetArg( al[0], XmNtopCharacter, &data) ;
- XtGetValues( (Widget) M_text(editor), al, 1) ;
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetTopCharacter */
- static void
- _DtEditorGetLineCountLabel(
- Widget wid,
- int resource_offset,
- XtArgVal *value )
- {
- DtEditorWidget editor = (DtEditorWidget) wid;
- XmString data;
- Arg al[1];
- /*
- * Get the value directly from the field in the instance structure.
- * If it is DtUNSPECIFIED then either:
- * 1) the value has been assigned to the widget (so get it from
- * there), or
- * 2) the value has never been set (so return the default value).
- */
- if (E_status_totalLineCountLabel(editor) != (XmString) DtUNSPECIFIED)
- data = XmStringCopy( E_status_totalLineCountLabel(editor) );
- else if (M_status_statusArea(editor) != (Widget) NULL)
- {
- XtSetArg( al[0], XmNlabelString, &data) ;
- XtGetValues( (Widget) M_status_totalLabel(editor), al, 1) ;
- }
- else
- data = XmStringCreateLocalized(TOTAL);
- *value = (XtArgVal) data ;
- return;
- } /* end _DtEditorGetLineCountLabel */
- /**************************************************************
- **
- ** Action Procedures
- **
- **/
- /*
- * The following are DtEditor's actions. A few are internal only (_I
- * suffix) and will be called by the default translations DtEditor places
- * on the text widget. The rest will be called from an application with
- * XtCallActionProc(). The main difference is the internal ones will be
- * passed a text widget ID, while the public ones will be passed a DtEditor ID.
- */
- static void
- BackwardChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "backward-character", event,
- params, *num_params );
- }
- static void
- BackwardPara(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "backward-paragraph", event,
- params, *num_params );
- }
- static void
- BackwardWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "backward-word", event,
- params, *num_params );
- }
- static void
- BeginningOfFile(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "beginning-of-file", event,
- params, *num_params );
- }
- static void
- BeginningOfLine(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "beginning-of-line", event,
- params, *num_params );
- }
- static void
- ClearSelection(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "clear-selection", event,
- params, *num_params );
- /*
- * Clearing selected text also deselects the selection, but for some
- * reason the selection proc (Editor_SetSelectionProc) does not get
- * called, therefore, we need to call the DtNtextDeselectCallback
- * from here.
- */
- Call_TextDeselectCallback(editor);
- }
- static void
- CopyClipboard(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "copy-clipboard", event,
- params, *num_params );
- }
- static void
- CutClipboard(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "cut-clipboard", event,
- params, *num_params );
- }
- static void
- DeleteNextChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "delete-next-character", event,
- params, *num_params );
- }
- static void
- DeleteNextWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "delete-next-word", event,
- params, *num_params );
- }
- static void
- DeletePrevChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "delete-previous-character", event,
- params, *num_params );
- }
- static void
- DeletePrevWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "delete-previous-word", event,
- params, *num_params );
- }
- static void
- DeleteToEOL(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "delete-to-end-of-line", event,
- params, *num_params );
- }
- static void
- DeleteToSOL(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "delete-to-start-of-line", event,
- params, *num_params );
- }
- static void
- DeselectAll(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "deselect-all", event,
- params, *num_params );
- }
- static void
- EndOfFile(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "end-of-file", event,
- params, *num_params );
- }
- static void
- EndOfLine(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "end-of-line", event,
- params, *num_params );
- }
- static void
- ForwardChar(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "forward-character", event,
- params, *num_params );
- }
- static void
- ForwardPara(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "forward-paragraph", event,
- params, *num_params );
- }
- static void
- ForwardWord(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "forward-word", event,
- params, *num_params );
- }
- static void
- GoToLine(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- if( M_status_statusArea(editor) != (Widget)NULL &&
- XtIsManaged(M_status_statusArea(editor)) == True )
- {
- /*
- * Set the input focus to the "Line" text field.
- */
- XmProcessTraversal(M_status_lineText(editor), XmTRAVERSE_CURRENT);
- /*
- * Select the current contents to allow easy modification.
- */
- XtCallActionProc( (Widget)M_status_lineText(editor), "select-all",
- event, (String *)NULL, 0 );
- }
- } /* end GoToLine */
- /*
- * Internal action called only from the scrolled text widget
- */
- static void
- GoToLine_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- XmTextWidget tw = (XmTextWidget)w;
- DtEditorWidget editor = (DtEditorWidget)M_editor(tw);
- GoToLine( (Widget)editor, event, params, num_params );
- } /* end GoToLine_I */
- static void
- Help(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- CallHelpCallback((DtEditorWidget)w, DtEDITOR_HELP_EDIT_WINDOW);
- }
- static void
- InsertString(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "insert-string", event,
- params, *num_params );
- }
- static void
- KeySelect(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "key-select", event,
- params, *num_params );
- }
- static void
- NewlineAndBackup(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "newline-and-backup", event,
- params, *num_params );
- }
- static void
- NewlineAndIndent(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "newline-and-indent", event,
- params, *num_params );
- }
- static void
- NextPage(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "next-page", event,
- params, *num_params );
- }
- static void
- PageLeft(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "page-left", event,
- params, *num_params );
- }
- static void
- PageRight(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "page-right", event,
- params, *num_params );
- }
- static void
- PasteClipboard(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "paste-clipboard", event,
- params, *num_params );
- }
- static void
- PreviousPage(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "previous-page", event,
- params, *num_params );
- }
- static void
- ProcessCancel(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "process-cancel", event,
- params, *num_params );
- }
- static void
- ProcessDown(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "process-down", event,
- params, *num_params );
- }
- static void
- ProcessShiftDown(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "process-shift-down", event,
- params, *num_params );
- }
- static void
- ProcessShiftUp(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "process-shift-up", event,
- params, *num_params );
- }
- static void
- ProcessUp(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "process-up", event,
- params, *num_params );
- }
- /************************************************************************
- * GetModeSwitchModifier
- * Find if any Mod<n> modifier is acting as the Group modifier - you
- * can't assume Mod1Mask is always it.
- * Returns the mask of the modifier key to which the Mode_switch
- * keysym is attached.
- *
- ************************************************************************/
- /* ARGSUSED */
- static unsigned int
- GetModeSwitchModifier(
- Display *dpy)
- {
- register XModifierKeymap *pMap;
- register int mapIndex, keyCol, mapSize;
- KeySym keySym;
- unsigned int modeSwitchModMask = 0;
- pMap = XGetModifierMapping(dpy);
- mapSize = 8*pMap->max_keypermod;
- for (mapIndex = 3*pMap->max_keypermod; mapIndex < mapSize; mapIndex++) {
- /* look only at the first 4 columns of key map */
- for (keyCol = 0; keyCol < 4; keyCol++) {
- keySym = XKeycodeToKeysym(dpy, pMap->modifiermap[mapIndex], keyCol);
- if (keySym == XK_Mode_switch)
- modeSwitchModMask |= 1 << (mapIndex / pMap->max_keypermod);
- }
- }
- XFreeModifiermap(pMap);
- return modeSwitchModMask;
- }
- /************************************************************************
- *
- * DtEditorQuoteNextChar
- * This action routine circumvents the normal XtDispatchEvent
- * mechanism, inserting the next control or extended character
- * directly into text without processed by event handlers or the
- * translation manager. This means, for
- * example, that the next control or extended character will be
- * inserted into text without being intrepreted as a Motif menu
- * or text widget accelerator.
- *
- ************************************************************************/
- /* ARGSUSED */
- static void
- QuoteNextChar(
- Widget widget,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)widget;
- static unsigned int ExtendcharMask = 0;
- /* NOTE: ExtendcharMask could be a global set via a MappingNotify
- * event handler. But it isn't...
- */
- if (! ExtendcharMask)
- {
- _DtProcessLock();
- if (! ExtendcharMask)
- ExtendcharMask = GetModeSwitchModifier( M_display(editor) );
- _DtProcessUnlock();
- }
- for (;;)
- {
- XEvent next;
- #ifdef XTHREADS
- /*
- * We cannot let XtAppNextEvent bloc, because the intrinsics
- * will release locks and some other thread might dispatch
- * the event we want to trap.
- */
- XtInputMask mask;
- XtAppContext app = XtWidgetToApplicationContext(widget);
- while ((mask = XtAppPending(app)) == 0)
- {
- if (XtAppGetExitFlag(app))
- return;
- }
- if (mask & XtIMXEvent)
- {
- #endif
- XtAppNextEvent(M_app_context(editor), &next);
- if ((next.type == KeyPress) &&
- (! IsModifierKey(XLookupKeysym((XKeyEvent *) &next, 0))) )
- {
- if (next.xkey.state & (ControlMask|ExtendcharMask))
- XtCallActionProc(M_text(editor), "self-insert", &next, NULL, 0);
- else
- XtDispatchEvent(&next);
- break;
- }
- else
- XtDispatchEvent(&next);
- #ifdef XTHREADS
- }
- else
- {
- /* Some (non-X) event is pending, so this should not block. */
- XtAppProcessEvent(app, mask);
- }
- #endif
- }
- } /* end QuoteNextChar */
- /*
- * Internal action called only from the scrolled text widget
- */
- static void
- QuoteNextChar_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- XmTextWidget tw = (XmTextWidget)w;
- DtEditorWidget editor = (DtEditorWidget) M_editor(tw);
- QuoteNextChar( (Widget)editor, event, params, num_params );
- } /* end QuoteNextChar_I */
- static void
- SelectAll(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- XtCallActionProc( M_text(editor), "select-all", event,
- params, *num_params );
- }
- static void
- ToggleInsertMode(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorWidget editor = (DtEditorWidget)w;
- /*
- * Toggle the state of the DtNoverstrike resource
- */
- XtVaSetValues(w, DtNoverstrike, !M_overstrikeMode(editor), NULL);
- } /* end ToggleInsertMode */
- static void
- ToggleInsertMode_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- XmTextWidget tw = (XmTextWidget)w;
- DtEditorWidget editor = (DtEditorWidget)M_editor(tw);
- ToggleInsertMode( (Widget)editor, event, params, num_params );
- } /* end ToggleInsertMode_I */
- static void
- UndoEdit(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- DtEditorUndoEdit(w);
- } /* end UndoEdit */
- static void
- UndoEdit_I(
- Widget w,
- XEvent *event,
- char **params,
- Cardinal *num_params)
- {
- XmTextWidget tw = (XmTextWidget)w;
- UndoEdit( (Widget)M_editor(tw), event, params, num_params );
- } /* end UndoEdit_I */
- /*
- * XXX All lines in this file marked "XXX Word Wrap workaround"
- * XXX are related to a Motif 1.2 Text widget design defect regarding
- * XXX word wrap. For Motif 1.2, the Text widget was designed so word
- * XXX wrap will not function if the scrolled text widget has a
- * XXX horizontal scroll bar ("a hscrollbar means the paper is infinite
- * XXX so there is no edge to wrap at"). This change was made in
- * XXX Xm/TextOut.c RCS version 1.71 checked in July, 1991. A
- * XXX CMVC report was filed 9/8/94 & assigned number 4772.
- */
- #include <Xm/TextOutP.h> /* XXX Word Wrap workaround */
- static void /* XXX Word Wrap workaround */
- FixWordWrap( /* XXX Word Wrap workaround */
- Widget w, /* XXX Word Wrap workaround */
- Boolean wrapOn) /* XXX Word Wrap workaround */
- { /* XXX Word Wrap workaround */
- XmTextWidget tw = (XmTextWidget)w; /* XXX Word Wrap workaround */
- OutputData data = tw->text.output->data; /* XXX Word Wrap workaround */
-
- data->scrollhorizontal = !wrapOn; /* XXX Word Wrap workaround */
- } /* XXX Word Wrap workaround */
- static void
- Call_TextSelectCallback(
- DtEditorWidget editor)
- {
- DtEditorSelectCallbackStruct select_cb;
- /*
- * Call the Editor widget's DtNtextSelectCallback proc
- * if it hasn't been called since the last select.
- */
- if ( !M_textSelectCbCalled(editor) ) {
- M_textSelectCbCalled(editor) = True;
- select_cb.reason = DtEDITOR_TEXT_SELECT;
- select_cb.event = (XEvent *)NULL;
- XtCallCallbackList ((Widget)editor, M_textSelect(editor),
- (XtPointer) &select_cb);
- }
- } /* end Call_TextSelectCallback */
- static void
- Call_TextDeselectCallback(
- DtEditorWidget editor)
- {
- DtEditorSelectCallbackStruct select_cb;
- /*
- * Call the Editor widget's DtNtextDeselectCallback proc
- * if it hasn't been called since the last deselect.
- */
- if ( M_textSelectCbCalled(editor) ) {
- M_textSelectCbCalled(editor) = False;
- select_cb.reason = DtEDITOR_TEXT_DESELECT;
- select_cb.event = (XEvent *)NULL;
- XtCallCallbackList ((Widget)editor, M_textDeselect(editor),
- (XtPointer) &select_cb);
- }
- } /* end Call_TextDeselectCallback */
- /*
- * Editor_SetSelectionProc
- * is put into the widget->text.source->SetSelection.
- * Used to call the DtEditor's select/unselect callbacks
- */
- static void
- Editor_SetSelectionProc(
- XmTextSource source,
- XmTextPosition left,
- XmTextPosition right,
- Time set_time )
- {
- XmSourceData data = source->data;
- Widget widget;
- XmTextWidget tw;
- DtEditorWidget editor;
- /*
- * Sanity check
- */
- if (!XtIsRealized((Widget)data->widgets[0]) ||
- data->numwidgets <= 0)
- return;
- if (left < 0) left = right = 0;
- widget = (Widget) data->widgets[0];
- tw = (XmTextWidget)widget;
- editor = M_editor(tw);
- if (!editor->core.being_destroyed) {
- if (left < right) {
- /*
- * There is a selected area if left < right so call the
- * DtNtextSelectCallback.
- */
- Call_TextSelectCallback( editor );
- }
- else {
- /*
- * Left = Right so nothing is selected; call the
- * DtNtextDeselectCallback.
- */
- Call_TextDeselectCallback( editor );
- }
- }
- /*
- * Now, call the text widget's real Set Selection proc
- */
- (*M_setSelection(editor))(source, left, right, set_time);
- } /* end Editor_SetSelectionProc */
- /**************************************************************
- **
- ** Drag and drop routines
- **
- **/
- /*
- * Handles drops of a file into the text editor, after validation in the
- * transfer callback. Files are handled by reading their contents.
- * Text is handled by Motif.
- *
- * Changing the contents of the text widget occurs here, rather than in
- * the transfer callback, because of the visual changes which occur when
- * changing the text widget.
- */
- static void
- AnimateCallback(
- Widget w,
- XtPointer client_data,
- XtPointer call_data )
- {
- int numItems, ii;
- DtEditorErrorCode error;
- DtDndDropAnimateCallbackStruct *animateInfo =
- (DtDndDropAnimateCallbackStruct *) call_data;
- DtEditorWidget editor = (DtEditorWidget) client_data;
- /*
- * XXX Only really needed if # of items is > 1
- */
- _DtTurnOnHourGlass( M_topLevelShell(editor) );
- /*
- * How many items are being dropped on us?
- */
- numItems = animateInfo->dropData->numItems;
- switch (animateInfo->dropData->protocol)
- {
- case DtDND_FILENAME_TRANSFER:
- {
- /*
- * OK, insert each file we are given
- */
- for (ii = 0; ii < numItems; ii++)
- {
- error = DtEditorInsertFromFile( (Widget)editor,
- animateInfo->dropData->data.files[ii] );
- /*
- * If the file was not inserted successfully, then quit
- * (don't care if the file is read only or if it contained
- * nulls that were stripped out).
- */
- if( error != DtEDITOR_NO_ERRORS &&
- error != DtEDITOR_READ_ONLY_FILE &&
- error != DtEDITOR_NULLS_REMOVED )
- {
- ii = numItems; /* break out of loop */
- }
- } /* end for */
- break;
- } /* end file transfer case */
- case DtDND_BUFFER_TRANSFER:
- {
- /*
- * OK, insert each buffer we are given
- */
- DtDndBuffer *buffers = animateInfo->dropData->data.buffers;
- DtEditorContentRec cr;
- cr.type = DtEDITOR_DATA;
- for (ii = 0; ii < numItems; ii++)
- {
- cr.value.data.buf = buffers[ii].bp;
- cr.value.data.length = buffers[ii].size;
-
- error = DtEditorInsert( (Widget)editor, &cr );
- /*
- * If the buffer was not inserted successfully, then quit
- * (don't care if the file contained nulls that were stripped out).
- */
- if( error != DtEDITOR_NO_ERRORS && error != DtEDITOR_NULLS_REMOVED )
- {
- ii = numItems; /* break out of loop */
- }
- } /* end for */
- break;
- } /* end buffer transfer case */
- case DtDND_TEXT_TRANSFER:
- {
- /*
- * Receiving a text drop.
- *
- * Text drag and drop is handled by Motif so this switch
- * will never be called.
- *
- */
- break;
- } /* end text transfer case */
- default:
- {
- }
- } /* end switch */
- /*
- * XXX Only really needed if # of items is > 1
- */
- _DtTurnOffHourGlass( M_topLevelShell(editor) );
- } /* end AnimateCallback */
- /*
- * Validates a drop of a file into the text widget.
- *
- * Changing the contents of the text widget occurs in the animate
- * callback, rather than here, because of the visual changes which
- * occur when changing the text widget.
- */
- /* ARGSUSED */
- static void
- TransferCallback(
- Widget w,
- XtPointer client_data,
- XtPointer call_data)
- {
- int numItems, ii;
- DtEditorErrorCode error;
- DtDndTransferCallbackStruct *transferInfo =
- (DtDndTransferCallbackStruct *) call_data;
- transferInfo->status = DtDND_SUCCESS;
- /*
- * How many items are being dropped on us?
- */
- numItems = transferInfo->dropData->numItems;
- switch (transferInfo->dropData->protocol)
- {
- case DtDND_FILENAME_TRANSFER:
- {
- /*
- * Check to see if we can read each file we are given
- */
- for (ii = 0; ii < numItems; ii++)
- {
- error = _DtEditorValidateFileAccess(
- transferInfo->dropData->data.files[ii],
- READ_ACCESS);
- /*
- * Can't access it for reading so reject drop
- */
- if ( error != DtEDITOR_NO_ERRORS ) {
- transferInfo->status = DtDND_FAILURE;
- ii = numItems; /* break out of loop */
- }
- } /* end for each file */
- break;
- } /* end file transfer case */
- case DtDND_BUFFER_TRANSFER:
- {
- /*
- * Receiving a buffer drop.
- * -- do nothing in transfer
- */
- break;
- } /* end buffer transfer case */
- case DtDND_TEXT_TRANSFER:
- {
- /*
- * Receiving a text drop.
- *
- * Text drag and drop is handled by Motif so this switch
- * will never be called.
- *
- */
- break;
- } /* end text transfer case */
- default:
- {
- transferInfo->status = DtDND_FAILURE;
- break;
- }
- } /* end switch */
- } /* end TransferCallback */
- /*-------------------------------------------------------------
- ** Function: static void RegisterDropZone (
- ** DtEditorWidget w)
- **
- ** Parameters: A DtEditor widget
- **
- ** Purpose: This routine registers the edit window's text widget
- ** as a drop site for file & buffer drops. Because it
- ** is a text widget it will automatically accept text
- ** drops.
- */
- static void
- RegisterDropZone(
- DtEditorWidget w)
- {
- int ac;
- Arg al[2];
-
- XtCallbackRec transferCB[] = { {TransferCallback, NULL}, {NULL, NULL} };
- XtCallbackRec animateCB[] = { {AnimateCallback, NULL}, {NULL, NULL} };
- transferCB[0].closure = (XtPointer) w;
- animateCB[0].closure = (XtPointer) w;
- /*
- * Register file & buffer transfers... let Motif handle text DnD
- */
- ac=0;
- XtSetArg( al[ac], DtNdropAnimateCallback, animateCB ); ac++;
- DtDndDropRegister( M_text(w),
- DtDND_FILENAME_TRANSFER|DtDND_BUFFER_TRANSFER,
- XmDROP_COPY, transferCB, al, ac );
- } /* end RegisterDropZone */
- /*-------------------------------------------------------------
- ** Function: static void UnregisterDropZone (
- ** DtEditorWidget w)
- **
- ** Parameters: A DtEditor widget
- **
- ** Purpose: This routine unregisters the edit window
- */
- static void
- UnregisterDropZone(
- DtEditorWidget w)
- {
- DtDndDropUnregister( M_text(w) );
- } /* end UnregisterDropZone */
- /************************************************************************
- *
- * SetInfoDialogTitle - Change the title for the Information dialog
- *
- ************************************************************************/
- static void
- SetInfoDialogTitle(
- DtEditorWidget editor)
- {
- Arg al[2];
- /*
- * If the Information dialog has been created, change its title
- */
- if( M_gen_warning(editor) != (Widget)NULL )
- {
- /*
- * Prepend the DialogTitle resource, if it has been set
- */
- if( E_dialogTitle(editor) != (XmString)NULL ) {
- XmString titleStr;
- /*
- * Add the "functional title" to the DialogTitle
- */
- titleStr = XmStringConcat( E_dialogTitle(editor),
- E_infoDialogTitle(editor) );
- XtSetArg( al[0], XmNdialogTitle, titleStr );
- XtSetValues(M_gen_warning(editor), al, 1);
- XmStringFree( titleStr );
- }
- else {
- XtSetArg( al[0], XmNdialogTitle, E_infoDialogTitle(editor) );
- XtSetValues(M_gen_warning(editor), al, 1);
- }
- }
- } /* end SetInfoDialogTitle */
- /************************************************************************
- *
- * _DtEditorWarning - get a message to the user
- *
- ************************************************************************/
- void
- _DtEditorWarning(
- DtEditorWidget editor,
- char *mess,
- unsigned char dialogType)
- {
- Arg al[10];
- int ac;
- char *tmpMess;
- XmString tmpStr;
-
- tmpMess = strdup(mess);
- /* create the dialog if it is the first time */
- if(M_gen_warning(editor) == (Widget) NULL)
- {
- XmString titleStr = (XmString) NULL;
- XmString okStr;
- ac = 0;
- /*
- * First, create the dialog's title, prepending the
- * DtNdialogTitle resource, if it is set
- */
- if( E_dialogTitle(editor) != (XmString)NULL ) {
-
- /*
- * Add the "functional title" to the DialogTitle
- */
- titleStr = XmStringConcat( E_dialogTitle(editor),
- E_infoDialogTitle(editor) );
- XtSetArg (al[ac], XmNdialogTitle, titleStr ); ac++;
- }
- else {
- XtSetArg (al[ac], XmNdialogTitle, E_infoDialogTitle(editor)); ac++;
- }
- okStr = XmStringCreateLocalized((char*) _DtOkString);
- XtSetArg (al[ac], XmNokLabelString, okStr); ac++;
- M_gen_warning(editor) = (Widget) XmCreateMessageDialog(
- M_topLevelShell(editor), "Warn",
- al, ac);
- if (titleStr != (XmString) NULL)
- XmStringFree( titleStr );
- XmStringFree(okStr);
- /* Set the correct font lists for the message & OK button. */
- XtSetArg (al[0], XmNfontList, E_buttonFontList(editor));
- XtSetValues(
- XmMessageBoxGetChild(M_gen_warning(editor), XmDIALOG_OK_BUTTON),
- al, 1) ;
- XtSetArg (al[0], XmNfontList, E_labelFontList(editor));
- XtSetValues(
- XmMessageBoxGetChild(M_gen_warning(editor), XmDIALOG_MESSAGE_LABEL),
- al, 1) ;
- /* Unmanage unneeded children. */
- XtUnmanageChild ( XmMessageBoxGetChild(M_gen_warning(editor),
- XmDIALOG_CANCEL_BUTTON) );
- XtUnmanageChild ( XmMessageBoxGetChild(M_gen_warning(editor),
- XmDIALOG_HELP_BUTTON) );
- XtRealizeWidget (M_gen_warning(editor));
- ac=0;
- XtSetArg(al[ac], XmNmwmInputMode,
- MWM_INPUT_PRIMARY_APPLICATION_MODAL);ac++;
- XtSetValues(XtParent(M_gen_warning(editor)), al, ac);
- }
- tmpStr = XmStringCreateLocalized(tmpMess);
- ac = 0;
- XtSetArg(al[ac], XmNdialogType, dialogType); ac++;
- XtSetArg(al[ac], XmNmessageString, tmpStr); ac++;
- XtSetValues(M_gen_warning(editor), al, ac);
- XmStringFree(tmpStr);
- XtFree( (char *) tmpMess );
- XtManageChild (M_gen_warning(editor));
- } /* end _DtEditorWarning */
- /*********************************************************************
- *
- * The following section contains the procedures related to the staus
- * line
- *
- *********************************************************************/
- #define FORCE True
- #define DONT_FORCE False
- /*
- * PositionActivateCB is invoked when the user presses [Return] after
- * (presumably) modifying the current line text field. It retrieves
- * the user specified line number and calls DtEditorGoToLine().
- */
-
- /* ARGSUSED */
- static void
- PositionActivateCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorWidget editor = (DtEditorWidget)client_data;
- char *lineStr = XmTextFieldGetString(M_status_lineText(editor));
- int newLineNum = atoi(lineStr);
- XtFree(lineStr);
- DtEditorGoToLine ((Widget)editor, newLineNum);
- XmProcessTraversal(M_text(editor), XmTRAVERSE_CURRENT);
- } /* PositionActivateCB */
- /*
- * _DtEditorUpdateLineDisplay updates the current & total line displays
- * in the status line, if needed. Normally, the displays are not changed
- * if the correct numbers are (supposedly) displayed. Setting forceUpdate
- * will cause the numbers to be updated anyways. This is primarily used
- * when the user enters a number into the current line display to force
- * display of the correct number.
- */
- void
- _DtEditorUpdateLineDisplay(
- DtEditorWidget editor,
- int currentLine,
- Boolean forceUpdate )
- {
- XmTextWidget tw = (XmTextWidget) M_text(editor);
- Arg al[10];
- char tmpChars[8];
- int lastLine;
- XmString tmpXmStr;
- /*
- * Only change the current & total lines displays if the status
- * line is visible
- */
- if ( M_status_showStatusLine(editor) == True )
- {
- /*
- * Current line
- */
- if (M_status_currentLine(editor) != currentLine || forceUpdate)
- {
- sprintf(tmpChars, "%d", currentLine);
- XmTextFieldSetString(M_status_lineText(editor), tmpChars);
- M_status_currentLine(editor) = currentLine;
- }
- /*
- * Total lines
- */
- lastLine = tw->text.total_lines;
- if(M_status_lastLine(editor) != lastLine )
- {
- sprintf(tmpChars, "%d", lastLine);
- tmpXmStr = XmStringCreateLocalized(tmpChars);
- XtSetArg(al[0], XmNlabelString, tmpXmStr);
- XtSetValues( M_status_totalText(editor), al, 1 );
- XmStringFree(tmpXmStr);
- M_status_lastLine(editor) = lastLine;
- }
- }
- } /* end _DtEditorUpdateLineDisplay */
- static void
- UpdateOverstrikeIndicator(
- DtEditorWidget widget,
- Boolean overstrikeOn )
- {
- Arg al[10];
- register int ac;
- DtEditorWidget ew = (DtEditorWidget) widget;
-
- /*
- * Only change the overstrike indicator if the status line is visible
- */
- if ( M_status_showStatusLine(ew) == True &&
- M_status_overstrikeWidget(ew) != (Widget) NULL )
- {
- ac=0;
- if ( overstrikeOn == True ) {
- XtSetArg(al[ac], XmNlabelString, M_status_overstrikeLabel(ew)); ac++;
- }
- else {
- XtSetArg(al[ac], XmNlabelString, M_status_insertLabel(ew)); ac++;
- }
- XtSetValues( M_status_overstrikeWidget(ew), al, ac );
- }
- } /* end UpdateOverstrikeIndicator */
- int
- _DtEditorGetLineIndex(
- XmTextWidget tw,
- XmTextPosition pos)
- {
- int startLine, lastLine, middleLine;
- XmTextLineTable lineTab = tw->text.line_table;
- startLine = 0;
- lastLine = tw->text.total_lines - 1;
- while(startLine != lastLine)
- {
- middleLine = (startLine + lastLine)/2;
- if(middleLine == startLine || middleLine == lastLine)
- {
- /*
- * We're down to 2 lines. It's gotta be on one of these
- * two lines.
- */
- if(pos < (XmTextPosition) lineTab[lastLine].start_pos)
- lastLine = startLine;
- else
- startLine = lastLine;
- }
- else
- {
- if (pos < (XmTextPosition) lineTab[middleLine].start_pos)
- lastLine = middleLine;
- else
- startLine = middleLine;
- }
- }
- return startLine;
- } /* end _DtEditorGetLineIndex */
- /*
- * SetCursorPosStatus is called as an XmNmotionVerifyCallback on the
- * text widget when the statusLine is turned on. It computes and
- * displays the new line of the insert cursor.
- */
- static void
- SetCursorPosStatus(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorWidget editor = (DtEditorWidget)client_data;
- XmTextWidget tw = (XmTextWidget)w;
- XmTextVerifyCallbackStruct * cb = (XmTextVerifyCallbackStruct *) call_data;
- int startLine;
- startLine = _DtEditorGetLineIndex(tw, cb->newInsert) + 1;
- _DtEditorUpdateLineDisplay( editor, startLine, FORCE );
- } /* end SetCursorPosStatus */
- static void
- SetStatusLine(
- DtEditorWidget ew,
- Boolean statusLineOn)
- {
- Arg al[10];
- register int ac;
- int currentLine;
- XmTextPosition cursorPos;
- M_status_showStatusLine(ew) = statusLineOn;
- if( statusLineOn == True )
- {
- if( M_status_statusArea(ew) == (Widget)NULL )
- M_status_statusArea(ew) = CreateStatusLine( ew );
- /*
- * Update the line counts
- */
- cursorPos = (XmTextPosition)DtEditorGetInsertionPosition( (Widget)ew );
- currentLine = _DtEditorGetLineIndex( (XmTextWidget) M_text(ew),
- cursorPos ) + 1;
- _DtEditorUpdateLineDisplay( ew, currentLine, DONT_FORCE );
- /*
- * Update the overstrike indicator
- */
- UpdateOverstrikeIndicator( ew, M_overstrikeMode(ew) );
- /*
- * Show the status line
- */
-
- XtManageChild( M_status_statusArea(ew) );
- /*
- * Hook the scrolled text widget to the status line
- */
- ac = 0;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_WIDGET ); ac++;
- XtSetArg( al[ac], XmNbottomWidget, M_status_statusArea(ew) ); ac++;
- XtSetValues( XtParent(M_text(ew)), al, ac );
-
- XtAddCallback( M_text(ew), XmNmotionVerifyCallback,
- (XtCallbackProc) SetCursorPosStatus, (XtPointer)ew);
- }
- else
- {
- /*
- * Hook the scrolled text widget to the bottom of the form
- */
- ac = 0;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetValues( XtParent(M_text(ew)), al, ac );
- XtRemoveCallback( M_text(ew), XmNmotionVerifyCallback,
- (XtCallbackProc) SetCursorPosStatus, (XtPointer)ew);
- /*
- * Hide the status line
- */
- if( M_status_statusArea(ew) != (Widget)NULL )
- XtUnmanageChild( M_status_statusArea(ew) );
- }
- } /* SetStatusLine */
- /************************************************************************
- *
- * CreateStatusLine - Creates the status line
- *
- ************************************************************************/
- static Widget
- CreateStatusLine(
- DtEditorWidget parent)
- {
- Arg al[20];
- int ac;
- Widget container;
- XmString tmpStr;
- Pixel background, foreground;
- /*
- * Match the background & foreground colors of the edit window
- * Don't use DtNtextBackground/Foreground directly because they
- * will be DtUNSPECIFIED.
- */
- ac = 0;
- XtSetArg(al[ac], XmNforeground, &foreground); ac++;
- XtSetArg(al[ac], XmNbackground, &background); ac++;
- XtGetValues(M_text(parent), al, ac);
- /*
- * Create the status line container
- */
- ac = 0;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNleftAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNrightAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNverticalSpacing, 3 ); ac++;
- XtSetArg( al[ac], XmNhorizontalSpacing, 3 ); ac++;
- container = (Widget) XmCreateForm( (Widget)parent, "statusLine",
- al, ac );
- /*
- * Create the current line label and text field
- */
- ac = 0;
- if (E_status_currentLineLabel(parent) != (XmString)DtUNSPECIFIED)
- {
- /*
- * Use the resource value & clear it (to save space).
- */
- tmpStr = XmStringCopy(E_status_currentLineLabel(parent));
- E_status_currentLineLabel(parent) = (XmString)DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tmpStr = XmStringCreateLocalized(LINE);
- }
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNleftAttachment, XmATTACH_FORM ); ac++;
- XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
- XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
- M_status_lineLabel(parent) = (Widget) XmCreateLabelGadget( container,
- "lineLabel", al, ac);
- XtManageChild(M_status_lineLabel(parent));
- XtAddCallback(M_status_lineLabel(parent), XmNhelpCallback,
- (XtCallbackProc)HelpStatusCurrentLineCB, parent);
- XmStringFree(tmpStr);
- ac = 0;
- XtSetArg(al[ac], XmNcolumns, 6); ac++;
- XtSetArg(al[ac], XmNforeground, foreground); ac++;
- XtSetArg(al[ac], XmNbackground, background); ac++;
- XtSetArg( al[ac], XmNfontList, E_textFontList(parent)); ac++;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
- XtSetArg( al[ac], XmNleftWidget, M_status_lineLabel(parent) ); ac++;
- M_status_lineText(parent) = XmCreateTextField( container, "lineText",
- al, ac );
- XtManageChild(M_status_lineText(parent));
- XtAddCallback(M_status_lineText(parent), XmNactivateCallback,
- (XtCallbackProc)PositionActivateCB, parent);
- XtAddCallback(M_status_lineText(parent), XmNhelpCallback,
- (XtCallbackProc)HelpStatusCurrentLineCB, parent);
- /*
- * Create the total lines labels
- */
- ac = 0;
- if (E_status_totalLineCountLabel(parent) != (XmString)DtUNSPECIFIED)
- {
- /*
- * Use the resource value & clear it (to save space).
- */
- tmpStr = XmStringCopy(E_status_totalLineCountLabel(parent));
- E_status_totalLineCountLabel(parent) = (XmString)DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tmpStr = XmStringCreateLocalized(TOTAL);
- }
- XtSetArg(al[ac], XmNlabelString, tmpStr); ac++;
- XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
- XtSetArg( al[ac], XmNleftWidget, M_status_lineText(parent) ); ac++;
- M_status_totalLabel(parent) = (Widget) XmCreateLabelGadget( container,
- "totalLabel", al, ac);
- XtManageChild(M_status_totalLabel(parent));
- XtAddCallback(M_status_totalLabel(parent), XmNhelpCallback,
- (XtCallbackProc)HelpStatusTotalLinesCB, parent);
- XmStringFree(tmpStr);
- ac = 0;
- XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
- XtSetArg( al[ac], XmNleftWidget, M_status_totalLabel(parent) ); ac++;
- M_status_totalText(parent) = (Widget) XmCreateLabelGadget( container,
- "totalText", al, ac);
- XtManageChild(M_status_totalText(parent));
- XtAddCallback(M_status_totalText(parent), XmNhelpCallback,
- (XtCallbackProc)HelpStatusTotalLinesCB, parent);
- /*
- * Create the overstrike indicator
- */
- ac = 0;
- /*
- XtSetArg(al[ac], XmNrecomputeSize, False); ac++;
- */
- XtSetArg(al[ac], XmNmarginLeft, 0); ac++;
- XtSetArg(al[ac], XmNmarginRight, 0); ac++;
- XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
- XtSetArg( al[ac], XmNrightOffset, 3 ); ac++;
- XtSetArg(al[ac], XmNfontList, E_labelFontList(parent) ); ac++;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNrightAttachment, XmATTACH_FORM ); ac++;
- M_status_overstrikeWidget(parent) =
- (Widget) XmCreateLabelGadget( container, "overstrikeLabel", al, ac);
- XtManageChild(M_status_overstrikeWidget(parent));
- XtAddCallback(M_status_overstrikeWidget(parent), XmNhelpCallback,
- (XtCallbackProc)HelpStatusOverstrikeCB, parent);
- /*
- * Create the application message area
- */
- ac = 0;
- XtSetArg(al[ac], XmNbackground, parent->core.background_pixel); ac++;
- XtSetArg(al[ac], XmNforeground, foreground); ac++;
- XtSetArg( al[ac], XmNfontList, E_textFontList(parent)); ac++;
- XtSetArg(al[ac], XmNeditable, False); ac++;
- XtSetArg(al[ac], XmNcursorPositionVisible, False); ac++;
- XtSetArg(al[ac], XmNtraversalOn, False); ac++;
- XtSetArg( al[ac], XmNbottomAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNtopAttachment, XmATTACH_FORM ); ac++;
- XtSetArg( al[ac], XmNleftAttachment, XmATTACH_WIDGET ); ac++;
- XtSetArg( al[ac], XmNleftWidget, M_status_totalText(parent) ); ac++;
- XtSetArg( al[ac], XmNleftOffset, 17 ); ac++;
- XtSetArg( al[ac], XmNrightAttachment, XmATTACH_WIDGET ); ac++;
- XtSetArg(al[ac], XmNrightWidget, M_status_overstrikeWidget(parent)); ac++;
- M_status_messageText(parent) =
- XmCreateTextField( container, "messageText", al, ac );
- XtManageChild(M_status_messageText(parent));
- XtAddCallback(M_status_messageText(parent), XmNhelpCallback,
- (XtCallbackProc)HelpStatusMessageCB, parent);
- return( container );
- } /* end CreateStatusLine */
- /*********************************************************************
- *
- * The following section contains the procedures related to help
- *
- *********************************************************************/
- static void
- CallHelpCallback(
- DtEditorWidget editor,
- int reason)
- {
- DtEditorHelpCallbackStruct help_cb;
- help_cb.reason = reason;
- help_cb.event = (XEvent *) NULL;
- XtCallCallbackList( (Widget)editor, M_HelpCB(editor),
- (XtPointer) &help_cb );
- } /* end CallHelpCallback */
- /****
- * Edit window help callbacks
- */
- /* ARGSUSED */
- static void
- HelpEditWindowCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback((DtEditorWidget)client_data, DtEDITOR_HELP_EDIT_WINDOW);
- }
- /****
- * Status Line help callbacks
- */
- /* XXX
- * Who uses this??
- */
- /* ARGSUSED */
- static void
- HelpStatusLineCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback((DtEditorWidget)client_data, DtEDITOR_HELP_STATUS_LINE);
- }
- /* ARGSUSED */
- static void
- HelpStatusCurrentLineCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_STATUS_CURRENT_LINE );
- }
- /* ARGSUSED */
- static void
- HelpStatusTotalLinesCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_STATUS_TOTAL_LINES );
- }
- /* ARGSUSED */
- static void
- HelpStatusMessageCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_STATUS_MESSAGE );
- }
- /* ARGSUSED */
- static void
- HelpStatusOverstrikeCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_STATUS_OVERSTRIKE );
- }
- /****
- * Format Settings dialog help callbacks
- */
- /* ARGSUSED */
- static void
- HelpFormatDialogCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback((DtEditorWidget)client_data, DtEDITOR_HELP_FORMAT_DIALOG);
- }
- /* ARGSUSED */
- static void
- HelpFormatRightMarginCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_FORMAT_RIGHT_MARGIN);
- }
- /* ARGSUSED */
- static void
- HelpFormatLeftMarginCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_FORMAT_LEFT_MARGIN);
- }
- /* ARGSUSED */
- static void
- HelpFormatJustifyButtonsCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_FORMAT_ALIGNMENT);
- }
- /****
- * Find/Change & Spell dialogs help callbacks
- */
- /* ARGSUSED */
- void
- _DtEditorHelpSearchCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorWidget editor = (DtEditorWidget)client_data;
- switch (M_search_dialogMode(editor))
- {
- case SPELL:
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_SPELL_DIALOG);
- break;
- case REPLACE:
- default:
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_CHANGE_DIALOG);
- break;
- }
- } /* _DtEditorHelpSearchCB */
- /* ARGSUSED */
- void
- _DtEditorHelpSearchFindCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_CHANGE_FIND);
- }
- /* ARGSUSED */
- void
- _DtEditorHelpSearchChangeCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorWidget editor = (DtEditorWidget)client_data;
- switch (M_search_dialogMode(editor))
- {
- case SPELL:
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_SPELL_CHANGE);
- break;
- case REPLACE:
- default:
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_CHANGE_CHANGE);
- break;
- }
- } /* _DtEditorHelpSearchChangeCB */
- /* ARGSUSED */
- void
- _DtEditorHelpSearchSpellCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- CallHelpCallback( (DtEditorWidget)client_data,
- DtEDITOR_HELP_SPELL_MISSPELLED_WORDS);
- }
- /*********************************************************************
- *
- * The following section contains the procedures related to formating
- * text and the Format Settings dialog.
- *
- *********************************************************************/
- /*
- * Do simple formatting of paragraphs of text.
- * Designed for speed, at some cost in complexity and redundancy.
- *
- * There is a minor undocumented bug in Dump(). It calls Justify() in the
- * case where the last word of the last line of a paragraph is an end-of-
- * sentence word (typical) and ends just one blank before the margin
- * (rare). This results in one blank being inserted in the line when it's
- * not necessary. It happens because the two trailing blanks after the
- * word cause an "ordinary" line dump before Fill() sees the next line and
- * knows it has an end of paragraph. WARNING: The situation would be
- * aggravated if FillWord() ever set blanks to an even larger number.
- */
- /*
- ** This section contains changes for EUC_4B compatibility.
- ** WPI interface is used.
- */
- /* Global Variables and extern declarations */
- typedef struct _WORD{ /* describe one word */
- wint_t *cp; /* word location in buffer */
- int inlinenum; /* word start line in input */
- int incolumn; /* word start column in input */
- int length; /* size of word */
- int score; /* word + next for jflag */
- int blanks; /* output trailing blanks need */
- int wclen; /* Length of wide character word */
- } WORD;
- typedef struct {
- wchar_t Blank;
- AdjRecPtr pAdj;
- /* FORMATTING CONTROL */
- int m0flag;
- long fillmargin;
- long centermiddle;
- int tabsize; /* tab size in use */
- int centerstartpara; /* expect para. start? in "Center" */
- /* Global/static vars used in "Fill" */
- wint_t *wordbuf; /* see comments for "Fill" for discussion */
- wint_t *wordcp;
- wint_t *wordcpwrap;
- WORD *word;
- WORD *wordbase;
- WORD *wordlimit;
- WORD *wordfirst;
- WORD *wordat;
- WORD *wordnext;
- int inlinenum;
- int incolumn;
- int outlinenum;
- int pendchars;
- int indent1, indent2;
- } FormatData;
- #define isekinsoku(wc) iswctype((wc),ekinclass)
- #define isbekinsoku(wc) iswctype((wc),bekinclass)
- #define LINESIZE BUFSIZ /* how big a line can be */
- #define WORDMAX LINESIZE /* see above for discussion */
- #define WORDNEXT(d,at) { if (++at == d->wordlimit) at = d->wordbase; } /* statement */
- #define WORDPREV(d,at) (((at == d->wordbase) ? d->wordlimit : at) - 1) /* function */
- #include <locale.h>
- extern int _nl_space_alt;
- /*
- * Forward declarations
- */
- static int DoLine (FormatData *data, register FILE *filep);
- static void Center (FormatData *data,
- wint_t *in_line, register wint_t *inlinelim);
- static void Fill (FormatData *data, wint_t *in_line, register wint_t *inlinelim);
- static void FillWord (FormatData *data);
- static void Dump (FormatData *data, int endpara);
- static void PrintIndent (FormatData *data, int indent);
- static void PrintTag (FormatData *data, WORD *wordpast);
- static void PrintWords (FormatData *data, WORD *wordpast);
- static void Justify (FormatData *data, register int blanks, WORD *wordpast);
- static int CompareWords (const void *, const void *);
- static int EkinBekinProc(FormatData *data, WORD **wordpast);
- static void postEkinBekinProc(FormatData *data, int *poutchars, WORD *wordpast);
- #if defined(sun)
- /*
- * A small workaround for systems that don't have wcwidth...
- */
- static int
- sun_wcwidth(
- const wchar_t wc)
- {
- int status;
- char mbstr[MB_LEN_MAX + 1];
- status = wctomb(mbstr, wc);
- if (status > 0)
- return(euccol(mbstr));
- else
- return(status);
- }
- #endif /* sun */
- /*
- * The following utilities: lineBlank, findNonBlank, and countBlanks all
- * require the lineLen parameter to specify the number of characters, not
- * bytes, in the line.
- */
- static Boolean
- lineBlank(
- char *pLine,
- int lineLen)
- {
- int byteNum, charNum;
- wchar_t wc;
- size_t mbCurMax = MB_CUR_MAX;
- for(byteNum = charNum = 0; charNum < lineLen;
- byteNum += mblen(&pLine[byteNum], mbCurMax), charNum++)
- {
- (void) mbtowc(&wc, &pLine[byteNum], mbCurMax);
- #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
- if( !iswctype(wc, _DtEditor_blankClass) )
- return False;
- #else
- if( !iswblank(wc) )
- return False;
- #endif /* not sun */
- }
- return True;
- }
- static char *
- findNonBlank(
- char *pLine,
- int lineLen)
- {
- int byteNum, charNum;
- wchar_t wc;
- size_t mbCurMax = MB_CUR_MAX;
- for(byteNum = charNum = 0; charNum < lineLen;
- byteNum += mblen(&pLine[byteNum], mbCurMax), charNum++)
- {
- (void) mbtowc(&wc, &pLine[byteNum], mbCurMax);
- #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
- if( !iswctype(wc, _DtEditor_blankClass) )
- return &pLine[byteNum];
- #else
- if(! iswblank(wc) )
- return &pLine[byteNum];
- #endif /* not sun */
- }
- return &pLine[byteNum];
- }
- static int
- countBlanks(
- char *pLine,
- int lineLen)
- {
- int byteNum, charNum, count;
- wchar_t wc;
- size_t mbCurMax = MB_CUR_MAX;
- for(byteNum = charNum = 0, count = 0; charNum < lineLen;
- byteNum += mblen(&pLine[byteNum], mbCurMax), charNum++)
- {
- (void) mbtowc(&wc, &pLine[byteNum], mbCurMax);
- if(iswcntrl(wc))
- {
- if(mblen(&pLine[byteNum], mbCurMax) == 1)
- {
- switch((int) pLine[byteNum])
- {
- /*
- * I don't really know what to do with weird embedded chars.
- * This is just a guess. In non-ascii locales this could
- * screw up, but I don't know how else to deal with
- * weird embedded control characters.
- */
- case '\n': /* newline */
- case '\f': /* form feed */
- count++;
- continue;
- case '\t': /* horizontal tab */
- count += 8;
- continue;
- case '\b': /* backspace */
- count--;
- continue;
- case '\r': /* carriage return */
- count = 0;
- continue;
- default:
- return count;
- }
- }
- else
- count++; /* multibyte control chars??? */
- continue;
- }
- #if !(defined(sun) && (_XOPEN_VERSION==3)) && !defined(USL) && !defined(__uxp__)
- if(!iswctype(wc, _DtEditor_blankClass))
- return count;
- #else
- if(! iswblank(wc) )
- return count;
- #endif /* not sun */
- count++;
- }
- return count;
- }
- /*
- * fixLeftMarginAndNewlines - writes out a substring from the text widget,
- * inserting leading blanks as needed to set the left margin, and adding
- * newlines at all "virtual" (i.e. word-wrapped) lines. It assumes that the
- * specified substring is an integer number of lines - i.e. the substring
- * cannot begin or end in the middle of a line. Non-complying substrings
- * are expanded to encompass whole lines.
- */
- static void
- fixLeftMarginAndNewlines(
- DtEditorWidget editor,
- FILE *fp,
- int leftMargin,
- int rightMargin,
- int startPos,
- int endPos)
- {
- Widget widget = M_text(editor);
- register XmTextLineTable lineTable;
- register int i;
- int lineIndex, lineLen, nextLen, lineIndent, lastIndex,
- lineByteLen, total_lines;
- Boolean newPara = True;
- char *pLine, *pNext, *pFirstNonBlank, *pLastChar;
- size_t mbCurMax = MB_CUR_MAX;
- lineTable = _XmTextGetLineTable(widget, &total_lines);
- if (leftMargin > rightMargin || leftMargin < 0)
- leftMargin = 0;
- lineIndent = leftMargin;
- /*
- * calculate the starting line number and ending line number
- * for the [sub]string we're operating upon.
- */
- lineIndex = _DtEditorGetLineIndex((XmTextWidget)M_text(editor), startPos);
- lastIndex = _DtEditorGetLineIndex((XmTextWidget)M_text(editor), endPos);
- /*
- * This loop terminates with one line unwritten. This is correct
- * if we're not formatting the last line of the file, as that means
- * that we must be formatting a paragraph, and the paragraph adjust
- * code has trouble locating the end of a paragraph (as opposed to the
- * beginning of the next paragraph. If the last line of the text is
- * to be formatted, it is handled after this loop terminates.
- */
- for(; lineIndex < lastIndex; lineIndex++)
- {
- /*
- * if the current line was word-wrapped, put out a nl.
- */
- if(lineTable[lineIndex].virt_line)
- fwrite("\n", sizeof(char), 1, fp);
- lineLen = lineTable[lineIndex + 1].start_pos -
- lineTable[lineIndex].start_pos;
- pLine = _XmStringSourceGetString((XmTextWidget)M_text(editor),
- lineTable[lineIndex].start_pos,
- lineTable[lineIndex + 1].start_pos, False);
- pLastChar = _DtEditorGetPointer(pLine, lineLen - 1);
- lineByteLen = pLastChar - pLine + mblen(pLastChar, mbCurMax);
- if(lineBlank(pLine, lineLen))
- {
- /*
- * Blank lines indicate the start of a new paragraph.
- * They also don't require any indent adjustment so are
- * quick/easy to write out.
- */
- fwrite( pLine, sizeof(char),
- _DtEditorGetPointer(pLine, lineLen) - pLine, fp );
- newPara = True;
- XtFree(pLine);
- continue;
- }
- if(newPara == True)
- {
- int firstIndent;
- /*
- * Calc the proper indent for the first line, and
- * the indent for the rest of the lines
- * in the paragraph. If there's only one line in the
- * paragraph, then the proper indent is adjustStuff.left_margin.
- */
- /*
- * Get the next line.
- */
- if((total_lines - lineIndex) > 2)
- nextLen = lineTable[lineIndex + 2].start_pos -
- lineTable[lineIndex + 1].start_pos;
- else
- nextLen = XmTextGetLastPosition(widget) -
- lineTable[lineIndex + 1].start_pos;
- pNext = _XmStringSourceGetString((XmTextWidget)M_text(editor),
- lineTable[lineIndex + 1].start_pos,
- lineTable[lineIndex + 1].start_pos + nextLen, False);
- if(lineBlank(pNext, nextLen)) /* single line paragraph */
- firstIndent = lineIndent = leftMargin;
- else
- {
- int curFirstIndent, curSecondIndent, offset;
- curFirstIndent = countBlanks(pLine, lineLen);
- curSecondIndent = countBlanks(pNext, nextLen);
- offset = curFirstIndent - curSecondIndent;
- if(offset >= 0)
- {
- /* second line is closer to the left margin */
- /*
- * Note, the first line will still be indented even
- * if the remaining words in the paragraph can
- * all fit on the first line. The end result is a
- * one line indented paragraph. I am mentioning
- * this because some may think this is a defect.
- */
- firstIndent = leftMargin + offset;
- lineIndent = leftMargin;
- }
- else
- {
- firstIndent = leftMargin;
- lineIndent = leftMargin - offset;
- }
- }
- for(i = firstIndent; i-- > 0;)
- fwrite(" ", sizeof(char), 1, fp); /* that's a _space_ */
- pFirstNonBlank = findNonBlank(pLine, lineLen);
- fwrite(pFirstNonBlank, sizeof(char), lineByteLen -
- (pFirstNonBlank - pLine), fp);
- newPara = False;
- XtFree(pLine);
- continue;
- }
- for(i = lineIndent; i-- > 0;)
- fwrite(" ", sizeof(char), 1, fp); /* that's a _space_ */
- pFirstNonBlank = findNonBlank(pLine, lineLen);
- fwrite(pFirstNonBlank, sizeof(char), lineByteLen -
- (pFirstNonBlank - pLine), fp);
- XtFree(pLine);
- }
- if((total_lines - lineIndex) == 1)
- {
- /*
- * Now we have to handle the last line.
- */
- if(lineTable[lineIndex].virt_line)
- fwrite("\n", sizeof(char), 1, fp);
-
- if((total_lines - lineIndex) > 2)
- lineLen = lineTable[lineIndex + 1].start_pos -
- lineTable[lineIndex].start_pos;
- else
- lineLen = XmTextGetLastPosition(widget) -
- lineTable[lineIndex].start_pos;
- if(lineLen > 0)
- {
- for(i = lineIndent; i-- > 0;)
- fwrite(" ", sizeof(char), 1, fp); /* that's a _space_ */
- pLine = _XmStringSourceGetString((XmTextWidget)M_text(editor),
- lineTable[lineIndex].start_pos,
- lineTable[lineIndex].start_pos + lineLen, False);
- pLastChar = _DtEditorGetPointer(pLine, lineLen - 1);
- lineByteLen = pLastChar - pLine + mblen(pLastChar, mbCurMax);
- if(lineBlank(pLine, lineLen))
- {
- fwrite(pLine, sizeof(char), lineByteLen, fp);
- }
- else
- {
- pFirstNonBlank = findNonBlank(pLine, lineLen);
- fwrite(pFirstNonBlank, sizeof(char), lineByteLen -
- (pFirstNonBlank - pLine), fp);
- }
- XtFree(pLine);
- }
- }
- XtFree((XtPointer)lineTable);
- }
- /************************************************************************
- * FormatText -
- *
- * Initialize, check arguments embedded in AdjRec, open and read files,
- * and pass a series of lines to lower-level routines.
- */
- static int
- FormatText (
- AdjRecPtr
- pAdjRec)
- {
- long maxmargin; /* max allowed */
- register FILE *filep; /* file to read */
- int retVal;
- FormatData data;
- /*
- * INITIALIZE FOR NLS
- */
- mbtowc(&data.Blank," ",1);
- /*
- * Initialize global/statics.
- */
- if((data.wordbuf = malloc(sizeof(wint_t) * LINESIZE * 3)) == (wint_t *)NULL)
- return 0;
- if((data.word = malloc(sizeof(WORD) * WORDMAX)) == (WORD *)NULL)
- {
- retVal = 0;
- goto CleanUp;
- }
- data.tabsize = 8; /* default tab size */
- data.centerstartpara = True;
- data.fillmargin = data.centermiddle = pAdjRec->margin;
- data.m0flag = (data.fillmargin == 0L);
- /*
- * Initialize global/statics for "Fill".
- */
- data.wordcp = data.wordbuf;
- data.wordcpwrap = data.wordbuf + (LINESIZE * 2);
- data.wordbase = & data.word [0];
- data.wordlimit = & data.word [WORDMAX];
- data.wordfirst = & data.word [0];
- data.wordnext = & data.word [0];
- data.inlinenum = 0;
- data.outlinenum = 1;
- data.pendchars = 0;
- /*
- * CHECK ARGUMENTS:
- */
- if (pAdjRec->cflag + pAdjRec->jflag + pAdjRec->rflag > 1)
- {
- retVal = 0;
- goto CleanUp;
- }
- maxmargin = pAdjRec->cflag? (LINESIZE / 2) : LINESIZE;
- if ((data.fillmargin < 0L) || (data.fillmargin > maxmargin))
- {
- retVal = 0;
- goto CleanUp;
- }
- if ((pAdjRec->tabsize > 0) && (pAdjRec->tabsize <= MAXTABSIZE))
- data.tabsize = pAdjRec->tabsize;
- /*
- * OPEN AND READ INPUT FILE:
- */
- filep = pAdjRec->infp;
- data.pAdj = pAdjRec; /* set (file) global var to passed in rec */
- while (DoLine (&data, filep))
- ;
- /*
- * DUMP LAST LINE AND EXIT:
- */
- if (! data.pAdj->cflag) /* not centering */
- {
- Dump (&data, True); /* force end paragraph */
- }
- retVal = 1;
- CleanUp:
- if(data.wordbuf != (wint_t *)NULL)
- {
- free(data.wordbuf);
- }
- if(data.word != (WORD *)NULL)
- {
- free(data.word);
- }
- return retVal;
- }
- /************************************************************************
- * D O L I N E
- *
- * Read one input line and do generic processing (read chars from input
- * to in_line, crunching backspaces). Return True if successful, else
- * false at end of input file. This must be done before expanding tabs;
- * pass half-processed line to Center() or Fill() for more work.
- *
- * Assumes getc() is efficient.
- * in_line[] is static so it is only allocated once.
- */
- static int
- DoLine (FormatData *data,
- register FILE *filep) /* open file to read */
- {
- wint_t in_line [LINESIZE]; /* after reading in */
- register wint_t *incp = in_line; /* place in in_line */
- register wint_t *incplim = in_line + LINESIZE; /* limit of in_line */
- register wint_t c;
- /*
- * READ LINE WITH BACKSPACE CRUNCHING:
- */
- while (incp < incplim) /* buffer not full */
- {
- c = getwc (filep); /* get and save wide char */
- switch(c)
- {
- case WEOF:
- if (incp == in_line) /* nothing read yet */
- return (False);
- case L'\0': /* fall through */
- case L'\n': /* end of line */
- incplim = incp; /* set limit (quit loop) */
- break;
- case L'\b': /* backspace */
- if (incp > in_line) /* not at start */
- incp--; /* just back up */
- break;
- default: /* any other char */
- *incp++ = c;
- break;
- }
- }
- /* now incplim is correctly set to last char + 1 */
- /*
- * PASS LINE ON FOR MORE WORK:
- */
- if (data->pAdj->cflag) Center (data, in_line, incplim);
- else Fill (data, in_line, incplim);
- return (True); /* maybe more to read */
- } /* DoLine */
- /************************************************************************
- * C E N T E R
- *
- * Center text (starting at in_line, ending before inlinelim). First copy
- * chars from in_line to outline skipping nonprintables and expanding tabs.
- * For efficiency (at the cost of simplicity), note and skip indentation
- * at the same time. Then, print outline with indentation to center it.
- *
- * outline[] is static so it is only allocated once; startpara so it is
- * used for successive lines.
- */
- static void
- Center (FormatData *data,
- wint_t *in_line, /* start of input line */
- register wint_t *inlinelim) /* end of line + 1 */
- {
- register wint_t *incp; /* pointer in in_line */
- wint_t outline [LINESIZE + MAXTABSIZE]; /* after generic work */
- register wint_t *outcp = outline; /* place in outline */
- register wint_t *outlinelim = outline + LINESIZE; /* limit of outline*/
- int haveword = False; /* hit word in in_line? */
- register wint_t ch; /* current working char */
- register int needsp; /* spaces need for tab */
- register int indent = 0; /* size of indentation */
- int textwidth; /* size of text part */
- int extwidth = 0; /* additional width for MBCS */
- /*
- * SCAN INPUT LINE:
- */
- for (incp = in_line; (incp < inlinelim) && (outcp < outlinelim); incp++)
- {
- ch = *incp;
- /*
- * SKIP WHITE SPACE:
- */
- if (iswspace(ch))
- {
- needsp = ((ch != L'\t') && (iswblank(ch))) ?
- 1 : data->tabsize - ((indent + outcp - outline) % data->tabsize);
- if (! haveword) /* indentation */
- indent += needsp;
- else /* past text */
- for ( ; needsp > 0; needsp--)
- *outcp++ = data->Blank;
- }
- /*
- * CARRY OVER PRINTABLE CHARS AND NOTE INDENTATION:
- */
- else if (iswprint (ch)) /* note: ch != ' ' */
- {
- *outcp++ = ch; /* just copy it over */
- haveword = True;
- if(MB_CUR_MAX > 1 && wcwidth(ch) > 1)
- extwidth += wcwidth(ch) - 1;
- }
- /* else do nothing, which tosses other chars */
- } /* end for */
- /* Now outcp is the new outlinelim */
- /*
- * HANDLE BLANK LINE (no text):
- */
- if (! haveword)
- {
- putc ('\n', data->pAdj->outfp); /* "eat" any whitespace */
- data->centerstartpara = True; /* expect new paragraph */
- }
- /*
- * EAT TRAILING BLANKS, SET TEXTWIDTH:
- */
- else
- {
- /* note that outcp > outline */
- while ((outcp[-1] != L'\t') && iswblank(outcp [-1]))
- outcp--;
- textwidth = (outcp - outline); /* thus textwidth > 0 */
- /*
- * SET AUTOMARGIN AND PRINT CENTERED LINE:
- *
- * The equations used depend on truncating division:
- *
- * eqn. 1 eqn. 2
- * Margin Middle Width Results
- * odd exact odd exact centering
- * odd exact even extra char to right
- * even left odd extra char to left
- * even left even exact centering (due to "extra" char to right)
- *
- * When centermiddle is default or given by user, it is the same as the
- * first two lines above (middle exactly specified).
- */
- if (data->centerstartpara) /* start of paragraph */
- {
- data->centerstartpara = False;
- if (data->m0flag) /* set automargin */
- /* 1 */ data->centermiddle = (indent + textwidth + extwidth + 1) / 2;
- }
- /* 2 */ PrintIndent (data, data->centermiddle - ((textwidth + extwidth + 1) / 2));
- {
- int i;
- for(i = 0; i < textwidth; i++)
- {
- putwc(outline[i], data->pAdj->outfp);
- }
- putc('\n', data->pAdj->outfp);
- }
- } /* else */
- } /* Center */
- /************************************************************************
- * WORD DATA STRUCTURES USED TO TRACK WORDS WHILE FILLING:
- *
- * This complicated scheme is used to minimize the actual data moving
- * and manipulation needed to do the job.
- *
- * Words are kept in wordbuf[] without trailing nulls. It is large enough
- * to accomodate two lines' worth of words plus wrap around to start a new
- * word (which might be as big as a line) without overwriting old words
- * not yet dumped. wordcp -> next free location in wordbuf[];
- * wordcpwrap -> last place a new word is allowed to start.
- *
- * Words are pointed to and described by word[] structures. The array is
- * big enough to accomodate two lines' worth of words, assuming each word
- * takes at least two characters (including separator). wordbase and
- * wordlimit are the bounds of the array. wordfirst remembers the first
- * word in the array not yet printed. wordat is the word being worked on
- * after wordnext is advanced (and maybe wrapped around). New elements
- * are "allocated" using wordnext, a pointer that is wrapped around as
- * needed.
- *
- * inlinenum and incolumn track the current input line and column per
- * paragraph. outlinenum tracks the next line to print. All are base 1,
- * but inlinenum is preset to zero at the start of each paragraph.
- *
- * pendchars tracks the number of dumpable characters accrued so far, to
- * trigger dumping. indent1 and indent2 remember the indentations seen
- * for the first two lines of each paragraph.
- */
- /************************************************************************
- * F I L L
- *
- * Parse an input line (in_line to inlinelim) into words and trigger
- * FillWord() as needed to finish each word, which in turn can call
- * Dump() to dump output lines. This routine sacrifices simplicity and
- * clarity for efficiency. It uses shared global word data except
- * outlinenum and pendchars.
- */
- static void
- Fill (FormatData *data,
- wint_t *in_line, /* start of input line */
- register wint_t *inlinelim) /* end of line + 1 */
- {
- register wint_t *incp; /* place in in_line */
- register wint_t ch; /* current working char */
- int haveword = False; /* hit word in in_line? */
- register int inword = False; /* currently in a word? */
- /*
- * SCAN INPUT LINE:
- */
- data->inlinenum++;
- data->incolumn = 1; /* starting a line */
- for (incp = in_line; incp < inlinelim; incp++)
- {
- ch = *incp;
- /*
- * AT WHITE SPACE; FINISH PREVIOUS WORD if any, then skip white space:
- */
- if (iswspace(ch))
- {
- if (inword) /* was skipping a word */
- {
- inword = False;
- FillWord(data);
- }
- data->incolumn += ((ch != L'\t') && (iswblank(ch))) ?
- 1 : data->tabsize - ((data->incolumn - 1) % data->tabsize);
- }
- /*
- * AT PART OF WORD; START NEW ONE IF NEEDED:
- */
- else if (iswprint (ch))
- {
- if (! inword) /* start new word */
- {
- inword = True;
- if (data->wordcp > data->wordcpwrap)/* past wrap point */
- data->wordcp = data->wordbuf;/* wraparound buffer */
- data->wordat = data->wordnext;
- WORDNEXT (data,data->wordnext);
- data->wordat->cp = data->wordcp; /* note start of word */
- data->wordat->inlinenum = data->inlinenum; /* note input line */
- data->wordat->incolumn = data->incolumn; /* note input column */
- data->wordat->wclen = 0;
- if (! haveword)
- {
- haveword = True;
-
- switch (data->inlinenum)/* note indentations */
- {
- case 1:
- data->indent1 = data->incolumn - 1;
- break;
- case 2:
- data->indent2 = data->incolumn - 1;
- break;
- }
- }
- }
- /*
- * SAVE ONE CHAR OF WORD:
- */
- *(data->wordcp++) = ch;
- {
- int n = wcwidth(ch);
- if (n > 0)
- { /* == 0 for a null char */
- data->incolumn += n;
- data->wordat->wclen++;
- }
- }
- } /* else */
- /* else skip other chars by doing nothing */
- } /* for */
- /*
- * END OF LINE; HANDLE BLANK LINE, OR FINISH WORD AND AUTOMARGIN:
- */
- if (! haveword) /* no text on line */
- {
- data->inlinenum--; /* don't count empty lines */
- Dump (data, True); /* force end paragraph */
- fputc ('\n', data->pAdj->outfp); /* put this empty line */
- data->inlinenum = 0; /* start new paragraph */
- }
- else /* have text on line */
- {
- if (inword) /* line ends in word */
- FillWord(data);
- if (data->pendchars > data->fillmargin)
- { /* time to dump line */
- Dump (data, False); /* not end of paragraph */
- }
- if (data->m0flag && (data->inlinenum == 1)) /* need to note right margin */
- data->fillmargin = data->wordat->incolumn + data->wordat->length - 1;
- }
- } /* Fill */
- /************************************************************************
- * F I L L W O R D
- *
- * Save values for the word just finished and dump the output line if
- * needed. Uses shared global word values, but does not touch outlinenum,
- * and only increments pendchars.
- *
- * Trailing blanks (1 or 2) needed after a word are figured here.
- * wordlen is the total length (nonzero) and wordcp points to the char
- * past the end of the word. Two blanks are needed after words ending in:
- *
- * <terminal>[<quote>][<close>]
- *
- * where <terminal> is any of . : ? !
- * <quote> is any of ' "
- * <close> is any of ) ] }
- *
- * For efficiency, this routine avoids calling others to do character
- * matching; it does them in line.
- */
- static void
- FillWord (FormatData *data)
- {
- int wordlen; /* length of word to fill */
- int blanks = 1; /* trailing blanks needed */
- register wint_t ch1, ch2, ch3; /* last chars of word */
- data->wordat->length = (data->incolumn - data->wordat->incolumn);
- wordlen = data->wordat->wclen;
- /*
- * CHECK FOR SPECIAL END OF WORD:
- */
- ch3 = data->wordcp [-1];
- if ((ch3 == L'.') || (ch3 == L':') || (ch3 == L'?') || (ch3 ==L'!'))
- {
- blanks = 2; /* <terminal> */
- }
- else if (wordlen >= 2)
- {
- ch2 = data->wordcp [-2];
- if( ((ch2 == L'.') || (ch2 == L':') || (ch2 ==L'?') || (ch2 == L'!')) &&
- ((ch3 == L'\'') || (ch3 == L'"') || (ch3 ==L')') || (ch3 == L']')
- || (ch3 == L'}'))
- )
- {
- blanks = 2; /* <terminal><quote or close> */
- }
- else if (wordlen >= 3)
- {
- ch1 = data->wordcp [-3];
- if( ((ch1 == L'.') || (ch1 == L':') || (ch1 == L'?') || (ch1 == L'!'))
- && ((ch2 == L'\'') || (ch2 == L'"'))
- && ((ch3 == L')') || (ch3 == L']') || (ch3 == L'}')) )
- {
- blanks = 2; /* <terminal><quote><close> */
- }
- }
- } /* else */
- /*
- * SAVE VALUES
- */
- data->pendchars += wordlen + (data->wordat->blanks = blanks);
- } /* FillWord */
- /************************************************************************
- * D U M P
- *
- * Print output line(s), with all necessary indentation and formatting,
- * if required (at end of paragraph) or if permissible. If required,
- * indent1 is used if indent2 is not set yet (not on second line of
- * input). Otherwise, if not at end of paragraph, dumping is only
- * permissible after beginning the second input line, so fillmargin and
- * indent2 are known, so tagged paragraphs are done right.
- *
- * Whenever dumping, all "full" lines are dumped, which means more than
- * just one may be printed per call. jflag or rflag formatting is
- * applied to all lines, except that jflag is ignored for the last line
- * of each paragraph.
- *
- * Uses shared global word data, but does not touch inlinenum, incolumn,
- * indent1, or indent2.
- */
- static void
- Dump (FormatData *data,
- int endpara) /* end of paragraph? */
- {
- int haveindent2 = (data->inlinenum >= 2); /* indent2 known? */
- int startpara; /* start of paragraph? */
- int normal; /* non-tagged line? */
- WORD *wordpast = data->wordfirst; /* past last to dump */
- register int wordlen; /* length of one word */
- int indent; /* local value */
- register int outneed; /* chars need to dump */
- int outchars; /* chars found to dump */
- /*
- * IF DUMPING NEEDED, DUMP LINES TILL DONE:
- */
- if (! (endpara || haveindent2)) /* not time to dump */
- return;
- while ( (data->pendchars > data->fillmargin) /* line is full */
- || (endpara && (data->wordfirst != data->wordnext)) ) /* more to dump */
- {
- startpara = (data->outlinenum < 2);
- indent = (startpara || (! haveindent2)) ? data->indent1 : data->indent2;
- /*
- * CHECK FOR TAGGED PARAGRAPH if needed:
- */
- normal = True; /* default == no tag */
- if (startpara && haveindent2 && (data->indent1 < data->indent2))
- {
- int incol2 = data->indent2 + 1; /* column needed */
- while ( (wordpast != data->wordnext) /* more words */
- && (wordpast->inlinenum == 1)) /* from line 1 */
- {
- if (wordpast->incolumn == incol2) /* bingo */
- {
- normal = False;
- break;
- }
- WORDNEXT (data,wordpast);
- }
- if (normal)
- wordpast = data->wordfirst; /* reset value */
- /*
- * PRINT TAG PART OF TAGGED PARAGRAPH:
- */
- else
- {
- WORD *wordat = data->wordfirst; /* local value */
- while (wordat != wordpast) /* decrement pendchars */
- {
- data->pendchars -= wordat->length + wordat->blanks;
- WORDNEXT (data,wordat);
- }
-
- PrintIndent (data, indent);
- PrintTag (data, wordpast); /* preceding words */
- data->wordfirst = wordpast; /* do rest of line */
- indent = data->indent2; /* as if second line */
- }
- } /* if */
- /*
- * FIND WORDS WHICH FIT ON [REST OF] LINE:
- */
- if (indent >= data->fillmargin) /* don't over indent */
- indent = data->fillmargin - 1;
- outneed = data->fillmargin - indent; /* always greater than zero */
- outchars = 0;
- wordlen = wordpast->length;
- do { /* always consume one */
- outchars += wordlen + wordpast->blanks;
- WORDNEXT (data,wordpast);
- } while ( (wordpast != data->wordnext) /* not last word */
- && (outchars + (wordlen = wordpast->length) <= outneed)
- );
- /* next will fit */
- /*
- ** BEKINSOKU/EKINSOKU PROCESSING
- */
- if( EkinBekinProc(data, &wordpast) )
- postEkinBekinProc(data, &outchars,wordpast);
- data->pendchars -= outchars; /* pendchars to consume */
- /* from now on, don't include trailing blanks on last word */
- outchars -= (WORDPREV (data,wordpast) -> blanks);
- /* now wordfirst and wordpast specify the words to dump */
- /*
- * PRINT INDENTATION AND PREPARE JUSTIFICATION:
- */
- if (data->pAdj->rflag) /* right-justify only */
- {
- if (normal) /* nothing printed yet */
- PrintIndent (data, data->fillmargin - outchars);
- else /* indent + tag printed */
- {
- int blanks = data->fillmargin - outchars - indent;
- while (blanks-- > 0) /* can't use PrintIndent()*/
- putwc(data->Blank, data->pAdj->outfp);
- }
- }
- else
- {
- if (normal) /* not already done */
- PrintIndent (data, indent);
- if (data->pAdj->jflag && ! (endpara && (wordpast == data->wordnext)))
- Justify (data, outneed - outchars, wordpast);
- }
- /*
- * PRINT REST OF LINE:
- */
- PrintWords (data, wordpast);
- putwc('\n', data->pAdj->outfp);
- data->wordfirst = wordpast;
- data->outlinenum++; /* affects startpara */
- } /* while */
- if (endpara)
- data->outlinenum = 1;
- } /* Dump */
- /************************************************************************
- * P R I N T I N D E N T
- *
- * Print line indentation (if > 0), optionally using tabs where possible.
- * Does not print a newline.
- */
- static void
- PrintIndent (FormatData *data,
- int indent) /* leading indentation */
- {
- if (indent > 0) /* indentation needed */
- {
- if (! data->pAdj->bflag) /* unexpand leading blanks */
- {
- while (indent >= data->tabsize)
- {
- putc ('\t', data->pAdj->outfp);
- indent -= data->tabsize;
- }
- }
- fprintf (data->pAdj->outfp, "%*s", indent, "");/*[remaining] blanks */
- }
- } /* PrintIndent */
- /************************************************************************
- * P R I N T T A G
- *
- * Print paragraph tag words from word[] array beginning with (global)
- * wordfirst and ending before (parameter) wordpast, using input column
- * positions in each word's data. Assumes indentation of indent1 was
- * already printed on the line. Assumes *wordpast is the next word on
- * the line and its column position is valid, and appends spaces up to
- * the start of that word. Doesn't print a newline.
- *
- * Line indentation must already be done, as this routine doesn't know
- * how to print leading tabs, only blanks.
- */
- static void
- PrintTag (FormatData *data,
- WORD *wordpast) /* past last to print */
- {
- register WORD *wordat = data->wordfirst; /* local value */
- register int outcol = data->indent1 + 1; /* next column */
- int wordcol; /* desired column */
- register wint_t *wordcp; /* place in word */
- wint_t *wordcplim; /* limit of word */
- while (True) /* till break */
- {
- wordcol = wordat->incolumn;
- while (outcol < wordcol)/* space over to word */
- {
- putwc(data->Blank, data->pAdj->outfp);
- outcol++;
- }
- if (wordat == wordpast) /* past last word */
- break; /* quit the loop */
- wordcp = wordat->cp;
- wordcplim = wordcp + wordat->wclen;
- while (wordcp < wordcplim) /* print word */
- putwc(*wordcp++, data->pAdj->outfp);
- outcol += wordat->length;
- WORDNEXT (data,wordat);
- }
- } /* PrintTag */
- /************************************************************************
- * P R I N T W O R D S
- *
- * Print words from word[] array beginning with (global) wordfirst and
- * ending before (parameter) wordpast, using word sizes and trailing
- * blanks (except for last word on line). Doesn't print a newline.
- */
- static void
- PrintWords (FormatData *data,
- WORD *wordpast) /* past last to print */
- {
- register WORD *wordat = data->wordfirst; /* local value */
- register wint_t *wordcp; /* place in word */
- wint_t *wordcplim; /* limit of word */
- register int blanks; /* after a word */
- while (True) /* till break */
- {
- wordcp = wordat->cp;
- wordcplim = wordcp + wordat->wclen;
- blanks = wordat->blanks; /* set before do WORDNEXT() */
- while (wordcp < wordcplim) /* print word */
- {
- putwc(*wordcp++, data->pAdj->outfp);
- }
- wordat->wclen = 0;
- WORDNEXT (data,wordat);
- if (wordat == wordpast) /* just did last word */
- break;
- while (blanks-- > 0) /* print trailing blanks */
- putwc(data->Blank, data->pAdj->outfp);
- }
- } /* PrintWords */
- /************************************************************************
- * J U S T I F Y
- *
- * Do left/right justification of [part of] a line in the word[] array
- * beginning with (global) wordfirst and ending before (parameter)
- * wordpast, by figuring where to insert blanks.
- *
- * Gives each word (except the last on the line) a score based on its
- * size plus the size of the next word. Quicksorts word indices into
- * order of current trailing blanks (least first), then score (most
- * first). Cycles through this list adding trailing blanks to word[]
- * entries such that words will space out nicely when printed.
- */
- static void
- Justify (FormatData *data,
- register int blanks, /* blanks to insert */
- WORD *wordpast) /* past last to print */
- {
- register WORD *wordat; /* local value */
- register int sortat; /* place in sort[] */
- register int wordlen; /* size of this word */
- register int nextlen; /* size of next word */
- int level; /* current blanks level */
- WORD *sort [WORDMAX]; /* sorted pointers */
- int words; /* words in sort[] */
- wordat = WORDPREV (data,wordpast); /* last word on line */
- if ((blanks < 1) || (wordat == data->wordfirst))
- return; /* can't do anything */
- /*
- * COMPUTE SCORES FOR WORDS AND SORT INDICES:
- *
- * March backwards through the words on line, starting with next to last.
- */
- words = 0;
- nextlen = wordat->length; /* length of last word */
- do { /* always at least one */
- wordat = WORDPREV (data,wordat);
- wordlen = wordat->length;
- wordat->score = wordlen + nextlen; /* this plus next */
- nextlen = wordlen;
- sort [words++] = wordat; /* prepare for sorting */
- } while (wordat != data->wordfirst);
- qsort ((wint_t *) sort, words, sizeof (WORD *), CompareWords);
- /*
- * ADD TRAILING BLANKS TO PAD OUT WORDS:
- *
- * Each pass through the sorted list adds one trailing blank to each word
- * not already past the current level. Thus all one-blank words are brought
- * up to two; then all twos up to three; etc.
- */
- level = 0;
- while (True) /* till return */
- {
- level++;
- for (sortat = 0; sortat < words; sortat++)
- {
- wordat = sort [sortat];
- if (wordat->blanks > level) /* end of this level */
- break; /* start next level */
- wordat->blanks++;
- if (--blanks <= 0) /* no more needed */
- return;
- }
- }
- } /* Justify */
- /************************************************************************
- * C O M P A R E W O R D S
- *
- * Compare two word[] entries based on pointers to (WORD *), as called
- * from qsort(3). Tell which entry has priority for receiving inserted
- * blanks (least trailing blanks first, then highest scores), by returning
- * -1 for the first entry, +1 for second entry, or 0 if no difference.
- * (-1 literally means first entry < second entry, so it sorts first.)
- */
- static int
- CompareWords (const void *p1, const void *p2)
- {
- WORD *word1 = *((WORD **)p1); /* (WORD *) pointers */
- WORD *word2 = *((WORD **)p2);
- int blanks1 = word1->blanks; /* trailing blanks */
- int blanks2 = word2->blanks;
- if (blanks1 == blanks2) /* commonest case */
- {
- int score1 = word1->score; /* word scores */
- int score2 = word2->score;
- if (score1 > score2) return (-1); /* word1 has priority */
- else if (score1 < score2) return ( 1);
- else return (0);
- }
- else if (blanks1 < blanks2) return (-1); /* word1 has priority */
- else return ( 1);
- } /* CompareWords */
- /*
- ** BKINSOKU and EKINSOKU processing for Japanese text
- **
- ** The function scans the wordlist that are ready for printing
- ** and updates the "wordpast" pointer based on the rules of
- ** BKINSOKU and EKINSOKU characters.
- **
- ** The code does not split a line just after a "gyomatu kinsoku"
- ** character and just before a "gyoto kinsoku" character.
- ** "Gyomatsu kinsoku" (e-kinsoku) are characters which cannot be
- ** placed at the end of a line. "Gyoto kinsoku" (b-kinsoku) are
- ** characters which can not be placed at the top of a line.
- **
- ** Global variables used:
- ** wordfirst - beginning the word list (buffer of pending lines)
- ** wordnext - next available spot in the pending buffer (i.e.
- ** end of the buffer).
- **
- ** Global variables modified:
- ** None.
- **
- ** Return Values:
- ** 0 - No Post processing is required.
- ** 1 - Post processing is required
- */
- #if !(defined(sun) && (_XOPEN_VERSION==3))
- static int
- EkinBekinProc(FormatData *data,
- WORD **wordpast)
- {
- WORD *curword,*compword,*prevword;
- int ekinflag = False, margin;
- /*
- * curword points to the last word of the first line.
- * compword points to the first word of the next line or to the next
- * available spot if there is no next line.
- */
- compword = *wordpast;
- curword = WORDPREV(data,compword);
- /*
- * If the length of the current word is > fillmargin
- * or it is the only word then return.
- */
- if (curword->length > data->fillmargin || (curword == data->wordfirst))
- return False;
- /*
- * EKINSOKU processing
- * If this character set supports ekinclass (can't end a line) char,
- * start at the end of the line and search back until
- * 1) we find a non-ekinsoku character, or
- * 2) come to the beginning of the pending buffer.
- */
- if (ekinclass)
- {
- while (isekinsoku(*(curword->cp+curword->wclen-1)))
- {
- ekinflag = True;
- if (curword == data->wordfirst) /* Boundary Condition */
- break;
- curword = WORDPREV(data,curword);
- }
- /*
- * Post EKIN processing (i.e. we found an ekinsoku character in
- * the line before finding an non-ekinsoku).
- */
- if (ekinflag) {
- if (curword != data->wordfirst) {
- /*
- * We found a non-ekinsoku after we found the ekinsoku.
- * Move the end of line to just after the non-ekinsoku.
- */
- WORDNEXT(data,curword);
- *wordpast = curword;
- return True;
- }
- else { /* Boundary condition */
- /*
- * Reached the beginning of the buffer without finding a
- * non-ekinsoku. If the last word in the line can begin
- * a line (i.e. non-bkinsoku) make it the first word of
- * the next line.
- */
- curword = WORDPREV(data,compword);
- if (!isbekinsoku(*curword->cp)) {
- *wordpast = curword;
- return True;
- }
- return False;
- }
- }
- }
- /*
- * If we reached this point then:
- * 1) the character set does not support ekinclass characters, or
- * 2) the last character in the line is non-ekinsoku.
- * Now, need to see if we can begin the next line with the first
- * character on that line.
- */
- /*
- * BEKINSOKU processing
- * If this character set supports bekinclass (can't begin a line) char,
- * search forward from the begining of the next line (curword) to the
- * end of the buffer (wordnext) until:
- * 1) A non-bekinsoku word is found,
- * 2) if the line limit exceeds the set value, or
- * 3) we reach the end of the buffer.
- */
- if (bekinclass)
- {
- /*
- * compword points to the first word of the next line.
- */
- curword = compword;
- margin = data->indent2;
- while (curword != data->wordnext)
- {
- if (!isbekinsoku(*curword->cp))
- break;
- margin += (curword->length + curword->blanks);
- if (margin >= data->fillmargin)
- return False;
- WORDNEXT(data,curword);
- }
- if (curword != data->wordnext && curword != compword)
- {
- /*
- * The first word of the second line is bekinsoku so search
- * backwards from end of first line until we are:
- * 1) not at the first word of the buffer, and
- * 2) not in between either an ekinsoku or bekinsoku character.
- */
- /*
- * compword points to the first word of the next line.
- * curword points to the last word of the first line.
- */
- curword = WORDPREV(data,compword);
- prevword = WORDPREV(data,curword);
- while ( (curword != data->wordfirst) &&
- (isbekinsoku(*curword->cp) ||
- isekinsoku(*(prevword->cp+prevword->wclen-1)))
- )
- {
- margin += curword->length + curword->blanks;
- if (margin >= data->fillmargin)
- return False;
- curword = prevword;
- prevword = WORDPREV(data,curword);
- }
- if (curword != data->wordfirst) {
- /*
- * Did not reach the beginning of the buffer so we are between
- * two non-ekinsoku & non-bekinsoku characters. Move the end
- * of the first line here.
- */
- *wordpast = curword;
- return True;
- }
- }
- return False;
- }
- return False;
- } /* end EkinBekinProc */
- #else
- static int
- EkinBekinProc(FormatData *data,
- WORD **wordpast)
- {
- WORD *curword,*compword,*prevword,*nextword;
- int margin = data->indent2;
- /*
- * prevword points to the last word of the first line.
- * compword & curword point to the first word of the next line or
- * to the next available spot in the buffer if there is no next line.
- */
- compword = *wordpast;
- curword = compword;
- prevword = WORDPREV(data,curword);
- /*
- * If the length of the previous word is > fillmargin
- * or it is the only word in the line then return.
- * wordfirst points to the beginning of the buffer of pending lines.
- */
- if (prevword->length > data->fillmargin || (prevword == data->wordfirst))
- return False;
- /*
- * Starting at the beginning of the next line, search backwards
- * until:
- * 1) we find two words we can split between lines, or
- * 2) we reach the beginning of the buffer.
- *
- * If there is no next line start with the last two words of this line
- * (wordnext points to the next available space in the buffer (i.e
- * the end of the buffer).
- */
- if (curword == data->wordnext) {
- curword = prevword;
- prevword = WORDPREV(data,curword);
- }
- while ( (curword != data->wordfirst) &&
- (wdbindf(*(prevword->cp+prevword->wclen-1), *curword->cp, 1) >4)
- )
- {
- curword = prevword;
- prevword = WORDPREV(data,curword);
- }
- if (curword != data->wordfirst) {
- /*
- * Did not reach the beginning of the buffer so we are between
- * two non-ekinsoku & non-bekinsoku characters. Move the end
- * of the first line here.
- */
- *wordpast = curword;
- return True;
- }
- else {
- /*
- * Reached the beginning of the buffer so search forward
- * from the beginning of the second line until:
- * 1) we find two words we can split between lines,
- * 2) we reach the end of the buffer, or
- * 3) the line becomes too long.
- *
- * If there is no next line then just exit.
- */
- /*
- * compword points to the first word of the next line or to the
- * next available spot in the buffer if there is no next line.
- * nextword points to the second word of the next line.
- * wordnext points to the next available space in the buffer (i.e
- * the end of the buffer)
- */
- curword = compword;
- nextword = compword;
- WORDNEXT(data,nextword);
- if (curword == data->wordnext)
- return False;
- while (nextword != data->wordnext)
- {
- if (wdbindf(*(curword->cp+curword->wclen-1), *nextword->cp, 1) < 5)
- break;
- margin += (curword->length + curword->blanks);
- if (margin >= data->fillmargin)
- return False;
- curword = nextword;
- WORDNEXT(data,nextword);
- }
- if (nextword != data->wordnext) {
- /*
- * Did not reach the end of the buffer so we are between
- * two non-ekinsoku & non-bekinsoku characters. Move the end
- * of the first line here.
- */
- *wordpast = nextword;
- return True;
- }
- return False;
- }
- } /* end EkinBekinProc */
- #endif /* not sun */
- static void
- postEkinBekinProc(FormatData *data,
- int *poutchars,
- WORD *wordpast)
- {
- WORD *curword;
- int colvalue,curlineno;
- /*
- * Recompute the value of *poutchars
- */
- (*poutchars) = 0;
- curword = data->wordfirst;
- while (curword != wordpast)
- {
- (*poutchars) += curword->length + curword->blanks;
- WORDNEXT(data,curword);
- }
- /*
- ** Adjust the word parameters -
- ** inlinenum,incolumn of all the words
- ** from 'curword' till 'wordnext'
- */
- curword = wordpast;
- curlineno = curword->inlinenum+1;
- colvalue = data->indent2;
- while (curword != data->wordnext)
- {
- curword->inlinenum = curlineno;
- curword->incolumn = colvalue;
- colvalue += curword->length + curword->blanks;
- if (colvalue > data->fillmargin)
- {
- colvalue = data->indent2;
- curlineno++;
- }
- WORDNEXT(data,curword);
- }
- data->incolumn = colvalue;
- data->inlinenum = curlineno;
- }
- #ifdef DEBUG
- static
- prnword(pword)
- WORD *pword;
- {
- int i = 0;
- if (pword == NULL)
- return;
- for (i=0; i < pword->wclen; i++)
- fprintf(stderr,(const char *)"%c",(char)*(pword->cp+i));
- fprintf(stderr,"Word Length :%d\n",pword->wclen);
- }
- #endif /* DEBUG */
- /* ARGSUSED */
- static void
- AdjustParaCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorFormat( (Widget)client_data, (DtEditorFormatSettings *)NULL,
- DtEDITOR_FORMAT_PARAGRAPH );
- } /* AdjustParaCB */
- /* ARGSUSED */
- static void
- AdjustAllCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorFormat( (Widget)client_data, (DtEditorFormatSettings *)NULL,
- DtEDITOR_FORMAT_ALL );
- } /* AdjustAllCB */
- /*********
- *
- * DoAdjust - given left & right margin values & an alignment style, formats
- * the text from one specified text position to another.
- *
- * Returns:
- * DtEDITOR_NO_ERRORS if the text was formatted successfully.
- * DtEDITOR_ILLEGAL_SIZE if the left & right margins don't make
- * sense.
- * DtEDITOR_NO_TMP_FILE if the 2 temporary files cannot be
- * created.
- * DtEDITOR_INVALID_TYPE if specified alignment is
- * unrecognized
- *
- */
- static DtEditorErrorCode
- DoAdjust(
- DtEditorWidget editor,
- int leftMargin,
- int rightMargin,
- unsigned int alignment,
- XmTextPosition start,
- XmTextPosition end)
- {
- char tempName1[L_tmpnam], tempName2[L_tmpnam];
- DtEditorErrorCode returnVal;
- AdjRec adjRec;
- /*
- * Check that valid margin values were passed in
- */
- if( leftMargin >= 0 &&
- rightMargin > 0 &&
- rightMargin < 1025 &&
- leftMargin <= rightMargin )
- {
- /*
- * Set up
- */
- _DtTurnOnHourGlass(M_topLevelShell(editor));
- if (M_format_dialog(editor) != (Widget)NULL)
- _DtTurnOnHourGlass(M_format_dialog(editor));
- memset(&adjRec, 0, sizeof(AdjRec));
- /* The adjust text formatting code works with a data
- representation to the screen of 1 byte per column for
- multibyte environment. The Motif text Widget has a data
- representation of 2 bytes per column in multibyte, so we must
- fool the adjust code into thinking the margins are twice the
- size in a multibyte environment.
- */
-
- if (MB_CUR_MAX > 1)
- {
- rightMargin = rightMargin * 2;
- leftMargin = leftMargin * 2;
- }
- switch (alignment)
- {
- case DtEDITOR_ALIGN_CENTER:
- {
- adjRec.cflag = 1;
- adjRec.margin = (rightMargin + leftMargin) / 2;
- break;
- }
- case DtEDITOR_ALIGN_JUSTIFY:
- {
- adjRec.jflag = 1;
- adjRec.margin = rightMargin;
- break;
- }
- case DtEDITOR_ALIGN_RIGHT:
- {
- adjRec.rflag = 1;
- adjRec.margin = rightMargin;
- break;
- }
- case DtEDITOR_ALIGN_LEFT:
- {
- adjRec.margin = rightMargin;
- break;
- }
- default:
- {
- returnVal = DtEDITOR_INVALID_TYPE;
- }
-
- } /* end switch */
- /*
- * Turn off converting leading spaces into tabs if we are
- * working in a multi-byte locale. This is necessary
- * because a tab may not equal (be as wide as) 8 spaces in
- * a multi-byte locale.
- */
- adjRec.tabsize = 8;
- if (MB_CUR_MAX > 1)
- adjRec.bflag = True;
- else
- adjRec.bflag = False;
- /*
- * Create the two temp files
- */
- (void)tmpnam(tempName1);
- (void)tmpnam(tempName2);
- if ((adjRec.infp = fopen(tempName1, "w+")) != (FILE *)NULL) {
- /*
- * Successfully opened the first temporary file
- */
- if((adjRec.outfp = fopen(tempName2, "w")) != (FILE *)NULL) {
- /*
- * Successfully opened the second temporary file, so do the
- * formatting.
- */
- returnVal = DtEDITOR_NO_ERRORS;
- fixLeftMarginAndNewlines( editor, adjRec.infp, leftMargin,
- rightMargin, (int)start, (int)end );
- fflush(adjRec.infp);
- rewind(adjRec.infp);
- FormatText(&adjRec);
- fclose(adjRec.infp);
- unlink(tempName1);
- fclose(adjRec.outfp);
- returnVal =
- DtEditorReplaceFromFile( (Widget)editor, start, end, tempName2 );
- unlink(tempName2);
- }
- else {
- /*
- * Could not open second temporary file, so clean up first one
- */
- fclose(adjRec.infp);
- unlink(tempName1);
- returnVal = DtEDITOR_NO_TMP_FILE;
- }
- } /* end creating temporary files */
- else
- returnVal = DtEDITOR_NO_TMP_FILE;
- /*
- * Clean up
- */
- _DtTurnOffHourGlass(M_topLevelShell(editor));
- if (M_format_dialog(editor) != (Widget)NULL)
- _DtTurnOffHourGlass(M_format_dialog(editor));
- } /* end check for valid margins */
- else
- returnVal = DtEDITOR_ILLEGAL_SIZE;
- return (returnVal);
- }
- /* ARGSUSED */
- static void
- AdjustCloseCB(
- Widget w,
- caddr_t client_data,
- caddr_t call_data )
- {
- DtEditorWidget editor = (DtEditorWidget )client_data;
- XtUnmanageChild (M_format_dialog(editor));
- }
- /* ARGSUSED */
- static int
- ComputeRightMargin(
- DtEditorWidget editor)
- {
- Dimension text_width, highlight_thickness, shadow_thickness,
- margin_width;
- int rightMargin;
- Arg al[5]; /* arg list */
- register int ac; /* arg count */
- ac=0;
- XtSetArg(al[ac], XmNwidth, &text_width); ac++;
- XtSetArg(al[ac], XmNhighlightThickness, &highlight_thickness); ac++;
- XtSetArg(al[ac], XmNshadowThickness, &shadow_thickness); ac++;
- XtSetArg(al[ac], XmNmarginWidth, &margin_width); ac++;
- XtGetValues(M_text(editor), al, ac);
- if (M_fontWidth(editor) != 0)
- rightMargin = ( (int)text_width -
- (2 * ((int)highlight_thickness +
- (int)shadow_thickness + (int)margin_width))
- ) / M_fontWidth(editor);
- else
- rightMargin = (int)text_width -
- (2 * ((int)highlight_thickness +
- (int)shadow_thickness + (int)margin_width));
- return( rightMargin );
- } /* end ComputeRightMargin */
- /* ARGSUSED */
- static void
- UpdateAdjust(
- Widget widget,
- XtPointer *client_data,
- XConfigureEvent *event )
- {
- Dimension width;
- DtEditorWidget editor = (DtEditorWidget) client_data;
- char orgnum[20]; /* original margin size string */
- Arg al[2];
- XtSetArg(al[0], XmNwidth, &width);
- XtGetValues(M_text(editor), al, 1);
- if (width == M_textWidth(editor))
- return;
- M_textWidth(editor) = width;
- sprintf( orgnum, "%d", ComputeRightMargin(editor) );
- XmTextFieldSetString(M_format_rightMarginField(editor), orgnum);
- }
- /************************************************************************
- *
- * SetFormatDialogTitle - Change the title for the Format Settings dialog
- *
- ************************************************************************/
- static void
- SetFormatDialogTitle(
- DtEditorWidget editor)
- {
- Arg al[2];
- /*
- * If the Format Settings dialog has been created, change its title
- */
- if( M_format_dialog(editor) != (Widget)NULL )
- {
- /*
- * Prepend the DialogTitle resource, if it has been set
- */
- if( E_dialogTitle(editor) != (XmString)NULL ) {
- XmString titleStr;
- /*
- * Add the "functional title" to the DialogTitle
- */
- titleStr = XmStringConcat( E_dialogTitle(editor),
- E_format_dialogTitle(editor) );
- XtSetArg( al[0], XmNdialogTitle, titleStr );
- XtSetValues(M_format_dialog(editor), al, 1);
- XmStringFree( titleStr );
- }
- else {
- XtSetArg( al[0], XmNdialogTitle, E_format_dialogTitle(editor) );
- XtSetValues(M_format_dialog(editor), al, 1);
- }
- }
- } /* end SetFormatDialogTitle */
- /************************************************************************
- *
- * ResetFormatDialog - Reset margins & alignment of the Format Settings
- * dialog
- *
- ************************************************************************/
- static void
- ResetFormatDialog(
- DtEditorWidget editor)
- {
- char orgnum[20]; /* original margin size string */
- /*
- * Reset the margins to default values
- */
- /* Right margin default value */
- sprintf( orgnum, "%d", ComputeRightMargin(editor) );
- XmTextFieldSetString(M_format_rightMarginField(editor), orgnum);
- /* Left margin default value */
- sprintf(orgnum, "%d", 0);
- XmTextFieldSetString(M_format_leftMarginField(editor), orgnum);
- /*
- * Reset the alignment style to default value
- */
- XmToggleButtonGadgetSetState(M_format_leftJust(editor), True, True);
- } /* end ResetFormatDialog */
- /************************************************************************
- *
- * CreateFormatDialog - Create & initialize the Format Settings dialog
- *
- ************************************************************************/
- static void
- CreateFormatDialog(
- DtEditorWidget editor)
- {
- Arg al[15]; /* arg list */
- register int ac; /* arg count */
- Pixel textBackground, textForeground;
- XmString tempString = (XmString)NULL;
- /*
- * Match the background & foreground colors of the edit window
- * Don't use DtNtextBackground/Foreground directly because they
- * will be DtUNSPECIFIED.
- */
- ac = 0;
- XtSetArg(al[ac], XmNforeground, &textForeground); ac++;
- XtSetArg(al[ac], XmNbackground, &textBackground); ac++;
- XtGetValues(M_text(editor), al, ac);
- ac = 0;
- /*
- * First, create the dialog's title, prepending the
- * DtNdialogTitle resource, if it is set
- */
- if( E_dialogTitle(editor) != (XmString)NULL ) {
- /*
- * Add the "functional title" to the DialogTitle
- */
- tempString = XmStringConcat( E_dialogTitle(editor),
- E_format_dialogTitle(editor) );
- XtSetArg (al[ac], XmNdialogTitle, tempString ); ac++;
-
- }
- else {
- XtSetArg(al[ac], XmNdialogTitle, E_format_dialogTitle(editor)); ac++;
- }
- XtSetArg (al[ac], XmNautoUnmanage, False); ac++;
- XtSetArg (al[ac], XmNmarginWidth, 5); ac++;
- XtSetArg (al[ac], XmNmarginHeight, 5); ac++;
- XtSetArg (al[ac], XmNshadowThickness, 1); ac++;
- XtSetArg (al[ac], XmNshadowType, XmSHADOW_OUT); ac++;
- XtSetArg (al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
- M_format_dialog(editor) = XmCreateFormDialog(
- M_topLevelShell(editor), "ad_dial", al, ac);
- if (tempString != (XmString)NULL)
- XmStringFree( tempString );
- XtAddCallback(M_format_dialog(editor), XmNhelpCallback,
- (XtCallbackProc)HelpFormatDialogCB, (XtPointer)editor);
- /*
- * When creating the fields & buttons use the appropriate label
- * resource (e.g. DtNcenterToggleLabel), if it has been set, then
- * clear the resource to save space. The field or button widget
- * will contain the actual value & it can be gotten from there,
- * if it is needed.
- *
- * If the appropriate resource has not been set, use its default
- * value from the message catalog.
- */
- /*
- * create the left margin label and text field
- */
- ac = 0;
- if (E_format_leftMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_leftMarginFieldLabel(editor));
- E_format_leftMarginFieldLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(LEFT_MARGIN);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNleftPosition, 2); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNtopOffset, 10); ac++;
- XtSetArg (al[ac], XmNfontList, E_labelFontList(editor)); ac++;
- M_format_leftLabel(editor) = (Widget) XmCreateLabelGadget (
- M_format_dialog(editor), "left_label", al, ac);
- XtManageChild (M_format_leftLabel(editor));
- XmStringFree (tempString);
- XtAddCallback(M_format_leftLabel(editor), XmNhelpCallback,
- (XtCallbackProc)HelpFormatLeftMarginCB, (XtPointer)editor);
- ac = 0;
- XtSetArg (al[ac], XmNbackground, textBackground); ac++;
- XtSetArg (al[ac], XmNforeground, textForeground); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNleftWidget, M_format_leftLabel(editor)); ac++;
- XtSetArg (al[ac], XmNleftOffset, 3); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNrightPosition, 45); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNtraversalOn, True); ac++;
- XtSetArg (al[ac], XmNcolumns, 3); ac++;
- XtSetArg (al[ac], XmNfontList, E_textFontList(editor)); ac++;
- M_format_leftMarginField(editor) = (Widget) XmCreateTextField (
- M_format_dialog(editor), "left_text", al, ac);
- XtManageChild (M_format_leftMarginField(editor));
- XtAddCallback(M_format_leftMarginField(editor), XmNhelpCallback,
- (XtCallbackProc)HelpFormatLeftMarginCB, (XtPointer)editor);
- /*
- * create the right margin label and text field
- */
- ac = 0;
- if (E_format_rightMarginFieldLabel(editor) != (XmString) DtUNSPECIFIED)
- {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_rightMarginFieldLabel(editor));
- E_format_rightMarginFieldLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else
- {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(RIGHT_MARGIN);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNleftPosition, 55); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNtopOffset, 10); ac++;
- XtSetArg (al[ac], XmNfontList, E_labelFontList(editor)); ac++;
- M_format_rightLabel(editor)= (Widget) XmCreateLabelGadget (
- M_format_dialog(editor), "right_label", al, ac);
- XtManageChild (M_format_rightLabel(editor));
- XmStringFree (tempString);
- XtAddCallback(M_format_rightLabel(editor), XmNhelpCallback,
- (XtCallbackProc)HelpFormatRightMarginCB,
- (XtPointer)editor);
- ac = 0;
- XtSetArg (al[ac], XmNbackground, textBackground); ac++;
- XtSetArg (al[ac], XmNforeground, textForeground); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNrightPosition, 98); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNleftWidget, M_format_rightLabel(editor)); ac++;
- XtSetArg (al[ac], XmNleftOffset, 3); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNtraversalOn, True); ac++;
- XtSetArg (al[ac], XmNcolumns, 3); ac++;
- XtSetArg (al[ac], XmNfontList, E_textFontList(editor)); ac++;
- M_format_rightMarginField(editor) = (Widget) XmCreateTextField (
- M_format_dialog(editor),
- "right_text", al, ac);
- XtManageChild (M_format_rightMarginField(editor));
- XtAddCallback(M_format_rightMarginField(editor), XmNhelpCallback,
- (XtCallbackProc)HelpFormatRightMarginCB,
- (XtPointer)editor);
- /*
- * create the radio box for justification choices
- */
- ac = 0;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNleftOffset, 5); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNtopWidget, M_format_leftMarginField(editor)); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNrightOffset, 5); ac++;
- XtSetArg (al[ac], XmNtraversalOn, True); ac++;
- M_format_radioBox(editor) = (Widget) XmCreateRadioBox(
- M_format_dialog(editor), "radioBox", al, ac);
- XtAddCallback(M_format_radioBox(editor), XmNhelpCallback,
- (XtCallbackProc)HelpFormatJustifyButtonsCB,
- (XtPointer)editor);
- XtManageChild(M_format_radioBox(editor));
- /* Create Left Align toggle */
- ac = 0;
- if (E_format_leftAlignToggleLabel(editor) != (XmString) DtUNSPECIFIED) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_leftAlignToggleLabel(editor));
- E_format_leftAlignToggleLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(LEFT_ALIGN);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_leftJust(editor) = (Widget) XmCreateToggleButtonGadget(
- M_format_radioBox(editor), "left_just", al, ac);
- XmStringFree (tempString);
- XtManageChild(M_format_leftJust(editor));
- /* Create Right Align toggle */
- ac = 0;
- if(E_format_rightAlignToggleLabel(editor) != (XmString)DtUNSPECIFIED) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_rightAlignToggleLabel(editor));
- E_format_rightAlignToggleLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(RIGHT_ALIGN);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_rightJust(editor) = (Widget) XmCreateToggleButtonGadget(
- M_format_radioBox(editor), "right_just", al, ac);
- XmStringFree (tempString);
- XtManageChild(M_format_rightJust(editor));
- /* Create Justify toggle */
- ac = 0;
- if (E_format_justifyToggleLabel(editor) != (XmString) DtUNSPECIFIED) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_justifyToggleLabel(editor));
- E_format_justifyToggleLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized( JUSTIFY );
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_bothJust(editor) = (Widget) XmCreateToggleButtonGadget(
- M_format_radioBox(editor), "both_just", al, ac);
- XmStringFree (tempString);
- XtManageChild(M_format_bothJust(editor));
- /* Create Center align toggle */
- ac = 0;
- if (E_format_centerToggleLabel(editor) != (XmString) DtUNSPECIFIED) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_centerToggleLabel(editor));
- E_format_centerToggleLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(CENTER);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_center(editor) = (Widget) XmCreateToggleButtonGadget(
- M_format_radioBox(editor), "center", al, ac);
- XmStringFree(tempString);
- XtManageChild(M_format_center(editor));
- /* Create a separator between the radio box and buttons */
- ac = 0;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNtopWidget, M_format_radioBox(editor)); ac++;
- XtSetArg (al[ac], XmNtopOffset, 15); ac++;
- M_format_separator(editor) = (Widget) XmCreateSeparatorGadget (
- M_format_dialog(editor), "separator", al, ac);
- XtManageChild (M_format_separator(editor));
- /* Create Format Paragraph button */
- ac = 0;
- if ( E_format_formatParagraphButtonLabel(editor) !=
- (XmString) DtUNSPECIFIED ) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_formatParagraphButtonLabel(editor));
- E_format_formatParagraphButtonLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(PARAGRAPH);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNleftPosition, 2); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNrightPosition, 25); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
- XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
- XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_paragraph(editor) = (Widget) XmCreatePushButtonGadget (
- M_format_dialog(editor), "para", al, ac);
- XtManageChild (M_format_paragraph(editor));
- XmStringFree (tempString);
- XtAddCallback (M_format_paragraph(editor), XmNactivateCallback,
- (XtCallbackProc) AdjustParaCB, (XtPointer) editor);
- /* Create Format All button */
- ac = 0;
- if (E_format_formatAllButtonLabel(editor) != (XmString)DtUNSPECIFIED) {
- /*
- * Use the resource value & clear it (to save space).
- */
- tempString = XmStringCopy(E_format_formatAllButtonLabel(editor));
- E_format_formatAllButtonLabel(editor) = (XmString) DtUNSPECIFIED;
- }
- else {
- /*
- * The resource has not been set so use its default value
- */
- tempString = XmStringCreateLocalized(ALL);
- }
- XtSetArg(al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNleftPosition, 27); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNrightPosition, 49); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
- XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
- XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_all(editor) = (Widget) XmCreatePushButtonGadget(
- M_format_dialog(editor), "all", al, ac);
- XtManageChild (M_format_all(editor));
- XmStringFree (tempString);
- XtAddCallback (M_format_all(editor), XmNactivateCallback,
- (XtCallbackProc) AdjustAllCB, (XtPointer) editor);
- /* Create Close button */
- tempString = XmStringCreateLocalized(CLOSE_BUTTON);
- ac = 0;
- XtSetArg (al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNleftPosition, 51); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNrightPosition, 73); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
- XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
- XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_close(editor) = (Widget) XmCreatePushButtonGadget (
- M_format_dialog(editor), "close", al, ac);
- XtManageChild (M_format_close(editor));
- XmStringFree (tempString);
- XtAddCallback (M_format_close(editor), XmNactivateCallback,
- (XtCallbackProc) AdjustCloseCB, (XtPointer) editor);
- tempString = XmStringCreateLocalized(HELP_BUTTON);
- ac = 0;
- XtSetArg (al[ac], XmNlabelString, tempString); ac++;
- XtSetArg (al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNleftPosition, 75); ac++;
- XtSetArg (al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
- XtSetArg (al[ac], XmNrightPosition, 98); ac++;
- XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
- XtSetArg (al[ac], XmNtopWidget, M_format_separator(editor)); ac++;
- XtSetArg (al[ac], XmNtopOffset, 5); ac++;
- XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
- XtSetArg (al[ac], XmNbottomOffset, 5); ac++;
- XtSetArg (al[ac], XmNmarginWidth, 4); ac++;
- XtSetArg (al[ac], XmNmarginHeight, 4); ac++;
- XtSetArg (al[ac], XmNfontList, E_buttonFontList(editor)); ac++;
- M_format_help(editor) = (Widget) XmCreatePushButtonGadget(
- M_format_dialog(editor), "help", al, ac);
- XtManageChild (M_format_help(editor));
- XmStringFree (tempString);
- XtAddCallback( M_format_help(editor), XmNactivateCallback,
- (XtCallbackProc) HelpFormatDialogCB, (XtPointer) editor);
- /*
- * set the default/activation button.
- */
- XtSetArg(al[0], XmNdefaultButton, M_format_close(editor));
- XtSetValues(M_format_dialog(editor), al, 1);
- XtRealizeWidget (M_format_dialog(editor));
- /*
- * Initialize the margins & alignment toggles
- */
- ResetFormatDialog(editor);
- XtSetArg(al[0], XmNwidth, &(M_textWidth(editor)));
- XtGetValues(M_text(editor), al, 1);
- XtAddEventHandler(M_text(editor), StructureNotifyMask, False,
- (XtEventHandler) UpdateAdjust, (XtPointer) editor);
- } /* end CreateFormatDialog */
- /************************************************************************
- *
- * GetAdjustSettings - Read the alignment settings from the Format
- * Settings dialog.
- *
- ************************************************************************/
- static void
- GetAdjustSettings(
- DtEditorWidget editor,
- DtEditorFormatSettings *formatSettings)
- {
- if( M_format_dialog(editor)!= (Widget)NULL ) {
- /*
- * Read the current alignment settings from the Format Settings
- * dialog.
- */
- char *num;
- /*
- * Get current type of alignment
- */
- if (XmToggleButtonGadgetGetState(M_format_leftJust(editor)))
- formatSettings->alignment = DtEDITOR_ALIGN_LEFT;
- else if (XmToggleButtonGadgetGetState(M_format_rightJust(editor)))
- formatSettings->alignment = DtEDITOR_ALIGN_RIGHT;
- else if (XmToggleButtonGadgetGetState(M_format_bothJust(editor)))
- formatSettings->alignment = DtEDITOR_ALIGN_JUSTIFY;
- else
- formatSettings->alignment = DtEDITOR_ALIGN_CENTER;
- /*
- * Get current margin settings
- */
- num = (char *) XmTextFieldGetString(
- (Widget)M_format_rightMarginField(editor) );
- formatSettings->rightMargin = atoi(num);
- XtFree(num);
- num = (char *) XmTextFieldGetString(
- (Widget)M_format_leftMarginField(editor) );
- formatSettings->leftMargin = atoi(num);
- XtFree(num);
- }
- else {
- /*
- * The Format Settings dialog box has not been created so use the
- * default values.
- */
- formatSettings->leftMargin = 0;
- formatSettings->rightMargin = ComputeRightMargin(editor);
- formatSettings->alignment = DtEDITOR_ALIGN_LEFT;
- }
- }
- /****************************************************************
- *
- * Public Procs
- *
- ****************************************************************/
- /*********************************************************
- *
- * DtCreateEditor
- * Create an instance of an editor and return the widget id.
- */
- Widget
- DtCreateEditor(
- Widget parent,
- char *name,
- ArgList arglist,
- Cardinal argcount )
- {
- return( XtCreateWidget(name,dtEditorWidgetClass,parent,arglist,argcount) );
- }
- Boolean
- DtEditorCheckForUnsavedChanges(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- Boolean result;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- result = M_unreadChanges( editor );
- _DtAppUnlock(app);
- return result;
- } /* end DtEditorCheckForUnsavedChanges */
- Boolean
- DtEditorDeleteSelection(
- Widget widget)
- {
- XmTextPosition first, last;
- DtEditorWidget editor = (DtEditorWidget) widget;
- Boolean result;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Check for a non-null selection
- */
- if ( XmTextGetSelectionPosition(M_text(editor), &first, &last) &&
- first != last )
- {
- XmTextRemove(M_text(editor));
- result = True;
- }
- else
- result = False;
- _DtAppUnlock(app);
- return result;
- } /* end DtEditorDeleteSelection */
- /*
- * DtEditorClearSelection replaces the currently selected text with
- * spaces. It requires an event because the underlying text widget
- * routines require one to look at the time stamp within.
- */
- Boolean
- DtEditorClearSelection(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- char *params=(char *)NULL;
- Cardinal num_params = 0;
- XEvent event;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Create an event with a correct timestamp
- */
- event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
- /*
- * Call routine to clear primary selection
- */
- ClearSelection( widget, &event, ¶ms, &num_params );
- _DtAppUnlock(app);
- return(True);
- } /* end DtEditorClearSelection */
- /*
- *
- * DtEditorDeselect - Unselects any selected text of an Editor widget
- *
- */
- Boolean
- DtEditorDeselect(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- char *params=(char *)NULL;
- Cardinal num_params = 0;
- XEvent event;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Create an event with a correct timestamp
- */
- event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
- DeselectAll( widget, &event, ¶ms, &num_params );
- _DtAppUnlock(app);
- return(True);
- } /* end DtEditorDeselect */
- /*
- *
- * DtEditorDisableRedisplay - Temporarily prevent visual update of a
- * Editor widget
- *
- */
- void
- DtEditorDisableRedisplay(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- XmTextDisableRedisplay( M_text(editor) );
- _DtAppUnlock(app);
- } /* end DtEditorDisableRedisplay */
- /*
- *
- * DtEditorEnableRedisplay - Force visual update of an Editor widget
- *
- */
- void
- DtEditorEnableRedisplay(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- XmTextEnableRedisplay( M_text(editor) );
- _DtAppUnlock(app);
- } /* end DtEditorEnableRedisplay */
- /*********
- *
- * DtEditorFormat
- * Given left & right margin values & an alignment style,
- * formats either the current paragraph or the entire document,
- * as specified. If margin values & alignment style are not
- * provided, DtEditorFormat will use the current values from
- * the Format Settings dialog.
- *
- * Returns:
- * DtEDITOR_NO_ERRORS if the text was formatted successfully.
- * DtEDITOR_NO_TMP_FILE if the 2 temporary files cannot be
- * created.
- * DtEDITOR_ILLEGAL_SIZE if the left & right margins don't make
- * sense.
- * DtEDITOR_INVALID_RANGE if specified amount to format is
- * unrecognized
- * DtEDITOR_INVALID_TYPE if specified alignment is
- * unrecognized
- *
- */
- DtEditorErrorCode
- DtEditorFormat(
- Widget widget,
- DtEditorFormatSettings *formatSettings,
- unsigned int amountToFormat )
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- DtEditorErrorCode error;
- int leftMargin, rightMargin, alignment;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Check to see if we should use the format settings from the
- * Format Settings dialog.
- */
- if( formatSettings == (DtEditorFormatSettings *) NULL )
- {
- DtEditorFormatSettings tmpFormatSettings;
- /*
- * Get the format settings from the Format Settings dialog
- */
- GetAdjustSettings(editor, &tmpFormatSettings);
- /*
- * Set up the correct format settings
- */
- leftMargin = tmpFormatSettings.leftMargin;
- rightMargin = tmpFormatSettings.rightMargin;
- alignment = tmpFormatSettings.alignment;
- }
- else {
- leftMargin = formatSettings->leftMargin;
- rightMargin = formatSettings->rightMargin;
- alignment = formatSettings->alignment;
- }
- /*
- * Now, do the formatting
- */
- switch (amountToFormat)
- {
- case DtEDITOR_FORMAT_ALL:
- {
- error = DoAdjust( editor, leftMargin, rightMargin, alignment,
- 0, XmTextGetLastPosition(M_text(editor)) );
- break;
- }
- case DtEDITOR_FORMAT_PARAGRAPH:
- {
- XmTextPosition start, end;
- char *params=(char *)NULL;
- Cardinal num_params = 0;
- /*
- * Create an event with a correct timestamp
- */
- XEvent event;
- event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
- /*
- * Get the beginning & ending positions of the current paragraph
- */
- ForwardPara( widget, &event, ¶ms, &num_params );
- end = XmTextGetInsertionPosition(M_text(editor));
- if( end != XmTextGetLastPosition(M_text(editor)) ) {
- /*
- * If we're not at the end, then we need to back up to the
- * start of this line, otherwise we'll disturb the first line
- * of the following paragraph. If we are at the end, then "end"
- * must point to the end of the line, or we'll leave the last
- * line along with the formatted text.
- */
- BeginningOfLine( widget, &event, ¶ms, &num_params );
- end = XmTextGetInsertionPosition(M_text(editor));
- }
- BackwardPara( widget, &event, ¶ms, &num_params );
- BeginningOfLine( widget, &event, ¶ms, &num_params );
- start = XmTextGetInsertionPosition(M_text(editor));
- /*
- * Pass in beginning & ending positions to adjust the current
- * paragraph
- */
- error = DoAdjust( editor, leftMargin, rightMargin, alignment,
- start, end );
- break;
- }
- default: {
- error = DtEDITOR_INVALID_RANGE;
- }
- } /* end switch */
- _DtAppUnlock(app);
- return( error );
- } /* DtEditorFormat */
- /*
- *
- * DtEditorGetMessageTextFieldID - Returns the widget ID of the Text
- * Field used to display application status messages.
- *
- */
- Widget
- DtEditorGetMessageTextFieldID(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- Widget result;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Create the status line if is does not exist
- */
- if( M_status_statusArea(editor) == (Widget) NULL )
- M_status_statusArea(editor) = CreateStatusLine( editor );
- result = M_status_messageText(editor);
- _DtAppUnlock(app);
- return result;
- } /* end DtEditorGetMessageTextFieldID */
- /*
- * DtEditorGoToLine moves the insert cursor to the beginning of the
- * line specified by lineNumber. It figures out the text character
- * position corresponding to the specified line and sets the text
- * widget's insertionPosition to that location. If this new
- * insertionPosition is not currently on-screen, then the
- * text widget's contents are scrolled to display the new position.
- *
- * The cursor can be moved to last line by specifying DtEDITOR_LAST_LINE
- * as the line number.
- * If lineNumber is less than one, the insert cursor will be placed
- * at the beginning of the first line. If it is greater than the total
- * number of lines, the cursor will be placed at the last line of text.
- */
-
- /* ARGSUSED */
- void DtEditorGoToLine(
- Widget widget,
- int lineNumber)
- {
- DtEditorWidget editor = (DtEditorWidget)widget;
- XmTextWidget tw;
- XmTextLineTable lineTab;
- XmTextPosition newPos;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- tw = (XmTextWidget)M_text(editor);
- lineTab = tw->text.line_table;
- /*
- * Validate the specified line number, check it is in range.
- * If we adjust the line number, then update the current line display
- * in the status line so it reflects where we are really going. This
- * is only a problem if lineNumber is less/greater than the first/last
- * line becausee we won't be moving the cursor so the status line will
- * not be updated.
- */
- if (lineNumber > tw->text.total_lines || lineNumber == DtEDITOR_LAST_LINE)
- {
- lineNumber = tw->text.total_lines;
- _DtEditorUpdateLineDisplay( editor, lineNumber, FORCE );
- }
- else if(lineNumber < 1)
- {
- lineNumber = 1;
- _DtEditorUpdateLineDisplay( editor, lineNumber, FORCE );
- }
- /*
- * Move the insertion cursor
- */
- newPos = lineTab[lineNumber - 1].start_pos;
- XmTextSetInsertionPosition(M_text(editor), newPos);
- /*
- * Scroll the widget, if necessary
- */
- if (newPos < tw->text.top_character || newPos >= tw->text.bottom_position)
- {
- Arg al[5];
- int ac;
- Dimension height;
- short rows;
- Position x, y;
- ac = 0;
- XtSetArg(al[ac], XmNheight, &height); ac++;
- XtSetArg(al[ac], XmNrows, &rows); ac++;
- XtGetValues(M_text(editor), al, ac);
- if(XmTextPosToXY(M_text(editor), newPos, &x, &y) == True)
- {
- int offset = (y - height/2) * rows;
- XmTextScroll(M_text(editor), offset/(int) height);
- }
- }
- _DtAppUnlock(app);
- } /* end DtEditorGoToLine */
- /*
- * DtEditorGetEditorSizeHints - Set the resize increment, minimum window
- * size, and base dimension properties in the supplied XSizeHints
- * struct for the editor as a whole.
- *
- * NOTE: This routine returns data in the struct pointed to by pHints.
- *
- */
- void
- DtEditorGetSizeHints(
- Widget widget,
- XSizeHints *pHints) /* Return */
- {
- Arg al[10]; /* arg list */
- register int ac; /* arg count */
- Dimension FormWidth, FormHeight,
- Twidth, Theight, statusHeight,
- highlightThickness, shadowThickness,
- marginWidth, marginHeight,
- textRegionWidth, textRegionHeight;
- DtEditorWidget editor = (DtEditorWidget) widget;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Window manager should resize in increments of a character or line.
- */
- pHints->width_inc = M_fontWidth(editor);
- pHints->height_inc = M_fontHeight(editor);
- /*
- * Size of the Editor (Form)
- */
- FormWidth = editor->core.width + (2 * editor->core.border_width);
- FormHeight = editor->core.height + (2 * editor->core.border_width);
- /*
- * Size of the Edit window (text widget)
- */
- ac=0;
- XtSetArg(al[ac], XmNwidth, &Twidth); ac++;
- XtSetArg(al[ac], XmNheight, &Theight); ac++;
- XtSetArg(al[ac], XmNhighlightThickness, &highlightThickness); ac++;
- XtSetArg(al[ac], XmNshadowThickness, &shadowThickness); ac++;
- XtSetArg(al[ac], XmNmarginWidth, &marginWidth); ac++;
- XtSetArg(al[ac], XmNmarginHeight, &marginHeight); ac++;
- XtGetValues(M_text(editor), al, ac);
- /*
- * Calculate the width & height of the area within the text widget
- * which can actually display characters.
- */
- textRegionWidth = (int)Twidth -
- (2 * ((int)highlightThickness +
- (int)shadowThickness + (int)marginWidth));
- textRegionHeight = (int)Theight -
- (2 * ((int)highlightThickness +
- (int)shadowThickness + (int)marginHeight));
- /*
- * Set the base width/height to the size of the area which will not
- * display characters.
- *
- * The base width/height is used by the window manager in concert
- * with the height & width increments to display the current size
- * (rows & columns) of edit window (text widget) while resizing the
- * editor.
- */
- pHints->base_width = FormWidth - textRegionWidth;
- pHints->base_height = FormHeight - textRegionHeight;
-
- /*
- * Get the height of the status line, if it is turned on.
- * Remember, the border width is not included in the height of the
- * status line so add it in to account for the border between the
- * edit window (text widget) and the status line.
- */
- /* XXX Actually, the statusHeight should already be included in the
- * FormHeight, so it should not be necessary to add it in again.
- * However, the numbers don't come out right otherwise. Hmmm? */
- if( M_status_showStatusLine(editor) == True )
- {
- XtSetArg( al[0], XmNheight, &statusHeight );
- XtGetValues( M_status_statusArea(editor), al, 1 );
- statusHeight = statusHeight + editor->core.border_width;
- }
- else
- statusHeight = 0;
- /*
- * What is being returned here is the minimum width & height of the
- * editor. Leave room for the scrollbars, shadows, etc., plus one
- * character.
- */
- pHints->min_width = pHints->base_width + pHints->width_inc;
- pHints->min_height = pHints->base_width + pHints->height_inc +
- statusHeight;
- pHints->flags = PMinSize | PResizeInc | PBaseSize;
- _DtAppUnlock(app);
- } /* end DtEditorGetSizeHints */
- void
- DtEditorInvokeFormatDialog(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Create the dialog if it is the first time
- */
- if (M_format_dialog(editor) == (Widget)NULL)
- CreateFormatDialog( editor );
- /*
- * Post the dialog
- */
- XtUnmanageChild (M_format_dialog(editor));
- XtManageChild (M_format_dialog(editor));
- XmProcessTraversal(M_format_paragraph(editor), XmTRAVERSE_CURRENT);
- _DtAppUnlock(app);
- } /* DtEditorInvokeFormatDialog */
- void
- DtEditorReset(
- Widget widget)
- {
- DtEditorContentRec cr;
- DtEditorWidget editor = (DtEditorWidget) widget;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Reset the edit window (includes the Undo context)
- */
- cr.type = DtEDITOR_TEXT;
- cr.value.string = "";
- DtEditorSetContents( widget, &cr );
- /*
- * Reset the status line
- * Note, the current & total line displays are reset by DtEditorSetContents()
- */
- if( M_status_statusArea(editor) != (Widget) NULL ) {
- XmTextFieldSetString( M_status_messageText(editor), "" );
- }
- /*
- * Reset the Find/Change & Spell dialogs
- */
- if ( M_search_string(editor) )
- XtFree(M_search_string(editor));
- M_search_string(editor) = (char *)NULL;
- if ( M_replace_string(editor) )
- XtFree(M_replace_string(editor));
- M_replace_string(editor) = (char *)NULL;
- if (M_misspelled_string(editor))
- XtFree(M_misspelled_string(editor));
- M_misspelled_string(editor) = (char *)NULL;
- /*
- * Reset the Format Settings dialog
- */
- if (M_format_dialog(editor) != (Widget)NULL)
- ResetFormatDialog(editor);
-
- _DtAppUnlock(app);
- } /* end DtEditorReset */
- /*
- *
- * DtEditorSelectAll - Selects the contents of an Editor widget
- *
- */
- Boolean
- DtEditorSelectAll(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- char *params=(char *)NULL;
- Cardinal num_params = 0;
- XEvent event;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- /*
- * Create an event with a correct timestamp
- */
- event.xkey.time = XtLastTimestampProcessed( M_display(editor) );
- SelectAll( widget, &event, ¶ms, &num_params );
- _DtAppUnlock(app);
- return(True);
- } /* end DtEditorSelectAll */
- void
- DtEditorTraverseToEditor(
- Widget widget)
- {
- DtEditorWidget editor = (DtEditorWidget) widget;
- _DtWidgetToAppContext(widget);
- _DtAppLock(app);
- XmProcessTraversal(M_text(editor), XmTRAVERSE_CURRENT);
- _DtAppUnlock(app);
- } /* end DtEditorTraverseToEditor */
|