1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284 |
- /*
- * 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 libraries 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
- */
- #ifndef _XOPEN_SOURCE
- #define _XOPEN_SOURCE 600
- #endif
- #include <ctype.h>
- #include <stdlib.h>
- #if defined(sun)
- # if (_XOPEN_VERSION==3)
- # include <wctype.h>
- # else
- # include <wchar.h>
- # endif
- # include <libintl.h>
- #elif defined(__linux__) || defined(CSRG_BASED)
- # include <wctype.h>
- # include <wchar.h>
- #endif /* linux || CSRG_BASED */
- #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(_AIX) /* _AIX */
- /* IBM defines wctype to get_wctype above - don't use const. */
- static char *blankString = "space";
- #else /* _AIX */
- static const char *blankString = "space";
- #endif /* _AIX */
- static wctype_t _DtEditor_blankClass;
- #else
- # define wctype_t int
- # define iswblank(a) iswspace(a)
- # define iswctype(a,b) _iswctype(a,b)
- # define wcwidth(a) sun_wcwidth(a)
- #endif /* not sun */
- #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))
- _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)
- {
- 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 = NULL;
- 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[15]; /* arg list */
- 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)
- {
- XModifierKeymap *pMap;
- 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];
- 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];
- 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, FILE *filep);
- static void Center (FormatData *data,
- wint_t *in_line, wint_t *inlinelim);
- static void Fill (FormatData *data, wint_t *in_line, 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, 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))
- 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))
- 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))
- 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);
- XmTextLineTable lineTable;
- 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 */
- 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,
- FILE *filep) /* open file to read */
- {
- wint_t in_line [LINESIZE]; /* after reading in */
- wint_t *incp = in_line; /* place in in_line */
- wint_t *incplim = in_line + LINESIZE; /* limit of in_line */
- 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 */
- wint_t *inlinelim) /* end of line + 1 */
- {
- wint_t *incp; /* pointer in in_line */
- wint_t outline [LINESIZE + MAXTABSIZE]; /* after generic work */
- wint_t *outcp = outline; /* place in outline */
- wint_t *outlinelim = outline + LINESIZE; /* limit of outline*/
- int haveword = False; /* hit word in in_line? */
- wint_t ch; /* current working char */
- int needsp; /* spaces need for tab */
- 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 accommodate 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 accommodate 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 */
- wint_t *inlinelim) /* end of line + 1 */
- {
- wint_t *incp; /* place in in_line */
- wint_t ch; /* current working char */
- int haveword = False; /* hit word in in_line? */
- 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 */
- 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 */
- int wordlen; /* length of one word */
- int indent; /* local value */
- 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 */
- {
- WORD *wordat = data->wordfirst; /* local value */
- int outcol = data->indent1 + 1; /* next column */
- int wordcol; /* desired column */
- 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 */
- {
- WORD *wordat = data->wordfirst; /* local value */
- wint_t *wordcp; /* place in word */
- wint_t *wordcplim; /* limit of word */
- 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,
- int blanks, /* blanks to insert */
- WORD *wordpast) /* past last to print */
- {
- WORD *wordat; /* local value */
- int sortat; /* place in sort[] */
- int wordlen; /* size of this word */
- 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 */
- 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 */
- 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 */
- 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 */
|