PrintSetupB.c 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: PrintSetupB.c /main/27 1998/08/06 17:28:56 mgreess $ */
  24. /*
  25. * DtPrint/PrintSetupB.c
  26. */
  27. /* (c) Copyright 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
  28. * ALL RIGHTS RESERVED
  29. * (c) Copyright 1989, 1996 DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
  30. * (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1995, 1996,
  31. * HEWLETT-PACKARD COMPANY
  32. * (c) Copyright 1996 International Business Machines Corp.
  33. * (c) Copyright 1996 Sun Microsystems, Inc.
  34. * (c) Copyright 1996 Novell, Inc.
  35. * (c) Copyright 1996 FUJITSU LIMITED.
  36. * (c) Copyright 1996 Hitachi.
  37. */
  38. /*
  39. * ------------------------------------------------------------------------
  40. * Include Files
  41. *
  42. */
  43. #include <Dt/DtNlUtils.h>
  44. #ifdef MAXINT
  45. #undef MAXINT
  46. #endif
  47. #include <ctype.h>
  48. #include <stdlib.h>
  49. #if defined(CSRG_BASED)
  50. #define MAXINT INT_MAX
  51. #else
  52. #include <values.h>
  53. #endif
  54. #include <stdio.h>
  55. #include <stdint.h>
  56. #include <Xm/XmAll.h>
  57. #include <Xm/ActivatableT.h>
  58. #include <Xm/RowColumnP.h>
  59. #include <Xm/TraitP.h>
  60. #include <Xm/TakesDefT.h>
  61. #include <Xm/XmPrivate.h>
  62. #include <Dt/PrintSetupBP.h>
  63. #include <Dt/PsubDefProcI.h>
  64. #include <Dt/PsubUtilI.h>
  65. #include <Dt/PrintI.h>
  66. /*
  67. * ------------------------------------------------------------------------
  68. * Constant Definitions
  69. *
  70. */
  71. #define IsButton(w) \
  72. (((XtPointer) XmeTraitGet((XtPointer) XtClass((w)), XmQTactivatable) != NULL))
  73. #define IsAutoButton(psub, w) ( \
  74. w == PSUB_PrinterInfoButton(psub) || \
  75. w == PSUB_SelectPrinterButton(psub) || \
  76. w == PSUB_SelectFileButton(psub) || \
  77. w == PSUB_PrintButton(psub) || \
  78. w == PSUB_SetupButton(psub) || \
  79. w == PSUB_CancelButton(psub) || \
  80. w == PSUB_HelpButton(psub))
  81. /*
  82. * value to indicate initially unspecified resources
  83. */
  84. #define DtUNSPECIFIED (~0)
  85. /*
  86. * limits
  87. */
  88. #define MAX_COPIES MAXINT
  89. /*
  90. * defaults
  91. */
  92. #define WORK_AREA_DEFAULT DtWORK_AREA_BOTTOM
  93. #define SETUP_MODE_DEFAULT DtPRINT_SETUP_XP
  94. #define DESCRIPTION_COLUMNS 35
  95. #define FILE_NAME_COLUMNS 27
  96. #define PRINTER_NAME_COLUMNS 25
  97. /*
  98. * Xp Attributes
  99. */
  100. #define XpATTR_DESCRIPTOR "descriptor"
  101. #define XpATTR_DOC_ATTRS_SUPPORTED "document-attributes-supported"
  102. #define XpATTR_COPY_COUNT "copy-count"
  103. #define XpATTR_SETUP_PROVISO "xp-setup-proviso"
  104. #define XpATTR_SETUP_STATE "xp-setup-state"
  105. /*
  106. * ------------------------------------------------------------------------
  107. * Type Definitions
  108. *
  109. */
  110. typedef enum {
  111. DtPRINT_NULL_CHILD,
  112. DtPRINT_CANCEL_BUTTON,
  113. DtPRINT_FILES_BUTTON,
  114. DtPRINT_HELP_BUTTON,
  115. DtPRINT_INFO_BUTTON,
  116. DtPRINT_PRINT_BUTTON,
  117. DtPRINT_PRINTERS_BUTTON,
  118. DtPRINT_SETUP_BUTTON
  119. } DtPrintSetupBoxChild;
  120. /*
  121. * column oriented geometry definitions
  122. */
  123. #define PSUB_GEO_COL_COUNT 3
  124. #define PSUB_GEO_MAX_ROW 4
  125. typedef enum {
  126. PSUB_GEO_ALIGN_LEFT = 0, /* default */
  127. PSUB_GEO_ALIGN_RIGHT,
  128. PSUB_GEO_ALIGN_EXPAND
  129. } PSUB_GeoBoxAlignment;
  130. typedef struct
  131. {
  132. XmKidGeometry geo;
  133. PSUB_GeoBoxAlignment align;
  134. Dimension orig_width;
  135. } PSUB_GeoBoxRec, *PSUB_GeoBox;
  136. typedef struct
  137. {
  138. int row_count;
  139. PSUB_GeoBoxRec pbox[PSUB_GEO_MAX_ROW][PSUB_GEO_COL_COUNT];
  140. XmGeoRowLayout layout_ptr[PSUB_GEO_MAX_ROW];
  141. Dimension col_width[PSUB_GEO_COL_COUNT];
  142. } PSUB_GeoExtensionRec, *PSUB_GeoExtension ;
  143. /*
  144. * ------------------------------------------------------------------------
  145. * External Function Declarations
  146. *
  147. */
  148. /*
  149. * Geometry management functions defined in Xm/GeoUtils
  150. */
  151. extern XmGeoMatrix _XmGeoMatrixAlloc(
  152. unsigned int numRows,
  153. unsigned int numBoxes,
  154. unsigned int extSize);
  155. extern Boolean _XmGeoSetupKid(
  156. XmKidGeometry geo,
  157. Widget kidWid);
  158. /*
  159. * ------------------------------------------------------------------------
  160. * Static Function Declarations
  161. *
  162. */
  163. static void ClassInitialize(
  164. void);
  165. static void ClassPartInitialize(
  166. WidgetClass w_class);
  167. static void ClosePrintConnection(
  168. DtPrintSetupBoxWidget psub,
  169. String old_printer_name,
  170. Boolean update_gui);
  171. static void ClosePrintConnectionCallback(Widget w,
  172. XtPointer client_data,
  173. XtPointer call_data);
  174. static void ColumnGeoFixUp(
  175. XmGeoMatrix geoSpec,
  176. int action,
  177. XmGeoMajorLayout layoutPtr,
  178. XmKidGeometry rowPtr);
  179. static void ColumnGeoPreSet(
  180. PSUB_GeoExtension ext,
  181. int row);
  182. static void ColumnGeoRestoreWidths(
  183. PSUB_GeoExtension ext,
  184. int row);
  185. static void ColumnGeoSaveWidths(
  186. PSUB_GeoExtension ext,
  187. int row);
  188. static void ColumnGeoSetPreferredWidths(
  189. PSUB_GeoExtension ext,
  190. int row);
  191. static Boolean ConvertStringToEnum(
  192. Display *dpy,
  193. XrmValuePtr args,
  194. Cardinal *num_args,
  195. XrmValuePtr from,
  196. XrmValuePtr to,
  197. XtPointer *data);
  198. static void CopiesTextValueChangedCallback(
  199. Widget w,
  200. XtPointer client_data,
  201. XtPointer call_data);
  202. static Widget CreateButton(Widget parent,
  203. String label,
  204. String name,
  205. XmNavigationType nav_type);
  206. static Widget CreateButtonGadget(
  207. Widget parent,
  208. String label,
  209. String name,
  210. XmNavigationType nav_type);
  211. static Widget CreateLabelGadget(
  212. Widget parent,
  213. String label,
  214. String name);
  215. static String CreateModalPrinterSpec(
  216. XtEnum name_mode,
  217. const String full_printer_name);
  218. static void DeleteChild(
  219. Widget child);
  220. static void DestinationChangedCallback(
  221. Widget w,
  222. XtPointer client_data,
  223. XtPointer call_data);
  224. static void Destroy(
  225. Widget w);
  226. static XtEnum EstablishPrinter(
  227. DtPrintSetupBoxWidget psub,
  228. DtPrintSetupData* psd);
  229. static void GetPrintAttributes(
  230. DtPrintSetupBoxWidget psub);
  231. static void Initialize(
  232. Widget rw,
  233. Widget nw,
  234. ArgList args,
  235. Cardinal *num_args);
  236. static void InsertChild(
  237. Widget child);
  238. static Boolean IsSetupRequired(
  239. DtPrintSetupBoxWidget psub);
  240. static void MenuBarFixUp(
  241. XmGeoMatrix geoSpec,
  242. int action,
  243. XmGeoMajorLayout layoutPtr,
  244. XmKidGeometry rowPtr);
  245. static void PrintSetupBoxCallback(
  246. Widget w,
  247. XtPointer client_data,
  248. XtPointer call_data);
  249. static void SeparatorFixUp(
  250. XmGeoMatrix geoSpec,
  251. int action,
  252. XmGeoMajorLayout layoutPtr,
  253. XmKidGeometry rowPtr);
  254. static void SetNewPrinterName(
  255. DtPrintSetupBoxWidget psub,
  256. String new_printer_name,
  257. String old_printer_name);
  258. static void SetPrintAttributes(
  259. DtPrintSetupBoxWidget psub);
  260. static void SetPSDDestination(
  261. DtPrintSetupBoxWidget psub,
  262. DtPrintSetupData* psd);
  263. static XmImportOperator SetSyntheticResForChild(
  264. Widget widget,
  265. int offset,
  266. XtArgVal *value);
  267. static Boolean SetValues(
  268. Widget cw,
  269. Widget rw,
  270. Widget nw,
  271. ArgList args,
  272. Cardinal *num_args) ;
  273. static int SpanNonWhitespace(
  274. const char* string);
  275. static int SpanWhitespace(
  276. const char* string);
  277. static void SynthGetFileName(
  278. DtPrintSetupBoxWidget psub);
  279. static void SynthGetPrinterName(
  280. DtPrintSetupBoxWidget psub);
  281. static void SynthSetCopies(
  282. DtPrintSetupBoxWidget new_w,
  283. DtPrintSetupBoxWidget current);
  284. static void SynthSetFileName(
  285. DtPrintSetupBoxWidget new_w,
  286. DtPrintSetupBoxWidget current);
  287. static void SynthSetPrintDestination(
  288. DtPrintSetupBoxWidget new_w,
  289. DtPrintSetupBoxWidget current);
  290. static void SynthSetPrinterName(
  291. DtPrintSetupBoxWidget psub,
  292. String new_printer_name,
  293. String old_printer_name);
  294. static void UpdatePrinterNameCallback(
  295. Widget w,
  296. XtPointer client_data,
  297. XtPointer call_data);
  298. static void UpdatePrinterNameTimeoutProc(XtPointer client_data,
  299. XtIntervalId* id);
  300. static void UpdateString(
  301. Widget w,
  302. XmString string,
  303. XmStringDirection direction) ;
  304. static void ValidatePrintSetupMode(
  305. DtPrintSetupBoxWidget new_w,
  306. DtPrintSetupBoxWidget current);
  307. static void ValidateWorkAreaLocation(
  308. DtPrintSetupBoxWidget new_w,
  309. DtPrintSetupBoxWidget current);
  310. /*
  311. * ------------------------------------------------------------------------
  312. * Static Global Variable Definitions
  313. *
  314. */
  315. /*
  316. * Synthetic Resource Definitions
  317. */
  318. static XmSyntheticResource syn_resources[] =
  319. {
  320. {
  321. DtNcopies,
  322. sizeof(int),
  323. XtOffsetOf(DtPrintSetupBoxRec,
  324. print_setup_box.copies),
  325. _DtPrintSetupBoxGetCopies,
  326. SetSyntheticResForChild
  327. },
  328. {
  329. DtNdescription,
  330. sizeof(XmString),
  331. XtOffsetOf(DtPrintSetupBoxRec,
  332. print_setup_box.description_string),
  333. _DtPrintSetupBoxGetDescription,
  334. SetSyntheticResForChild
  335. },
  336. {
  337. DtNfileName,
  338. sizeof(String),
  339. XtOffsetOf(DtPrintSetupBoxRec,
  340. print_setup_box.file_name),
  341. _DtPrintSetupBoxGetFileName,
  342. SetSyntheticResForChild
  343. },
  344. {
  345. DtNprinterName,
  346. sizeof(String),
  347. XtOffsetOf(DtPrintSetupBoxRec,
  348. print_setup_box.printer_name),
  349. _DtPrintSetupBoxGetPrinterName,
  350. SetSyntheticResForChild
  351. }
  352. };
  353. /*
  354. * Resource Definitions
  355. */
  356. static XtResource resources[] =
  357. {
  358. {
  359. XmNnoResize, XmNnoResize,
  360. XmRBoolean, sizeof(Boolean),
  361. XtOffsetOf(XmBulletinBoardRec, bulletin_board.no_resize),
  362. XmRImmediate, (XtPointer) True
  363. },
  364. {
  365. DtNcancelCallback, DtCCancelCallback,
  366. XmRCallback, sizeof(XtCallbackList),
  367. XtOffsetOf(DtPrintSetupBoxRec,
  368. print_setup_box.cancel_callback),
  369. XmRImmediate, (XtPointer) NULL
  370. },
  371. {
  372. DtNclosePrintDisplayCallback, DtCClosePrintDisplayCallback,
  373. XmRCallback, sizeof(XtCallbackList),
  374. XtOffsetOf(DtPrintSetupBoxRec,
  375. print_setup_box.close_display_callback),
  376. XmRImmediate, (XtPointer) NULL
  377. },
  378. {
  379. DtNcopies, DtCCopies,
  380. XmRInt, sizeof(int),
  381. XtOffsetOf(DtPrintSetupBoxRec,
  382. print_setup_box.copies),
  383. XmRImmediate, (XtPointer) 1
  384. },
  385. {
  386. DtNdescription, DtCDescription,
  387. XmRXmString, sizeof(XmString),
  388. XtOffsetOf(DtPrintSetupBoxRec,
  389. print_setup_box.description_string),
  390. XmRString, (XtPointer) NULL
  391. },
  392. {
  393. DtNfileName, DtCFileName,
  394. XmRString, sizeof(String),
  395. XtOffsetOf(DtPrintSetupBoxRec,
  396. print_setup_box.file_name),
  397. XmRString, (XtPointer) NULL
  398. },
  399. {
  400. DtNminimizeButtons, DtCMinimizeButtons,
  401. XmRBoolean, sizeof(Boolean),
  402. XtOffsetOf(DtPrintSetupBoxRec,
  403. print_setup_box.minimize_buttons),
  404. XmRImmediate, (XtPointer) False
  405. },
  406. {
  407. DtNprintCallback, DtCPrintCallback,
  408. XmRCallback, sizeof(XtCallbackList),
  409. XtOffsetOf(DtPrintSetupBoxRec,
  410. print_setup_box.print_callback),
  411. XmRImmediate, (XtPointer) NULL
  412. },
  413. {
  414. DtNoptionCount, DtCOptionCount,
  415. XmRCardinal, sizeof(Cardinal),
  416. XtOffsetOf(DtPrintSetupBoxRec,
  417. print_setup_box.option_count),
  418. XmRImmediate, (XtPointer) 0
  419. },
  420. {
  421. DtNoptions, DtCOptions,
  422. XmRPointer, sizeof(XtPointer),
  423. XtOffsetOf(DtPrintSetupBoxRec,
  424. print_setup_box.options),
  425. XmRImmediate, (XtPointer) NULL
  426. },
  427. {
  428. DtNprintDestination, DtCPrintDestination,
  429. XmREnum, sizeof(XtEnum),
  430. XtOffsetOf(DtPrintSetupBoxRec,
  431. print_setup_box.print_destination),
  432. XmRImmediate, (XtPointer) DtPRINT_TO_PRINTER,
  433. },
  434. {
  435. DtNprinterInfoProc, DtCPrinterInfoProc,
  436. DtRPrintSetupProc, sizeof(DtPrintSetupProc),
  437. XtOffsetOf(DtPrintSetupBoxRec,
  438. print_setup_box.printer_info_proc),
  439. XmRImmediate, (XtPointer)DtUNSPECIFIED
  440. },
  441. {
  442. DtNprinterName, DtCPrinterName,
  443. XmRString, sizeof(String),
  444. XtOffsetOf(DtPrintSetupBoxRec,
  445. print_setup_box.printer_name),
  446. XmRString, (XtPointer) NULL
  447. },
  448. {
  449. DtNprintSetupMode, DtCPrintSetupMode,
  450. XmREnum, sizeof(XtEnum),
  451. XtOffsetOf(DtPrintSetupBoxRec,
  452. print_setup_box.print_setup_mode),
  453. XmRImmediate, (XtPointer)SETUP_MODE_DEFAULT,
  454. },
  455. {
  456. DtNselectFileProc, DtCSelectFileProc,
  457. DtRPrintSetupProc, sizeof(DtPrintSetupProc),
  458. XtOffsetOf(DtPrintSetupBoxRec,
  459. print_setup_box.select_file_proc),
  460. XmRImmediate, (XtPointer) _DtPrintSetupBoxSelectFileProc
  461. },
  462. {
  463. DtNselectPrinterProc, DtCSelectPrinterProc,
  464. DtRPrintSetupProc, sizeof(DtPrintSetupProc),
  465. XtOffsetOf(DtPrintSetupBoxRec,
  466. print_setup_box.select_printer_proc),
  467. XmRImmediate, (XtPointer)DtUNSPECIFIED
  468. },
  469. {
  470. DtNsetupCallback, DtCSetupCallback,
  471. XmRCallback, sizeof(XtCallbackList),
  472. XtOffsetOf(DtPrintSetupBoxRec,
  473. print_setup_box.setup_callback),
  474. XmRImmediate, (XtPointer) NULL
  475. },
  476. {
  477. DtNverifyPrinterProc, DtCVerifyPrinterProc,
  478. DtRPrintSetupProc, sizeof(DtPrintSetupProc),
  479. XtOffsetOf(DtPrintSetupBoxRec,
  480. print_setup_box.verify_printer_proc),
  481. XmRImmediate, (XtPointer)DtUNSPECIFIED
  482. },
  483. {
  484. DtNworkAreaLocation, DtCWorkAreaLocation,
  485. XmREnum, sizeof(XtEnum),
  486. XtOffsetOf(DtPrintSetupBoxRec,
  487. print_setup_box.work_area_location),
  488. XmRImmediate, (XtPointer)WORK_AREA_DEFAULT,
  489. },
  490. };
  491. externaldef(dtprintsetupboxclassrec) DtPrintSetupBoxClassRec
  492. dtPrintSetupBoxClassRec =
  493. {
  494. {
  495. /* superclass */ (WidgetClass)&xmBulletinBoardClassRec,
  496. /* class_name */ "DtPrintSetupBox",
  497. /* widget_size */ sizeof(DtPrintSetupBoxRec),
  498. /* class_initialize */ ClassInitialize,
  499. /* chained class init */ ClassPartInitialize,
  500. /* class_inited */ FALSE,
  501. /* initialize */ Initialize,
  502. /* initialize hook */ NULL,
  503. /* realize */ XtInheritRealize,
  504. /* actions */ NULL,
  505. /* num_actions */ 0,
  506. /* resources */ resources,
  507. /* num_resources */ XtNumber(resources),
  508. /* xrm_class */ NULLQUARK,
  509. /* compress_motion */ TRUE,
  510. /* compress_exposure */ XtExposeCompressMaximal,
  511. /* compress enter/exit*/ TRUE,
  512. /* visible_interest */ FALSE,
  513. /* destroy */ Destroy,
  514. /* resize */ XtInheritResize,
  515. /* expose */ XtInheritExpose,
  516. /* set_values */ SetValues,
  517. /* set_values_hook */ NULL,
  518. /* set_values_almost */ XtInheritSetValuesAlmost,
  519. /* get_values_hook */ NULL,
  520. /* accept_focus */ NULL,
  521. /* version */ XtVersion,
  522. /* callback_offsets */ NULL,
  523. /* tm_table */ XtInheritTranslations,
  524. /* query_geometry */ XtInheritGeometryManager,
  525. /* display_accelerator*/ NULL,
  526. /* extension */ NULL,
  527. },
  528. { /* composite class record */
  529. /* childrens geo mgr proc */ XtInheritGeometryManager,
  530. /* set changed proc */ XtInheritChangeManaged,
  531. /* insert_child */ InsertChild,
  532. /* delete_child */ DeleteChild,
  533. /* extension */ NULL,
  534. },
  535. { /* constraint class record */
  536. /* no additional resources */ NULL,
  537. /* num additional resources */ 0,
  538. /* size of constraint rec */ 0,
  539. /* constraint_initialize */ NULL,
  540. /* constraint_destroy */ NULL,
  541. /* constraint_setvalue */ NULL,
  542. /* extension */ NULL,
  543. },
  544. { /* manager class record */
  545. XmInheritTranslations, /* default translations */
  546. syn_resources, /* syn_resources */
  547. XtNumber (syn_resources), /* num_syn_resources */
  548. NULL, /* syn_cont_resources */
  549. 0, /* num_syn_cont_resources */
  550. XmInheritParentProcess, /* parent_process */
  551. NULL, /* extension */
  552. },
  553. { /* bulletin board class record */
  554. TRUE, /*always_install_accelerators*/
  555. _DtPrintSetupBoxGeoMatrixCreate, /* geo_matrix_create */
  556. XmInheritFocusMovedProc, /* focus_moved_proc */
  557. NULL, /* extension */
  558. },
  559. { /* print setup box class record */
  560. NULL, /* extension */
  561. },
  562. };
  563. externaldef(dtprintsetupboxwidgetclass) WidgetClass dtPrintSetupBoxWidgetClass = (WidgetClass) &dtPrintSetupBoxClassRec ;
  564. /*
  565. * ------------------------------------------------------------------------
  566. * Name: ClassInitialize - Core class method
  567. *
  568. * Description:
  569. *
  570. * Return value:
  571. *
  572. * None.
  573. *
  574. */
  575. static void
  576. ClassInitialize(void)
  577. {
  578. /*
  579. * Register a type converter for String to Enum
  580. */
  581. XtSetTypeConverter("String", "Enum", ConvertStringToEnum,
  582. NULL, 0, XtCacheAll, NULL);
  583. }
  584. /*
  585. * ------------------------------------------------------------------------
  586. * Name: ClassPartInitialize - Core class method
  587. *
  588. * Description:
  589. *
  590. * Return value:
  591. *
  592. * None.
  593. *
  594. */
  595. static void
  596. ClassPartInitialize(WidgetClass w_class)
  597. {
  598. DtPrintSetupBoxWidgetClass wc = (DtPrintSetupBoxWidgetClass) w_class;
  599. DtPrintSetupBoxWidgetClass super =
  600. (DtPrintSetupBoxWidgetClass) wc->core_class.superclass;
  601. if (wc->print_setup_box_class.list_callback == XmInheritCallbackProc)
  602. wc->print_setup_box_class.list_callback =
  603. super->print_setup_box_class.list_callback;
  604. }
  605. /*
  606. * ------------------------------------------------------------------------
  607. * Name: ClosePrintConnection
  608. *
  609. * Description:
  610. *
  611. * Call the DtNclosePrintDisplayCallback list, and destroy the print
  612. * context and X print display connection managed by the widget.
  613. *
  614. * Return value:
  615. *
  616. * None.
  617. *
  618. */
  619. static void
  620. ClosePrintConnection(
  621. DtPrintSetupBoxWidget psub,
  622. String old_printer_name,
  623. Boolean update_gui)
  624. {
  625. DtPrintSetupCallbackStruct cbs;
  626. DtPrintSetupData psd;
  627. XmString empty_label;
  628. memset(&cbs, 0, sizeof(DtPrintSetupCallbackStruct));
  629. memset(&psd, 0, sizeof(DtPrintSetupData));
  630. cbs.print_data = &psd;
  631. /*
  632. * call DtNclosePrintDisplayCallback before closing the
  633. * current print display
  634. */
  635. cbs.reason = DtPRINT_CR_CLOSE_PRINT_DISPLAY;
  636. psd.printer_name = old_printer_name;
  637. psd.print_display = PSUB_Display(psub);
  638. #if 0 && defined(PRINTING_SUPPORTED)
  639. psd.print_context = PSUB_Context(psub);
  640. #endif /* PRINTING_SUPPORTED */
  641. XtCallCallbackList((Widget)psub,
  642. PSUB_CloseDisplayCallback(psub),
  643. (XtPointer)&cbs);
  644. /*
  645. * unset the printer description
  646. */
  647. if(update_gui)
  648. {
  649. empty_label = XmStringGenerate((XtPointer)"", (XmStringTag)NULL,
  650. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  651. UpdateString(PSUB_Description((Widget)psub),
  652. empty_label, PSUB_StringDirection((Widget)psub));
  653. XmStringFree(empty_label);
  654. }
  655. /*
  656. * reset copy_count_supported flag
  657. */
  658. if(!PSUB_CopyCountSupported(psub))
  659. {
  660. PSUB_CopyCountSupported(psub) = True;
  661. if(PSUB_PrintDestination(psub) == DtPRINT_TO_PRINTER && update_gui)
  662. {
  663. if(PSUB_CopiesSpinBox(psub))
  664. XtSetSensitive(PSUB_CopiesSpinBox(psub), True);
  665. if(PSUB_CopiesControl(psub))
  666. {
  667. Widget copies_label =
  668. XtNameToWidget(PSUB_CopiesControl(psub), "CopiesLabel");
  669. XtSetSensitive(copies_label, True);
  670. }
  671. }
  672. }
  673. /*
  674. * destroy the print context
  675. */
  676. #if 0 && defined(PRINTING_SUPPORTED)
  677. XpDestroyContext(PSUB_Display(psub), PSUB_Context(psub));
  678. PSUB_Context(psub) = (XPContext)NULL;
  679. #endif /* PRINTING_SUPPORTED */
  680. /*
  681. * close the print display
  682. */
  683. XtCloseDisplay(PSUB_Display(psub));
  684. PSUB_Display(psub) = (Display*)NULL;
  685. }
  686. /*
  687. * ------------------------------------------------------------------------
  688. * Name: ClosePrintConnectionCallback
  689. *
  690. * Description:
  691. *
  692. * Calls ClosePrintConnection if there is an existing connection.
  693. *
  694. * Return value:
  695. *
  696. * None.
  697. *
  698. */
  699. static void
  700. ClosePrintConnectionCallback(Widget w,
  701. XtPointer client_data,
  702. XtPointer call_data)
  703. {
  704. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)client_data;
  705. /*
  706. * close the Xp connection if open
  707. */
  708. if(PSUB_Display(psub) != (Display*)NULL)
  709. {
  710. ClosePrintConnection(psub, PSUB_PrinterName(psub), True);
  711. }
  712. }
  713. /*
  714. * ------------------------------------------------------------------------
  715. * Name: ColumnGeoFixUp
  716. *
  717. * Description:
  718. *
  719. * This routine is a fixup routine which can be used for groups of
  720. * rows containing entries that can be organized into columns.
  721. *
  722. * Return value:
  723. *
  724. * None.
  725. *
  726. */
  727. static void
  728. ColumnGeoFixUp(
  729. XmGeoMatrix geo_spec,
  730. int action,
  731. XmGeoMajorLayout layout_ptr,
  732. XmKidGeometry row_ptr)
  733. {
  734. PSUB_GeoExtension ext = geo_spec->extension;
  735. int row;
  736. /*
  737. * determine which row we're on
  738. */
  739. for(row = 0; row < ext->row_count; row++)
  740. if((ext->layout_ptr)[row] == &(layout_ptr->row))
  741. break;
  742. if(row == ext->row_count)
  743. /*
  744. * shouldn't happen
  745. */
  746. return;
  747. switch(action)
  748. {
  749. case XmGET_PREFERRED_SIZE:
  750. ColumnGeoSaveWidths(ext, row);
  751. ColumnGeoSetPreferredWidths(ext, row);
  752. break;
  753. case XmGEO_PRE_SET:
  754. ColumnGeoPreSet(ext, row);
  755. break;
  756. case XmGEO_POST_SET:
  757. ColumnGeoRestoreWidths(ext, row);
  758. break;
  759. }
  760. }
  761. /*
  762. * ------------------------------------------------------------------------
  763. * Name: ColumnGeoPreSet
  764. *
  765. * Description:
  766. *
  767. * Update origins and widths based on alignment.
  768. *
  769. * Return value:
  770. *
  771. * None.
  772. *
  773. */
  774. static void
  775. ColumnGeoPreSet(
  776. PSUB_GeoExtension ext,
  777. int row)
  778. {
  779. Dimension delta = 0;
  780. Dimension slack = 0;
  781. int col;
  782. for(col = 0; col < PSUB_GEO_COL_COUNT; col++)
  783. {
  784. PSUB_GeoBox pbox = &(ext->pbox)[row][col];
  785. if(pbox->geo)
  786. {
  787. pbox->geo->box.x += slack;
  788. switch(pbox->align)
  789. {
  790. case PSUB_GEO_ALIGN_RIGHT:
  791. delta += (ext->col_width)[col] - pbox->geo->box.width;
  792. pbox->geo->box.x += (ext->col_width)[col] - pbox->orig_width;
  793. pbox->geo->box.width = pbox->orig_width;
  794. break;
  795. case PSUB_GEO_ALIGN_LEFT:
  796. pbox->geo->box.x += delta;
  797. delta += (ext->col_width)[col] - pbox->geo->box.width;
  798. pbox->geo->box.width = pbox->orig_width;
  799. break;
  800. case PSUB_GEO_ALIGN_EXPAND:
  801. pbox->geo->box.x += delta;
  802. pbox->geo->box.width = (ext->col_width)[col];
  803. break;
  804. }
  805. }
  806. else
  807. slack += (ext->col_width)[col];
  808. }
  809. }
  810. /*
  811. * ------------------------------------------------------------------------
  812. * Name: ColumnGeoRestoreWidths
  813. *
  814. * Description:
  815. *
  816. * Restore the original widths for items in the current row.
  817. *
  818. * Return value:
  819. *
  820. * None.
  821. *
  822. */
  823. static void
  824. ColumnGeoRestoreWidths(
  825. PSUB_GeoExtension ext,
  826. int row)
  827. {
  828. int col;
  829. for(col = 0; col < PSUB_GEO_COL_COUNT; col++)
  830. {
  831. PSUB_GeoBox pbox = &(ext->pbox)[row][col];
  832. if(pbox->geo)
  833. {
  834. /*
  835. * restore the original box width
  836. */
  837. pbox->geo->box.width = pbox->orig_width;
  838. }
  839. }
  840. }
  841. /*
  842. * ------------------------------------------------------------------------
  843. * Name: ColumnGeoSaveWidths
  844. *
  845. * Description:
  846. *
  847. * Save the original widths for items in the current row, and
  848. * increase a given column width if an item in a corresponding column
  849. * in this row is wider.
  850. *
  851. * Return value:
  852. *
  853. * None.
  854. *
  855. */
  856. static void
  857. ColumnGeoSaveWidths(
  858. PSUB_GeoExtension ext,
  859. int row)
  860. {
  861. int col;
  862. for(col = 0; col < PSUB_GEO_COL_COUNT; col++)
  863. {
  864. PSUB_GeoBox pbox = &(ext->pbox)[row][col];
  865. if(pbox->geo)
  866. {
  867. /*
  868. * save the original box width
  869. */
  870. pbox->orig_width = pbox->geo->box.width;
  871. /*
  872. * update the overall column width
  873. */
  874. if(pbox->geo->box.width > (ext->col_width)[col])
  875. (ext->col_width)[col] = pbox->geo->box.width;
  876. }
  877. }
  878. }
  879. /*
  880. * ------------------------------------------------------------------------
  881. * Name: ColumnGeoSetPreferredWidths
  882. *
  883. * Description:
  884. *
  885. * Ensure the overall width of the current row is equal to the
  886. * overall width of all of the columns.
  887. *
  888. * Assumes at least one box is defined in the row.
  889. *
  890. * Return value:
  891. *
  892. * None.
  893. *
  894. */
  895. static void
  896. ColumnGeoSetPreferredWidths(
  897. PSUB_GeoExtension ext,
  898. int row)
  899. {
  900. Dimension slack = 0;
  901. int last_non_empty_col = 0;
  902. int col;
  903. for(col = 0; col < PSUB_GEO_COL_COUNT; col++)
  904. {
  905. PSUB_GeoBox pbox = &(ext->pbox)[row][col];
  906. if(pbox->geo)
  907. {
  908. pbox->geo->box.width = (ext->col_width)[col] + slack;
  909. slack = 0;
  910. last_non_empty_col = col;
  911. }
  912. else
  913. {
  914. slack += (ext->col_width)[col];
  915. }
  916. }
  917. if(slack)
  918. (ext->pbox)[row][last_non_empty_col].geo->box.width += slack;
  919. }
  920. /*
  921. * ------------------------------------------------------------------------
  922. * Name: ConvertStringToEnum
  923. *
  924. * Description:
  925. *
  926. * This type converter converts from type String to Enum. It is
  927. * used for the DtNprintDestination, DtNworkAreaLocation, and
  928. * DtNprintSetupMode resources.
  929. *
  930. */
  931. static Boolean
  932. ConvertStringToEnum(
  933. Display *dpy,
  934. XrmValuePtr args,
  935. Cardinal *num_args,
  936. XrmValuePtr from,
  937. XrmValuePtr to,
  938. XtPointer *data)
  939. {
  940. char *from_str;
  941. static unsigned char to_value;
  942. if(*num_args !=0 )
  943. {
  944. XtError(WARN_CONVERSION_ARGS);
  945. }
  946. from_str = (char *)from->addr;
  947. if(strcmp(from_str, "PRINT_TO_FILE")==0 ||
  948. strcmp(from_str, "DtPRINT_TO_FILE")==0)
  949. to_value = DtPRINT_TO_FILE;
  950. else if(strcmp(from_str, "PRINT_TO_PRINTER")==0 ||
  951. strcmp(from_str, "DtPRINT_TO_PRINTER")==0)
  952. to_value = DtPRINT_TO_PRINTER;
  953. else if(strcmp(from_str, "PRINT_SETUP_PLAIN")==0 ||
  954. strcmp(from_str, "DtPRINT_SETUP_PLAIN")==0)
  955. to_value = DtPRINT_SETUP_PLAIN;
  956. else if(strcmp(from_str, "PRINT_SETUP_XP")==0 ||
  957. strcmp(from_str, "DtPRINT_SETUP_XP")==0)
  958. to_value = DtPRINT_SETUP_XP;
  959. else if(strcmp(from_str, "WORK_AREA_BOTTOM")==0 ||
  960. strcmp(from_str, "DtWORK_AREA_BOTTOM")==0)
  961. to_value = DtWORK_AREA_BOTTOM;
  962. else if(strcmp(from_str, "WORK_AREA_TOP")==0 ||
  963. strcmp(from_str, "DtWORK_AREA_TOP")==0)
  964. to_value = DtWORK_AREA_TOP;
  965. else if(strcmp(from_str, "WORK_AREA_TOP_AND_BOTTOM")==0 ||
  966. strcmp(from_str, "DtWORK_AREA_TOP_AND_BOTTOM")==0)
  967. to_value = DtWORK_AREA_TOP_AND_BOTTOM;
  968. else if(strcmp(from_str, "SHORT_NAME")==0 ||
  969. strcmp(from_str, "DtSHORT_NAME")==0)
  970. to_value = DtSHORT_NAME;
  971. else if(strcmp(from_str, "MEDIUM_NAME")==0 ||
  972. strcmp(from_str, "DtMEDIUM_NAME")==0)
  973. to_value = DtMEDIUM_NAME;
  974. else if(strcmp(from_str, "LONG_NAME")==0 ||
  975. strcmp(from_str, "DtLONG_NAME")==0)
  976. to_value = DtLONG_NAME;
  977. else
  978. {
  979. XtDisplayStringConversionWarning(dpy, from->addr, "Enum");
  980. return False;
  981. }
  982. if(to->addr == NULL)
  983. to->addr = (caddr_t) &to_value;
  984. else if(to->size <sizeof(unsigned char))
  985. {
  986. XtDisplayStringConversionWarning(dpy, from->addr, "Enum");
  987. return False;
  988. }
  989. else
  990. *(unsigned char *) to->addr = to_value;
  991. to->size = sizeof(unsigned char);
  992. return True;
  993. }
  994. /*
  995. * ------------------------------------------------------------------------
  996. * Name: CopiesTextValueChangedCallback
  997. *
  998. * Description:
  999. *
  1000. * Process a change in the textfield of the copies simple spin box.
  1001. *
  1002. * Return value:
  1003. *
  1004. * None.
  1005. *
  1006. */
  1007. static void
  1008. CopiesTextValueChangedCallback(
  1009. Widget w,
  1010. XtPointer client_data,
  1011. XtPointer call_data)
  1012. {
  1013. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)client_data;
  1014. XmAnyCallbackStruct* cbs = (XmAnyCallbackStruct*)call_data;
  1015. if (NULL == psub || NULL == cbs) return;
  1016. if(XmCR_VALUE_CHANGED == cbs->reason)
  1017. {
  1018. char *value = NULL;
  1019. int value_int = 0;
  1020. XtVaGetValues(w, XmNvalue, &value, NULL);
  1021. if (value) value_int = strtol(value, (char**)NULL, 10);
  1022. if (1 <= value_int || value_int <= MAX_COPIES)
  1023. {
  1024. PSUB_Copies(psub) = value_int;
  1025. XtVaSetValues(
  1026. PSUB_CopiesSpinBox(psub),
  1027. XmNposition, value_int,
  1028. NULL);
  1029. }
  1030. else
  1031. {
  1032. XmeWarning((Widget)w, WARN_COPY_COUNT);
  1033. XtVaGetValues(
  1034. PSUB_CopiesSpinBox(psub),
  1035. XmNposition, &value_int,
  1036. NULL);
  1037. value = (char*) XtMalloc(64);
  1038. if (value)
  1039. {
  1040. sprintf(value, "%d", value_int);
  1041. XtVaSetValues(w, XmNvalue, value, NULL);
  1042. XtFree(value);
  1043. }
  1044. }
  1045. if (value) XtVaSetValues(w, XmNcursorPosition, strlen(value), NULL);
  1046. }
  1047. }
  1048. /*
  1049. * ------------------------------------------------------------------------
  1050. * Name: CreateButton
  1051. *
  1052. * Description:
  1053. *
  1054. * Return value:
  1055. *
  1056. * Widget ID of the new button widget.
  1057. *
  1058. */
  1059. static Widget
  1060. CreateButton(Widget parent,
  1061. String label,
  1062. String name,
  1063. XmNavigationType nav_type)
  1064. {
  1065. XmString label_string;
  1066. Widget w;
  1067. XmTakesDefaultTrait trait_default ;
  1068. label_string = XmStringGenerate((XtPointer)label, (XmStringTag)NULL,
  1069. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  1070. w = XtVaCreateWidget(name,
  1071. xmPushButtonWidgetClass,
  1072. parent,
  1073. XmNlabelString, label_string,
  1074. XmNnavigationType, nav_type,
  1075. NULL);
  1076. if(label_string) XmStringFree(label_string);
  1077. trait_default = (XmTakesDefaultTrait)
  1078. XmeTraitGet((XtPointer)XtClass(w), XmQTtakesDefault) ;
  1079. if(trait_default)
  1080. trait_default->showAsDefault(w, XmDEFAULT_READY);
  1081. return w;
  1082. }
  1083. /*
  1084. * ------------------------------------------------------------------------
  1085. * Name: CreateButtonGadget
  1086. *
  1087. * Description:
  1088. *
  1089. * Return value:
  1090. *
  1091. * Widget ID of the new button gadget.
  1092. *
  1093. */
  1094. static Widget
  1095. CreateButtonGadget(Widget parent,
  1096. String label,
  1097. String name,
  1098. XmNavigationType nav_type)
  1099. {
  1100. XmString label_string;
  1101. Widget w;
  1102. XmTakesDefaultTrait trait_default ;
  1103. label_string = XmStringGenerate((XtPointer)label, (XmStringTag)NULL,
  1104. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  1105. w = XtVaCreateWidget(name,
  1106. xmPushButtonGadgetClass,
  1107. parent,
  1108. XmNlabelString, label_string,
  1109. XmNnavigationType, nav_type,
  1110. NULL);
  1111. if(label_string) XmStringFree(label_string);
  1112. trait_default = (XmTakesDefaultTrait)
  1113. XmeTraitGet((XtPointer)XtClass(w), XmQTtakesDefault) ;
  1114. if(trait_default)
  1115. trait_default->showAsDefault(w, XmDEFAULT_READY);
  1116. return w;
  1117. }
  1118. /*
  1119. * ------------------------------------------------------------------------
  1120. * Name: CreateLabelGadget
  1121. *
  1122. * Description:
  1123. *
  1124. * Return value:
  1125. *
  1126. * Widget ID of the new label gadget.
  1127. *
  1128. */
  1129. static Widget
  1130. CreateLabelGadget(
  1131. Widget parent,
  1132. String label,
  1133. String name)
  1134. {
  1135. XmString label_string;
  1136. Widget w;
  1137. label_string = XmStringGenerate((XtPointer)label, (XmStringTag)NULL,
  1138. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  1139. w = XtVaCreateWidget(name,
  1140. xmLabelGadgetClass,
  1141. parent,
  1142. XmNlabelString, label_string,
  1143. NULL);
  1144. if(label_string) XmStringFree(label_string);
  1145. return w;
  1146. }
  1147. /*
  1148. * ------------------------------------------------------------------------
  1149. * Name: CreateModalPrinterSpec
  1150. *
  1151. * Arguments:
  1152. *
  1153. * name_mode
  1154. * A valid X Printer Specifier Display Mode (see the
  1155. * XpPrinterNameMode resource definition).
  1156. *
  1157. * full_printer_name
  1158. * The fully qualified printer name
  1159. *
  1160. * Description:
  1161. *
  1162. * Creates an X Printer Specifier appropriate to an X Printer
  1163. * Specifier Display Mode, given a full printer name
  1164. *
  1165. * Return value:
  1166. *
  1167. * A newly allocated string containing the resulting X Printer
  1168. * specifier. It is the resposibility of the caller to free the
  1169. * memory using XtFree(1).
  1170. *
  1171. * NULL is returned if:
  1172. * * the passed printer_name is NULL
  1173. * * if memory allocation fails.
  1174. *
  1175. */
  1176. static String
  1177. CreateModalPrinterSpec(
  1178. XtEnum name_mode,
  1179. const String full_printer_name)
  1180. {
  1181. String modal_printer_spec;
  1182. String printer_name;
  1183. String display_spec;
  1184. /*
  1185. * check for NULL passed parms
  1186. */
  1187. if(full_printer_name == (String)NULL)
  1188. {
  1189. return (String)NULL;
  1190. }
  1191. /*
  1192. * break the fully qualified printer name into printer and display
  1193. * name components
  1194. */
  1195. _DtPrintParseXPrinterSpecifier(full_printer_name,
  1196. &printer_name, &display_spec);
  1197. /*
  1198. * if display mode is SHORT, just the printer name will do
  1199. */
  1200. if(name_mode == DtSHORT_NAME)
  1201. {
  1202. modal_printer_spec = XtNewString(printer_name);
  1203. }
  1204. else
  1205. {
  1206. String host_name;
  1207. DtPrintSpecNet spec_net;
  1208. int display_num;
  1209. int screen_num;
  1210. /*
  1211. * break up the display specifier
  1212. */
  1213. _DtPrintParseXDisplaySpecifier(display_spec, &host_name,
  1214. &spec_net, &display_num, &screen_num);
  1215. /*
  1216. * create the modal specifier
  1217. */
  1218. switch(name_mode)
  1219. {
  1220. case DtMEDIUM_NAME:
  1221. modal_printer_spec =
  1222. _DtPrintCreateXPrinterSpecifier(printer_name, host_name,
  1223. DtPRINT_NET_UNSPECIFIED,
  1224. -1, -1);
  1225. break;
  1226. case DtLONG_NAME:
  1227. modal_printer_spec =
  1228. _DtPrintCreateXPrinterSpecifier(printer_name, host_name,
  1229. spec_net,
  1230. display_num, screen_num);
  1231. break;
  1232. default:
  1233. /*
  1234. * invalid name mode; default to short name
  1235. */
  1236. modal_printer_spec = XtNewString(printer_name);
  1237. break;
  1238. }
  1239. XtFree(host_name);
  1240. }
  1241. /*
  1242. * clean up and return
  1243. */
  1244. XtFree(printer_name);
  1245. XtFree(display_spec);
  1246. return modal_printer_spec;
  1247. }
  1248. /*
  1249. * ------------------------------------------------------------------------
  1250. * Name: DeleteChild - Composite class method
  1251. *
  1252. * Description:
  1253. *
  1254. * Remove child from setup box widget
  1255. *
  1256. * Return value:
  1257. *
  1258. * None.
  1259. *
  1260. */
  1261. static void
  1262. DeleteChild(
  1263. Widget child)
  1264. {
  1265. DtPrintSetupBoxWidget psub ;
  1266. XtWidgetProc delete_child;
  1267. if(XtIsRectObj(child))
  1268. {
  1269. psub = (DtPrintSetupBoxWidget) XtParent(child);
  1270. /*
  1271. * Clear widget fields (BulletinBoard does default and cancel).
  1272. */
  1273. if(child == PSUB_BottomSeparator(psub))
  1274. {
  1275. PSUB_BottomSeparator(psub) = NULL;
  1276. }
  1277. else if(child == PSUB_ButtonSeparator(psub))
  1278. {
  1279. PSUB_ButtonSeparator(psub) = NULL;
  1280. }
  1281. else if(child == PSUB_DescriptionLabel(psub))
  1282. {
  1283. PSUB_DescriptionLabel(psub) = NULL;
  1284. }
  1285. else if(child == PSUB_Description(psub))
  1286. {
  1287. PSUB_Description(psub) = NULL;
  1288. }
  1289. else if(child == PSUB_PrinterNameLabel(psub))
  1290. {
  1291. PSUB_PrinterNameLabel(psub) = NULL;
  1292. }
  1293. else if(child == PSUB_CopiesControl(psub))
  1294. {
  1295. PSUB_CopiesControl(psub) = NULL;
  1296. PSUB_CopiesSpinBox(psub) = NULL;
  1297. }
  1298. else if(child == PSUB_TopWorkArea(psub))
  1299. {
  1300. PSUB_TopWorkArea(psub) = NULL;
  1301. }
  1302. else if(child == PSUB_BottomWorkArea(psub))
  1303. {
  1304. PSUB_BottomWorkArea(psub) = NULL;
  1305. }
  1306. else if(child == PSUB_PrintButton(psub))
  1307. {
  1308. PSUB_PrintButton(psub) = NULL;
  1309. }
  1310. else if(child == PSUB_PrinterInfoButton(psub))
  1311. {
  1312. PSUB_PrinterInfoButton(psub) = NULL;
  1313. }
  1314. else if(child == PSUB_PrinterNameCombo(psub))
  1315. {
  1316. PSUB_PrinterNameCombo(psub) = NULL;
  1317. PSUB_PrinterNameText(psub) = NULL;
  1318. }
  1319. else if(child == PSUB_SetupButton(psub))
  1320. {
  1321. PSUB_SetupButton(psub) = NULL;
  1322. }
  1323. else if(child == PSUB_HelpButton(psub))
  1324. {
  1325. PSUB_HelpButton(psub) = NULL;
  1326. }
  1327. else if(child == PSUB_TopSeparator(psub))
  1328. {
  1329. PSUB_TopSeparator(psub) = NULL;
  1330. }
  1331. else if(child == PSUB_DestinationRadioBox(psub))
  1332. {
  1333. PSUB_DestinationRadioBox(psub) = NULL;
  1334. }
  1335. else if(child == PSUB_FileNameLabel(psub))
  1336. {
  1337. PSUB_FileNameLabel(psub) = NULL;
  1338. }
  1339. else if(child == PSUB_FileNameText(psub))
  1340. {
  1341. PSUB_FileNameText(psub) = NULL;
  1342. }
  1343. else if(child == PSUB_SelectFileButton(psub))
  1344. {
  1345. PSUB_SelectFileButton(psub) = NULL;
  1346. }
  1347. else if(child == PSUB_SelectPrinterButton(psub))
  1348. {
  1349. PSUB_SelectPrinterButton(psub) = NULL;
  1350. }
  1351. }
  1352. _DtPrintProcessLock();
  1353. delete_child = ((XmBulletinBoardWidgetClass)xmBulletinBoardWidgetClass)
  1354. ->composite_class.delete_child;
  1355. _DtPrintProcessUnlock();
  1356. (*delete_child)(child) ;
  1357. }
  1358. /*
  1359. * ------------------------------------------------------------------------
  1360. * Name: DestinationChangedCallback
  1361. *
  1362. * Description:
  1363. *
  1364. * Process a change in the print destination generated by the GUI user.
  1365. *
  1366. * Return value:
  1367. *
  1368. * None.
  1369. *
  1370. */
  1371. static void
  1372. DestinationChangedCallback(
  1373. Widget w,
  1374. XtPointer client_data,
  1375. XtPointer call_data)
  1376. {
  1377. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)client_data;
  1378. XmToggleButtonCallbackStruct* cbs =
  1379. (XmToggleButtonCallbackStruct*)call_data;
  1380. if(cbs->set)
  1381. {
  1382. XtPointer user_data;
  1383. /*
  1384. * set the print destination according to the selected radio
  1385. * button
  1386. */
  1387. XtVaGetValues(w, XmNuserData, &user_data, NULL);
  1388. PSUB_PrintDestination(psub) = (XtEnum) (intptr_t) user_data;
  1389. /*
  1390. * Update the print setup box controls sensitivity accordingly
  1391. */
  1392. if(PSUB_SelectFileButton(psub))
  1393. XtSetSensitive(PSUB_SelectFileButton(psub),
  1394. PSUB_PrintDestination(psub) == DtPRINT_TO_FILE);
  1395. if(PSUB_FileNameLabel(psub))
  1396. XtSetSensitive(PSUB_FileNameLabel(psub),
  1397. PSUB_PrintDestination(psub) == DtPRINT_TO_FILE);
  1398. if(PSUB_FileNameText(psub))
  1399. XtSetSensitive(PSUB_FileNameText(psub),
  1400. PSUB_PrintDestination(psub) == DtPRINT_TO_FILE);
  1401. if(PSUB_CopyCountSupported(psub))
  1402. {
  1403. if(PSUB_CopiesSpinBox(psub))
  1404. XtSetSensitive(PSUB_CopiesSpinBox(psub),
  1405. PSUB_PrintDestination(psub) == DtPRINT_TO_PRINTER);
  1406. if(PSUB_CopiesControl(psub))
  1407. {
  1408. Widget copies_label =
  1409. XtNameToWidget(PSUB_CopiesControl(psub), "CopiesLabel");
  1410. XtSetSensitive(copies_label,
  1411. PSUB_PrintDestination(psub) == DtPRINT_TO_PRINTER);
  1412. }
  1413. }
  1414. }
  1415. }
  1416. /*
  1417. * ------------------------------------------------------------------------
  1418. * Name: Destroy - Core class method
  1419. *
  1420. * Description:
  1421. *
  1422. * Clean up resources allocated by the PrintSetupBox widget.
  1423. *
  1424. * Return Value:
  1425. *
  1426. * None.
  1427. */
  1428. static void
  1429. Destroy(
  1430. Widget w)
  1431. {
  1432. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)w;
  1433. /*
  1434. * close the Xp connection
  1435. */
  1436. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP
  1437. &&
  1438. PSUB_Display(psub) != (Display*)NULL)
  1439. {
  1440. ClosePrintConnection(psub, PSUB_PrinterName(psub), False);
  1441. }
  1442. /*
  1443. * synthetic resources
  1444. */
  1445. XtFree(PSUB_FileName(psub));
  1446. XtFree(PSUB_PrinterName(psub));
  1447. /*
  1448. * internal data
  1449. */
  1450. XtFree(PSUB_ModalPrinterSpec(psub));
  1451. }
  1452. /*
  1453. * ------------------------------------------------------------------------
  1454. * Name: EstablishPrinter
  1455. *
  1456. * Description:
  1457. *
  1458. *
  1459. * Return Value:
  1460. *
  1461. * DtPRINT_SUCCESS
  1462. * if a valid printer has been established
  1463. * (i.e. for Xp, a connection has been set up)
  1464. *
  1465. * DtPRINT_FAILURE
  1466. * if the printer could not be established
  1467. *
  1468. * DtPRINT_BAD_PARM
  1469. * if any passed parameter is invalid
  1470. *
  1471. */
  1472. static XtEnum
  1473. EstablishPrinter(
  1474. DtPrintSetupBoxWidget psub,
  1475. DtPrintSetupData* psd)
  1476. {
  1477. switch(PSUB_VerifyPrinterState(psub))
  1478. {
  1479. case DtPRINT_NOT_VERIFIED:
  1480. /*
  1481. * if there's a printer connection timer waiting, remove it
  1482. * to avoid conflict
  1483. */
  1484. if(PSUB_TimeoutId(psub) != (XtIntervalId)NULL)
  1485. {
  1486. XtRemoveTimeOut(PSUB_TimeoutId(psub));
  1487. PSUB_TimeoutId(psub) = (XtIntervalId)NULL;
  1488. }
  1489. /*
  1490. * call the verify printer proc for the new printer
  1491. */
  1492. if(PSUB_VerifyPrinterProc(psub) != NULL)
  1493. {
  1494. int status;
  1495. psd->printer_name = PSUB_PrinterName(psub);
  1496. PSUB_VerifyPrinterState(psub) = DtPRINT_IN_VERIFY;
  1497. status = (*PSUB_VerifyPrinterProc(psub))((Widget)psub, psd);
  1498. if(status != DtPRINT_SUCCESS)
  1499. {
  1500. /*
  1501. * the printer isn't valid - set the verify printer state
  1502. * back to "not verified" and return
  1503. */
  1504. PSUB_VerifyPrinterState(psub) = DtPRINT_NOT_VERIFIED;
  1505. return status;
  1506. }
  1507. PSUB_VerifyPrinterState(psub) = DtPRINT_VERIFIED;
  1508. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP)
  1509. {
  1510. /*
  1511. * set the new display and context in the widget
  1512. */
  1513. PSUB_Display(psub) = psd->print_display;
  1514. #if 0 && defined(PRINTING_SUPPORTED)
  1515. PSUB_Context(psub) = psd->print_context;
  1516. #endif /* PRINTING_SUPPORTED */
  1517. /*
  1518. * initialize the display for use with Xt
  1519. */
  1520. {
  1521. String *argv = NULL, *argv_copy;
  1522. int argc = 0, i;
  1523. String video_name, video_class;
  1524. Widget video_widget = (Widget)psub;
  1525. XtAppContext app_context;
  1526. /*
  1527. * get to the video app root shell
  1528. */
  1529. while((Widget)NULL != video_widget)
  1530. {
  1531. if(XtIsApplicationShell(video_widget))
  1532. break;
  1533. else
  1534. video_widget = XtParent(video_widget);
  1535. }
  1536. if((Widget)NULL == video_widget)
  1537. video_widget = (Widget)psub;
  1538. /*
  1539. * if not an applicationShell, argc/argv will stay
  1540. * NULL in the GetValues call, no need to check
  1541. * explicitly
  1542. */
  1543. XtVaGetValues(video_widget,
  1544. XmNargc, &argc, XmNargv, &argv,
  1545. NULL);
  1546. /* copy argv, modified by XtDisplayInitialize below */
  1547. argv_copy =
  1548. (String *) XtMalloc(sizeof(String) * (argc + 1));
  1549. for (i = 0; i < argc; i++) {
  1550. argv_copy[i] = argv[i];
  1551. }
  1552. argv_copy[argc] = NULL;
  1553. /*
  1554. * now add the print display in our app context, so
  1555. * that event dispatching works
  1556. */
  1557. XtGetApplicationNameAndClass(XtDisplay(video_widget),
  1558. &video_name, &video_class);
  1559. app_context = XtWidgetToApplicationContext(video_widget);
  1560. XtDisplayInitialize(app_context,
  1561. PSUB_Display(psub),
  1562. video_name, video_class,
  1563. PSUB_Options(psub),
  1564. PSUB_OptionCount(psub),
  1565. &argc, argv_copy);
  1566. XtFree((char *) argv_copy);
  1567. }
  1568. /*
  1569. * pick up attributes for the new printer
  1570. */
  1571. GetPrintAttributes(psub);
  1572. }
  1573. }
  1574. else
  1575. {
  1576. PSUB_VerifyPrinterState(psub) = DtPRINT_VERIFIED;
  1577. }
  1578. /*
  1579. * no break
  1580. */
  1581. case DtPRINT_VERIFIED:
  1582. /*
  1583. * fill out current printer info in setup data
  1584. */
  1585. psd->printer_name = PSUB_PrinterName(psub);
  1586. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP)
  1587. {
  1588. psd->print_display = PSUB_Display(psub);
  1589. #if 0 && defined(PRINTING_SUPPORTED)
  1590. psd->print_context = PSUB_Context(psub);
  1591. #endif /* PRINTING_SUPPORTED */
  1592. }
  1593. break;
  1594. case DtPRINT_IN_VERIFY:
  1595. /*
  1596. * EstablishPrinter should not be called recursively
  1597. */
  1598. return DtPRINT_BAD_PARM;
  1599. break;
  1600. }
  1601. return DtPRINT_SUCCESS;
  1602. }
  1603. /*
  1604. * ------------------------------------------------------------------------
  1605. * Name: GetPrintAttributes
  1606. *
  1607. * Description:
  1608. *
  1609. * Get printing attributes relevant to the PrintSetupBox from the
  1610. * current print context.
  1611. *
  1612. * Return value:
  1613. *
  1614. * None.
  1615. *
  1616. */
  1617. static void
  1618. GetPrintAttributes(
  1619. DtPrintSetupBoxWidget psub)
  1620. {
  1621. #if 0 && defined(PRINTING_SUPPORTED)
  1622. char* attr_value;
  1623. XTextProperty text_prop;
  1624. char** list;
  1625. int count;
  1626. XmString description = (XmString)NULL;
  1627. char* ptr;
  1628. /*
  1629. * get the printer description, and set the description field
  1630. */
  1631. attr_value = XpGetOneAttribute(PSUB_Display(psub),
  1632. PSUB_Context(psub),
  1633. XPPrinterAttr,
  1634. XpATTR_DESCRIPTOR);
  1635. if(attr_value != (char*)NULL)
  1636. {
  1637. /*
  1638. * convert the description from COMPOUND_TEXT into the
  1639. * codeset of the current locale
  1640. */
  1641. text_prop.value = (unsigned char*)attr_value;
  1642. text_prop.encoding =
  1643. XInternAtom(XtDisplay((Widget)psub), "COMPOUND_TEXT", False);
  1644. text_prop.format = 8;
  1645. text_prop.nitems = strlen((char*)text_prop.value);
  1646. if(Success ==
  1647. XmbTextPropertyToTextList(XtDisplay((Widget)psub),
  1648. &text_prop, &list, &count))
  1649. {
  1650. if(count > 0)
  1651. {
  1652. if((String)NULL != list[0] && '\0' != *(list[0]))
  1653. {
  1654. /*
  1655. * chop the description after the 1st line
  1656. */
  1657. char* ptr = Dt_strchr(list[0], '\n');
  1658. if((char*)NULL != ptr)
  1659. *ptr = '\0';
  1660. }
  1661. description =
  1662. XmStringGenerate((XtPointer)list[0], (XmStringTag)NULL,
  1663. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  1664. }
  1665. XFreeStringList(list);
  1666. }
  1667. else
  1668. {
  1669. XmeWarning((Widget)psub, WARN_CT_CONVERSION);
  1670. }
  1671. XFree(attr_value);
  1672. }
  1673. /*
  1674. * update the printer description
  1675. */
  1676. if((XmString)NULL == description)
  1677. description = XmStringGenerate((XtPointer)"", (XmStringTag)NULL,
  1678. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  1679. UpdateString(PSUB_Description(psub),
  1680. description,
  1681. PSUB_StringDirection(psub));
  1682. XmStringFree(description);
  1683. /*
  1684. * determine if copy-count is supported
  1685. */
  1686. PSUB_CopyCountSupported(psub) = False;
  1687. attr_value = XpGetOneAttribute(PSUB_Display(psub), PSUB_Context(psub),
  1688. XPPrinterAttr, XpATTR_DOC_ATTRS_SUPPORTED);
  1689. if(attr_value != (char*)NULL)
  1690. {
  1691. int token_len;
  1692. for(ptr = attr_value + SpanWhitespace(attr_value);
  1693. *ptr != '\0';
  1694. ptr += SpanWhitespace(ptr+=token_len))
  1695. {
  1696. token_len = SpanNonWhitespace(ptr);
  1697. if(0 == strncmp(ptr, XpATTR_COPY_COUNT, token_len))
  1698. {
  1699. PSUB_CopyCountSupported(psub) = True;
  1700. break;
  1701. }
  1702. }
  1703. XFree(attr_value);
  1704. }
  1705. if(!PSUB_CopyCountSupported(psub))
  1706. {
  1707. /*
  1708. * copy-count not supported; disable the copies control
  1709. */
  1710. if(PSUB_CopiesSpinBox(psub))
  1711. XtSetSensitive(PSUB_CopiesSpinBox(psub), False);
  1712. if(PSUB_CopiesControl(psub))
  1713. {
  1714. Widget copies_label =
  1715. XtNameToWidget(PSUB_CopiesControl(psub), "CopiesLabel");
  1716. XtSetSensitive(copies_label, False);
  1717. }
  1718. }
  1719. #endif /* PRINTING_SUPPORTED */
  1720. }
  1721. /*
  1722. * ------------------------------------------------------------------------
  1723. * Name: Initialize - Core class method
  1724. *
  1725. * Description:
  1726. *
  1727. * Create a PrintSetupBox widget instance.
  1728. *
  1729. * Return value:
  1730. *
  1731. * None.
  1732. *
  1733. */
  1734. static void
  1735. Initialize(
  1736. Widget rw,
  1737. Widget nw,
  1738. ArgList args,
  1739. Cardinal *num_args)
  1740. {
  1741. DtPrintSetupBoxWidget new_w = (DtPrintSetupBoxWidget) nw ;
  1742. /*
  1743. * Validate the Print Setup Mode
  1744. */
  1745. ValidatePrintSetupMode(new_w, (DtPrintSetupBoxWidget)NULL);
  1746. /*
  1747. * set the Xp-mode default resource procedure if the resource is
  1748. * unspecified
  1749. */
  1750. if(PSUB_PrintSetupMode(new_w) == DtPRINT_SETUP_XP)
  1751. {
  1752. if(PSUB_PrinterInfoProc(new_w) == (DtPrintSetupProc)DtUNSPECIFIED)
  1753. PSUB_PrinterInfoProc(new_w) = _DtPrintSetupBoxXPrinterInfoProc;
  1754. if(PSUB_SelectPrinterProc(new_w) == (DtPrintSetupProc)DtUNSPECIFIED)
  1755. PSUB_SelectPrinterProc(new_w) = _DtPrintSetupBoxSelectXPrinterProc;
  1756. if(PSUB_VerifyPrinterProc(new_w) == (DtPrintSetupProc)DtUNSPECIFIED)
  1757. PSUB_VerifyPrinterProc(new_w) = _DtPrintSetupBoxVerifyXPrinterProc;
  1758. }
  1759. else
  1760. {
  1761. /*
  1762. * for the plain setup mode, unspecified procedure resources
  1763. * default to NULL
  1764. */
  1765. if(PSUB_PrinterInfoProc(new_w) == (DtPrintSetupProc)DtUNSPECIFIED)
  1766. PSUB_PrinterInfoProc(new_w) = (DtPrintSetupProc)NULL;
  1767. if(PSUB_SelectPrinterProc(new_w) == (DtPrintSetupProc)DtUNSPECIFIED)
  1768. PSUB_SelectPrinterProc(new_w) = (DtPrintSetupProc)NULL;
  1769. if(PSUB_VerifyPrinterProc(new_w) == (DtPrintSetupProc)DtUNSPECIFIED)
  1770. PSUB_VerifyPrinterProc(new_w) = (DtPrintSetupProc)NULL;
  1771. }
  1772. /*
  1773. * initialize internal flags
  1774. */
  1775. PSUB_VerifyPrinterState(new_w) = DtPRINT_NOT_VERIFIED;
  1776. PSUB_CopyCountSupported(new_w) = True;
  1777. /*
  1778. * initialize internal data
  1779. */
  1780. PSUB_ModalPrinterSpec(new_w) = (String)NULL;
  1781. PSUB_Display(new_w) = (Display*)NULL;
  1782. #if 0 && defined(PRINTING_SUPPORTED)
  1783. PSUB_Context(new_w) = (XPContext)NULL;
  1784. #endif /* PRINTING_SUPPORTED */
  1785. PSUB_TimeoutId(new_w) = (XtIntervalId)NULL;
  1786. /*
  1787. * retrieve the XpPrinterNameMode application resource for this
  1788. * widget
  1789. */
  1790. {
  1791. XtResource res_struct;
  1792. res_struct.resource_name = "xpPrinterNameMode";
  1793. res_struct.resource_class = "XpPrinterNameMode";
  1794. res_struct.resource_type = XmREnum;
  1795. res_struct.resource_size = sizeof(XtEnum);
  1796. res_struct.resource_offset = 0;
  1797. res_struct.default_type = XmRImmediate;
  1798. res_struct.default_addr = (XtPointer)DtSHORT_NAME;
  1799. XtGetApplicationResources(nw,
  1800. (XtPointer)&PSUB_XpPrinterNameMode(new_w),
  1801. &res_struct, 1, (ArgList)NULL, 0);
  1802. }
  1803. /*
  1804. * Initialize work area children variables
  1805. */
  1806. PSUB_TopWorkArea(new_w) = (Widget)NULL;
  1807. PSUB_BottomWorkArea(new_w) = (Widget)NULL;
  1808. ValidateWorkAreaLocation(new_w, (DtPrintSetupBoxWidget)NULL);
  1809. /*
  1810. * Initialize default resource procedures private data
  1811. */
  1812. _DtPrintDefProcInitialize((Widget)new_w);
  1813. /*
  1814. * Create child widgets.
  1815. */
  1816. PSUB_AddingSelWidgets(new_w) = True;
  1817. _DtPrintSetupBoxCreateTopSeparator(new_w);
  1818. _DtPrintSetupBoxCreateDescriptionLabel(new_w);
  1819. _DtPrintSetupBoxCreateDescription(new_w);
  1820. _DtPrintSetupBoxCreatePrinterInfoButton (new_w);
  1821. _DtPrintSetupBoxCreatePrinterNameLabel(new_w);
  1822. _DtPrintSetupBoxCreatePrinterNameCombo(new_w);
  1823. _DtPrintSetupBoxCreateSelectPrinterButton(new_w);
  1824. _DtPrintSetupBoxCreateFileNameLabel(new_w);
  1825. _DtPrintSetupBoxCreateFileNameText(new_w);
  1826. _DtPrintSetupBoxCreateSelectFileButton(new_w);
  1827. _DtPrintSetupBoxCreateDestinationRadioBox(new_w);
  1828. _DtPrintSetupBoxCreateCopiesControl(new_w);
  1829. _DtPrintSetupBoxCreateBottomSeparator(new_w);
  1830. _DtPrintSetupBoxCreateButtonSeparator (new_w);
  1831. _DtPrintSetupBoxCreatePrintButton (new_w);
  1832. _DtPrintSetupBoxCreateSetupButton (new_w);
  1833. _DtPrintSetupBoxCreateCancelButton (new_w);
  1834. _DtPrintSetupBoxCreateHelpButton (new_w);
  1835. /*
  1836. * Validate/update copies spin box
  1837. */
  1838. SynthSetCopies(new_w, (DtPrintSetupBoxWidget)NULL);
  1839. /*
  1840. * Update Printer Description
  1841. */
  1842. if((XmString)NULL != PSUB_DescriptionString(new_w))
  1843. {
  1844. UpdateString(PSUB_Description(new_w),
  1845. PSUB_DescriptionString(new_w),
  1846. PSUB_StringDirection(new_w));
  1847. PSUB_DescriptionString(new_w) = NULL ;
  1848. }
  1849. /*
  1850. * Initialize printer information
  1851. */
  1852. SynthSetPrinterName(new_w,
  1853. XtNewString(PSUB_PrinterName(new_w)),
  1854. (String)NULL);
  1855. /*
  1856. * Validate print destination / update print to file checkbox
  1857. */
  1858. SynthSetPrintDestination(new_w, (DtPrintSetupBoxWidget)NULL);
  1859. /*
  1860. * Update the file name text box
  1861. */
  1862. SynthSetFileName(new_w, (DtPrintSetupBoxWidget)NULL);
  1863. /*
  1864. * specify the Print button as the default button
  1865. */
  1866. BB_DefaultButton(new_w) = PSUB_PrintButton(new_w) ;
  1867. _XmBulletinBoardSetDynDefaultButton((Widget) new_w,
  1868. BB_DefaultButton(new_w)) ;
  1869. PSUB_AddingSelWidgets(new_w) = False;
  1870. XtManageChildren (new_w->composite.children,
  1871. new_w->composite.num_children) ;
  1872. }
  1873. /*
  1874. * ------------------------------------------------------------------------
  1875. * Name: InsertChild - Composite class method
  1876. *
  1877. * Description:
  1878. *
  1879. * The Print Setup widget supports up to TWO work area children. This
  1880. * routine handles adding a child to the Print Setup widget.
  1881. *
  1882. * Return value:
  1883. *
  1884. * None.
  1885. *
  1886. */
  1887. static void
  1888. InsertChild(
  1889. Widget child)
  1890. {
  1891. DtPrintSetupBoxWidget psub ;
  1892. XtWidgetProc insert_child;
  1893. /*
  1894. * Use the dialog class insert proc to do all the dirty work
  1895. */
  1896. _DtPrintProcessLock();
  1897. insert_child = ((XmBulletinBoardWidgetClass)xmBulletinBoardWidgetClass)
  1898. ->composite_class.insert_child;
  1899. _DtPrintProcessUnlock();
  1900. (*insert_child)(child) ;
  1901. if(!XtIsRectObj(child))
  1902. {
  1903. return ;
  1904. }
  1905. psub = (DtPrintSetupBoxWidget) XtParent(child) ;
  1906. /*
  1907. * check if this child is to be the one of the work areas
  1908. */
  1909. if(!PSUB_AddingSelWidgets(psub)
  1910. && !(XmIsRowColumn(child)
  1911. && ((XmRowColumnWidget)child)->row_column.type == XmMENU_BAR
  1912. )
  1913. && !XtIsShell(child)
  1914. && !IsButton(child))
  1915. {
  1916. if(PSUB_TopWorkArea(psub) == (Widget)NULL
  1917. &&
  1918. (PSUB_WorkAreaLocation(psub) == DtWORK_AREA_TOP
  1919. ||
  1920. PSUB_WorkAreaLocation(psub) == DtWORK_AREA_TOP_AND_BOTTOM)
  1921. )
  1922. {
  1923. PSUB_TopWorkArea(psub) = child;
  1924. }
  1925. else if(PSUB_BottomWorkArea(psub) == (Widget)NULL
  1926. &&
  1927. (PSUB_WorkAreaLocation(psub) == DtWORK_AREA_BOTTOM
  1928. ||
  1929. PSUB_WorkAreaLocation(psub) == DtWORK_AREA_TOP_AND_BOTTOM)
  1930. )
  1931. {
  1932. PSUB_BottomWorkArea(psub) = child;
  1933. }
  1934. }
  1935. }
  1936. static Boolean
  1937. IsSetupRequired(
  1938. DtPrintSetupBoxWidget psub)
  1939. {
  1940. #if 0 && defined(PRINTING_SUPPORTED)
  1941. char* setup_proviso;
  1942. #endif /* PRINTING_SUPPORTED */
  1943. Boolean required = False;
  1944. #if 0 && defined(PRINTING_SUPPORTED)
  1945. setup_proviso = XpGetOneAttribute(PSUB_Display(psub),
  1946. PSUB_Context(psub),
  1947. XPPrinterAttr,
  1948. XpATTR_SETUP_PROVISO);
  1949. if((char*)NULL != setup_proviso)
  1950. {
  1951. char* ptr;
  1952. int token_len;
  1953. ptr = setup_proviso + SpanWhitespace(setup_proviso);
  1954. token_len = SpanNonWhitespace(ptr);
  1955. if(token_len && 0 == strncmp(ptr, "xp-setup-mandatory", token_len))
  1956. {
  1957. char* setup_state;
  1958. /*
  1959. * setup is mandatory; check to see if it has been performed
  1960. */
  1961. setup_state = XpGetOneAttribute(PSUB_Display(psub),
  1962. PSUB_Context(psub),
  1963. XPJobAttr,
  1964. XpATTR_SETUP_STATE);
  1965. if((char*)NULL == setup_state)
  1966. required = True;
  1967. else
  1968. {
  1969. ptr = setup_state + SpanWhitespace(setup_state);
  1970. token_len = SpanNonWhitespace(ptr);
  1971. if(token_len)
  1972. {
  1973. /*
  1974. * if the value of the setup state attribute is
  1975. * xp-setup-ok then setup is not required
  1976. */
  1977. if(0 != strncmp(ptr, "xp-setup-ok", token_len))
  1978. required = True;
  1979. }
  1980. else
  1981. required = True;
  1982. XFree(setup_state);
  1983. }
  1984. }
  1985. XFree(setup_proviso);
  1986. }
  1987. #endif /* PRINTING_SUPPORTED */
  1988. return required;
  1989. }
  1990. /*
  1991. * ------------------------------------------------------------------------
  1992. * Name: MenuBarFixUp
  1993. *
  1994. * Description:
  1995. *
  1996. * This routine is a fixup routine which can be used for rows which
  1997. * consist of a single MenuBar RowColumn. The effect of this routine
  1998. * is to have the RowColumn ignore the margin width and height.
  1999. *
  2000. * Return value:
  2001. *
  2002. * None.
  2003. *
  2004. */
  2005. static void
  2006. MenuBarFixUp(
  2007. XmGeoMatrix geoSpec,
  2008. int action,
  2009. XmGeoMajorLayout layoutPtr,
  2010. XmKidGeometry rowPtr)
  2011. {
  2012. Dimension marginW ;
  2013. Dimension marginH ;
  2014. Dimension twoMarginW ;
  2015. marginW = geoSpec->margin_w ;
  2016. twoMarginW = (marginW << 1) ;
  2017. marginH = geoSpec->margin_h ;
  2018. switch( action )
  2019. {
  2020. case XmGEO_PRE_SET:
  2021. {
  2022. rowPtr->box.x -= marginW ;
  2023. rowPtr->box.width += twoMarginW ;
  2024. rowPtr->box.y -= marginH ;
  2025. break ;
  2026. }
  2027. default:
  2028. {
  2029. if( rowPtr->box.width > twoMarginW )
  2030. {
  2031. /*
  2032. * Avoid subtracting a margin from box width which would
  2033. * result in underflow.
  2034. */
  2035. rowPtr->box.x += marginW ;
  2036. rowPtr->box.width -= twoMarginW ;
  2037. }
  2038. if( action == XmGET_PREFERRED_SIZE )
  2039. {
  2040. /*
  2041. * Set width to some small value so it does not effect
  2042. * total width of matrix.
  2043. */
  2044. rowPtr->box.width = 1 ;
  2045. }
  2046. break ;
  2047. }
  2048. }
  2049. }
  2050. /*
  2051. * ------------------------------------------------------------------------
  2052. * Name: PrintSetupBoxCallback
  2053. *
  2054. * Description:
  2055. *
  2056. * Call the callbacks for a PrintSetupBox button.
  2057. *
  2058. * Return value:
  2059. *
  2060. * None.
  2061. *
  2062. */
  2063. static void
  2064. PrintSetupBoxCallback(
  2065. Widget w,
  2066. XtPointer client_data,
  2067. XtPointer call_data)
  2068. {
  2069. DtPrintSetupBoxChild which_button = (DtPrintSetupBoxChild)client_data;
  2070. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)XtParent(w);
  2071. XmAnyCallbackStruct* callback = (XmAnyCallbackStruct*)call_data;
  2072. DtPrintSetupCallbackStruct cbs;
  2073. DtPrintSetupData psd;
  2074. memset(&cbs, 0, sizeof(DtPrintSetupCallbackStruct));
  2075. memset(&psd, 0, sizeof(DtPrintSetupData));
  2076. cbs.print_data = &psd;
  2077. cbs.event = callback->event;
  2078. /*
  2079. * we want to see any error messages that may pop up when
  2080. * establishing the printer connection
  2081. */
  2082. psd.messages_hint = DtPRINT_HINT_MESSAGES_OK;
  2083. switch(which_button)
  2084. {
  2085. case DtPRINT_CANCEL_BUTTON:
  2086. cbs.reason = DtPRINT_CR_CANCEL;
  2087. XtCallCallbackList((Widget)psub,
  2088. PSUB_CancelCallback(psub),
  2089. (XtPointer)&cbs);
  2090. break;
  2091. case DtPRINT_FILES_BUTTON:
  2092. if(PSUB_SelectFileProc(psub))
  2093. {
  2094. /*
  2095. * setup the destination info
  2096. */
  2097. SetPSDDestination(psub, &psd);
  2098. /*
  2099. * call select file proc
  2100. */
  2101. (*PSUB_SelectFileProc(psub))((Widget)psub, &psd);
  2102. }
  2103. break;
  2104. case DtPRINT_HELP_BUTTON:
  2105. /*
  2106. * Invoke the help system.
  2107. */
  2108. _XmManagerHelp((Widget)psub, callback->event, NULL, NULL) ;
  2109. break;
  2110. case DtPRINT_INFO_BUTTON:
  2111. if(PSUB_PrinterInfoProc(psub))
  2112. {
  2113. /*
  2114. * pick up the printer name from the widget's Printer Name text
  2115. * field
  2116. */
  2117. SynthGetPrinterName(psub);
  2118. /*
  2119. * establish a connection to the X printer
  2120. */
  2121. if(EstablishPrinter(psub, &psd) == DtPRINT_SUCCESS)
  2122. {
  2123. /*
  2124. * For X printing, set printing attributes
  2125. */
  2126. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP)
  2127. {
  2128. SetPrintAttributes(psub);
  2129. }
  2130. /*
  2131. * call printer info proc
  2132. */
  2133. (*PSUB_PrinterInfoProc(psub))((Widget)psub, &psd);
  2134. }
  2135. }
  2136. break;
  2137. case DtPRINT_PRINT_BUTTON:
  2138. /*
  2139. * pick up the printer name from the widget's Printer Name text
  2140. * field
  2141. */
  2142. SynthGetPrinterName(psub);
  2143. /*
  2144. * establish a connection to the X printer
  2145. */
  2146. if(EstablishPrinter(psub, &psd) == DtPRINT_SUCCESS)
  2147. {
  2148. /*
  2149. * For X printing, set printing attributes
  2150. */
  2151. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP)
  2152. {
  2153. SetPrintAttributes(psub);
  2154. }
  2155. /*
  2156. * setup the destination info
  2157. */
  2158. SetPSDDestination(psub, &psd);
  2159. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP
  2160. &&
  2161. IsSetupRequired(psub))
  2162. {
  2163. /*
  2164. * setup is needed; call the setup callback instead
  2165. */
  2166. cbs.reason = DtPRINT_CR_SETUP;
  2167. XtCallCallbackList((Widget)psub,
  2168. PSUB_SetupCallback(psub),
  2169. (XtPointer)&cbs);
  2170. }
  2171. else
  2172. {
  2173. /*
  2174. * The printer name is OK. Go ahead and unmanage the print
  2175. * setup box if the auto-unmanage resource is set.
  2176. */
  2177. if(PSUB_AutoUnmanage(psub) && PSUB_Shell(psub))
  2178. XtUnmanageChild((Widget)psub);
  2179. /*
  2180. * call the Print callback list
  2181. */
  2182. cbs.reason = DtPRINT_CR_PRINT;
  2183. XtCallCallbackList((Widget)psub,
  2184. PSUB_PrintCallback(psub),
  2185. (XtPointer)&cbs);
  2186. }
  2187. }
  2188. break;
  2189. case DtPRINT_PRINTERS_BUTTON:
  2190. if(PSUB_SelectPrinterProc(psub))
  2191. {
  2192. /*
  2193. * call the printer selection proc
  2194. */
  2195. psd.printer_name = PSUB_PrinterName(psub);
  2196. (*PSUB_SelectPrinterProc(psub))((Widget)psub, &psd);
  2197. }
  2198. break;
  2199. case DtPRINT_SETUP_BUTTON:
  2200. /*
  2201. * pick up the printer name from the widget's Printer Name text
  2202. * field
  2203. */
  2204. SynthGetPrinterName(psub);
  2205. /*
  2206. * establish a connection to the X printer
  2207. */
  2208. if(EstablishPrinter(psub, &psd) == DtPRINT_SUCCESS)
  2209. {
  2210. /*
  2211. * For X printing, set printing attributes
  2212. */
  2213. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP)
  2214. {
  2215. SetPrintAttributes(psub);
  2216. }
  2217. /*
  2218. * setup the destination info
  2219. */
  2220. SetPSDDestination(psub, &psd);
  2221. /*
  2222. * Call setup callback
  2223. */
  2224. cbs.reason = DtPRINT_CR_SETUP;
  2225. XtCallCallbackList((Widget)psub,
  2226. PSUB_SetupCallback(psub),
  2227. (XtPointer)&cbs);
  2228. }
  2229. break;
  2230. }
  2231. }
  2232. /*
  2233. * ------------------------------------------------------------------------
  2234. * Name: SeparatorFixUp
  2235. *
  2236. * Description:
  2237. *
  2238. * This routine is a fixup routine which can be used for rows which
  2239. * consist of a single separator widget. The effect of this routine
  2240. * is to have the separator ignore the margin width.
  2241. *
  2242. * Return value:
  2243. *
  2244. * None.
  2245. *
  2246. */
  2247. static void
  2248. SeparatorFixUp(
  2249. XmGeoMatrix geoSpec,
  2250. int action,
  2251. XmGeoMajorLayout layoutPtr,
  2252. XmKidGeometry rowPtr )
  2253. {
  2254. Dimension marginW ;
  2255. Dimension twoMarginW ;
  2256. marginW = geoSpec->margin_w ;
  2257. twoMarginW = (marginW << 1) ;
  2258. switch( action )
  2259. {
  2260. case XmGEO_PRE_SET:
  2261. {
  2262. rowPtr->box.x -= marginW ;
  2263. rowPtr->box.width += twoMarginW ;
  2264. break ;
  2265. }
  2266. default:
  2267. {
  2268. if( rowPtr->box.width > twoMarginW )
  2269. {
  2270. /*
  2271. * Avoid subtracting a margin from box width which would
  2272. * result in underflow.
  2273. */
  2274. rowPtr->box.x += marginW ;
  2275. rowPtr->box.width -= twoMarginW ;
  2276. }
  2277. if( action == XmGET_PREFERRED_SIZE )
  2278. {
  2279. /*
  2280. * Set width to some small value so it does not
  2281. * effect total width of matrix.
  2282. */
  2283. rowPtr->box.width = 1 ;
  2284. }
  2285. break ;
  2286. }
  2287. }
  2288. }
  2289. /*
  2290. * ------------------------------------------------------------------------
  2291. * Name: SetNewPrinterName
  2292. *
  2293. * Description:
  2294. *
  2295. * For Xp, if there is an existing open Xp connection, the
  2296. * connection is closed, and the DtNclosePrintDisplayCallback list is
  2297. * called using old_printer_name.
  2298. *
  2299. * old_printer_name is then freed using XtFree.
  2300. *
  2301. * The printer_name instance variable is set to new_printer_name
  2302. * which must point to memory previously allocated using one of the
  2303. * Xt memory allocation functions.
  2304. *
  2305. * This function unsets the printer name verified flag.
  2306. *
  2307. * Return value:
  2308. *
  2309. * None.
  2310. *
  2311. */
  2312. static void
  2313. SetNewPrinterName(
  2314. DtPrintSetupBoxWidget psub,
  2315. String new_printer_name,
  2316. String old_printer_name)
  2317. {
  2318. /*
  2319. * close the existing Xp connection
  2320. */
  2321. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP
  2322. &&
  2323. PSUB_Display(psub) != (Display*)NULL)
  2324. {
  2325. ClosePrintConnection(psub, old_printer_name, True);
  2326. }
  2327. /*
  2328. * free the old printer name
  2329. */
  2330. XtFree(old_printer_name);
  2331. /*
  2332. * update the printer name instance data
  2333. */
  2334. PSUB_PrinterName(psub) = new_printer_name;
  2335. /*
  2336. * ensure the new printer name will be verified
  2337. */
  2338. if(PSUB_VerifyPrinterState(psub) == DtPRINT_VERIFIED)
  2339. PSUB_VerifyPrinterState(psub) = DtPRINT_NOT_VERIFIED;
  2340. }
  2341. /*
  2342. * ------------------------------------------------------------------------
  2343. * Name: SetPrintAttributes
  2344. *
  2345. * Description:
  2346. *
  2347. * Set printing attributes relevant to the PrintSetupBox into the
  2348. * current print context.
  2349. *
  2350. * Return value:
  2351. *
  2352. * None.
  2353. *
  2354. */
  2355. static void
  2356. SetPrintAttributes(
  2357. DtPrintSetupBoxWidget psub)
  2358. {
  2359. /*
  2360. * Set the copy-count document attribute in the current context
  2361. */
  2362. if((Widget)NULL != PSUB_CopiesSpinBox(psub))
  2363. {
  2364. char str[48];
  2365. XtVaGetValues(PSUB_CopiesSpinBox(psub),
  2366. XmNposition, &PSUB_Copies(psub),
  2367. NULL);
  2368. sprintf(str, "*%s: %d\n", XpATTR_COPY_COUNT, PSUB_Copies(psub));
  2369. #if 0 && defined(PRINTING_SUPPORTED)
  2370. XpSetAttributes(PSUB_Display(psub), PSUB_Context(psub),
  2371. XPDocAttr, str, XPAttrMerge);
  2372. #endif /* PRINTING_SUPPORTED */
  2373. }
  2374. }
  2375. /*
  2376. * ------------------------------------------------------------------------
  2377. * Name: SetPSDDestination
  2378. *
  2379. * Description:
  2380. *
  2381. * Set print destination information in the passed setup data
  2382. * struct for use in callbacks.
  2383. *
  2384. * Return value:
  2385. *
  2386. * None.
  2387. *
  2388. */
  2389. static void SetPSDDestination(
  2390. DtPrintSetupBoxWidget psub,
  2391. DtPrintSetupData* psd)
  2392. {
  2393. psd->destination = PSUB_PrintDestination(psub);
  2394. switch(PSUB_PrintDestination(psub))
  2395. {
  2396. case DtPRINT_TO_PRINTER:
  2397. psd->dest_info = PSUB_ModalPrinterSpec(psub);
  2398. break;
  2399. case DtPRINT_TO_FILE:
  2400. SynthGetFileName(psub);
  2401. psd->dest_info = PSUB_FileName(psub);
  2402. break;
  2403. }
  2404. }
  2405. /*
  2406. * ------------------------------------------------------------------------
  2407. * Name: SetSyntheticResForChild
  2408. *
  2409. * Description:
  2410. *
  2411. * Indicate to the synthetic resource mechanism that it should copy
  2412. * the resource value.
  2413. *
  2414. * Return value:
  2415. *
  2416. * Always XmSYNTHETIC_LOAD.
  2417. *
  2418. */
  2419. static XmImportOperator
  2420. SetSyntheticResForChild(
  2421. Widget widget,
  2422. int offset,
  2423. XtArgVal *value)
  2424. {
  2425. return XmSYNTHETIC_LOAD;
  2426. }
  2427. /*
  2428. * ------------------------------------------------------------------------
  2429. * Name: SetValues - Core class method
  2430. *
  2431. * Description:
  2432. *
  2433. * Update widget when values change.
  2434. *
  2435. * Return value:
  2436. *
  2437. * Always False, because this widget will redraw itself.
  2438. *
  2439. */
  2440. static Boolean
  2441. SetValues(
  2442. Widget cw,
  2443. Widget rw,
  2444. Widget nw,
  2445. ArgList args,
  2446. Cardinal *num_args)
  2447. {
  2448. DtPrintSetupBoxWidget current = (DtPrintSetupBoxWidget) cw ;
  2449. DtPrintSetupBoxWidget new_w = (DtPrintSetupBoxWidget) nw ;
  2450. Boolean need_layout = False;
  2451. BB_InSetValues(new_w) = True;
  2452. /*
  2453. * Validate the Print Setup Mode
  2454. */
  2455. if(PSUB_PrintSetupMode(new_w) != PSUB_PrintSetupMode(current))
  2456. ValidatePrintSetupMode(new_w, current);
  2457. /*
  2458. * Validate work area location
  2459. */
  2460. if(PSUB_WorkAreaLocation(new_w) != PSUB_WorkAreaLocation(current))
  2461. ValidateWorkAreaLocation(new_w, current);
  2462. /*
  2463. * Update Printer Description
  2464. */
  2465. if(PSUB_DescriptionString(new_w) != PSUB_DescriptionString(current))
  2466. {
  2467. UpdateString(PSUB_Description(new_w),
  2468. PSUB_DescriptionString(new_w),
  2469. PSUB_StringDirection(new_w));
  2470. PSUB_DescriptionString(new_w) = NULL ;
  2471. }
  2472. /*
  2473. * Validate print destination / update print to file checkbox
  2474. */
  2475. if(PSUB_PrintDestination(new_w) != PSUB_PrintDestination(current))
  2476. SynthSetPrintDestination(new_w, current);
  2477. /*
  2478. * Update the file name
  2479. */
  2480. if(PSUB_FileName(new_w) != PSUB_FileName(current))
  2481. SynthSetFileName(new_w, current);
  2482. /*
  2483. * Validate/update copies spin box
  2484. */
  2485. if(PSUB_Copies(new_w) != PSUB_Copies(current))
  2486. SynthSetCopies(new_w, current);
  2487. /*
  2488. * Update the Printer Name text field
  2489. */
  2490. if(PSUB_PrinterName(new_w) != PSUB_PrinterName(current))
  2491. {
  2492. if((PSUB_PrinterName(new_w) == NULL
  2493. ||
  2494. PSUB_PrinterName(current) == NULL)
  2495. ? True
  2496. : strcmp(PSUB_PrinterName(new_w), PSUB_PrinterName(current)) != 0)
  2497. {
  2498. /*
  2499. * the printer names are different; set the new printer name
  2500. * into the instance structure and the printer name text
  2501. * field
  2502. */
  2503. SynthSetPrinterName(new_w,
  2504. XtNewString(PSUB_PrinterName(new_w)),
  2505. PSUB_PrinterName(current));
  2506. }
  2507. else
  2508. {
  2509. /*
  2510. * printer names are identical; keep current
  2511. */
  2512. PSUB_PrinterName(new_w) = PSUB_PrinterName(current);
  2513. }
  2514. }
  2515. if(PSUB_MinimizeButtons(new_w) != PSUB_MinimizeButtons(current))
  2516. {
  2517. need_layout = True;
  2518. }
  2519. /*
  2520. * finished setting values
  2521. */
  2522. BB_InSetValues (new_w) = False;
  2523. /*
  2524. * If this is the instantiated class then do layout.
  2525. */
  2526. if(need_layout && XtClass(new_w) == dtPrintSetupBoxWidgetClass)
  2527. {
  2528. _XmBulletinBoardSizeUpdate((Widget) new_w) ;
  2529. }
  2530. return False;
  2531. }
  2532. /*
  2533. * ------------------------------------------------------------------------
  2534. * Name: SpanNonWhitespace
  2535. *
  2536. * Description:
  2537. *
  2538. * Returns the length of the initial segment of the passed string
  2539. * that consists entirely of non-whitespace characters.
  2540. *
  2541. *
  2542. */
  2543. static int
  2544. SpanNonWhitespace(const char* string)
  2545. {
  2546. const char* ptr;
  2547. for(ptr = string;
  2548. *ptr != '\0' && !DtIsspace((char*)ptr);
  2549. ptr = DtNextChar((char*)ptr));
  2550. return ptr - string;
  2551. }
  2552. /*
  2553. * ------------------------------------------------------------------------
  2554. * Name: SpanWhitespace
  2555. *
  2556. * Description:
  2557. *
  2558. * Returns the length of the initial segment of the passed string
  2559. * that consists entirely of whitespace characters.
  2560. *
  2561. *
  2562. */
  2563. static int
  2564. SpanWhitespace(const char* string)
  2565. {
  2566. const char* ptr;
  2567. for(ptr = string;
  2568. *ptr != '\0' && DtIsspace((char*)ptr);
  2569. ptr = DtNextChar((char*)ptr));
  2570. return ptr - string;
  2571. }
  2572. /*
  2573. * ------------------------------------------------------------------------
  2574. * Name: SynthGetFileName
  2575. *
  2576. * Description:
  2577. *
  2578. * Updates the file_name element of the PrintSetupBox instance
  2579. * structure based on the current state of the File Name text field.
  2580. *
  2581. * Return Value:
  2582. *
  2583. * None.
  2584. *
  2585. */
  2586. static void SynthGetFileName(
  2587. DtPrintSetupBoxWidget psub)
  2588. {
  2589. /*
  2590. * free the existing file name
  2591. */
  2592. XtFree(PSUB_FileName(psub));
  2593. /*
  2594. * set the file name widget instance value based on the File Name
  2595. * text field value
  2596. */
  2597. if(PSUB_FileNameText(psub) != (Widget)NULL)
  2598. XtVaGetValues((Widget)PSUB_FileNameText(psub),
  2599. XmNvalue, &PSUB_FileName(psub),
  2600. NULL);
  2601. else
  2602. PSUB_FileName(psub) = (String)NULL;
  2603. }
  2604. /*
  2605. * ------------------------------------------------------------------------
  2606. * Name: SynthGetPrinterName
  2607. *
  2608. * Description:
  2609. *
  2610. * Updates the modal_printer_spec and the printer_name elements of
  2611. * the PrintSetupBox instance structure based on the current state of
  2612. * the Printer Name text field. The verify printer state will be set
  2613. * to "not verified" if the printer_name is updated.
  2614. *
  2615. * Return Value:
  2616. *
  2617. * None.
  2618. *
  2619. */
  2620. static void
  2621. SynthGetPrinterName(
  2622. DtPrintSetupBoxWidget psub)
  2623. {
  2624. Boolean printer_spec_changed = False;
  2625. String previous_modal_spec;
  2626. if(PSUB_PrinterNameText(psub) != (Widget)NULL)
  2627. {
  2628. /*
  2629. * get the modal Printer Specifier from the Printer Name text
  2630. * field
  2631. */
  2632. previous_modal_spec = PSUB_ModalPrinterSpec(psub);
  2633. XtVaGetValues((Widget)PSUB_PrinterNameText(psub),
  2634. XmNvalue, &PSUB_ModalPrinterSpec(psub),
  2635. NULL);
  2636. /*
  2637. * determine if we have a new printer name
  2638. */
  2639. switch(PSUB_PrintSetupMode(psub))
  2640. {
  2641. case DtPRINT_SETUP_PLAIN:
  2642. if((PSUB_ModalPrinterSpec(psub) == (String)NULL
  2643. ||
  2644. PSUB_PrinterName(psub) == (String)NULL))
  2645. {
  2646. printer_spec_changed = True;
  2647. }
  2648. else if(strcmp(PSUB_ModalPrinterSpec(psub), PSUB_PrinterName(psub))
  2649. != 0)
  2650. {
  2651. printer_spec_changed = True;
  2652. }
  2653. break;
  2654. case DtPRINT_SETUP_XP:
  2655. if(PSUB_PrinterName(psub) == (String)NULL
  2656. ||
  2657. PSUB_ModalPrinterSpec(psub) == (String)NULL
  2658. ||
  2659. (Display*)NULL == PSUB_Display(psub)
  2660. ||
  2661. strcmp(previous_modal_spec, PSUB_ModalPrinterSpec(psub)) != 0)
  2662. {
  2663. printer_spec_changed = True;
  2664. }
  2665. break;
  2666. }
  2667. XtFree(previous_modal_spec);
  2668. }
  2669. if(printer_spec_changed)
  2670. {
  2671. SetNewPrinterName(psub,
  2672. XtNewString(PSUB_ModalPrinterSpec(psub)),/*new name*/
  2673. PSUB_PrinterName(psub)); /* old name */
  2674. }
  2675. }
  2676. /*
  2677. * ------------------------------------------------------------------------
  2678. * Name: SynthSetCopies
  2679. *
  2680. * Description:
  2681. *
  2682. * Validate the DtNcopies resource, and use it to update the Copies
  2683. * spin box.
  2684. *
  2685. * Return value:
  2686. *
  2687. * None.
  2688. *
  2689. */
  2690. static void
  2691. SynthSetCopies(
  2692. DtPrintSetupBoxWidget new_w,
  2693. DtPrintSetupBoxWidget current)
  2694. {
  2695. if(PSUB_Copies(new_w) < 1 || PSUB_Copies(new_w) > MAX_COPIES)
  2696. {
  2697. XmeWarning((Widget)new_w, WARN_COPY_COUNT);
  2698. if(current == (DtPrintSetupBoxWidget)NULL)
  2699. PSUB_Copies(new_w) = 1;
  2700. else
  2701. PSUB_Copies(new_w) = PSUB_Copies(current);
  2702. }
  2703. if(PSUB_CopiesSpinBox(new_w) != (Widget)NULL)
  2704. XtVaSetValues(PSUB_CopiesSpinBox(new_w),
  2705. XmNposition, PSUB_Copies(new_w),
  2706. NULL);
  2707. }
  2708. /*
  2709. * ------------------------------------------------------------------------
  2710. * Name: SynthSetFileName
  2711. *
  2712. * Description:
  2713. *
  2714. * Update the file name text field.
  2715. *
  2716. * Return value:
  2717. *
  2718. * None.
  2719. *
  2720. */
  2721. static void
  2722. SynthSetFileName(
  2723. DtPrintSetupBoxWidget new_w,
  2724. DtPrintSetupBoxWidget current)
  2725. {
  2726. /*
  2727. * free the old file name
  2728. */
  2729. if(current != (DtPrintSetupBoxWidget)NULL)
  2730. {
  2731. XtFree(PSUB_FileName(current));
  2732. }
  2733. /*
  2734. * make a copy of the new file name
  2735. */
  2736. PSUB_FileName(new_w) = XtNewString(PSUB_FileName(new_w));
  2737. /*
  2738. * update the file name text box
  2739. */
  2740. if(PSUB_FileNameText(new_w) != (Widget)NULL)
  2741. {
  2742. XmTextPosition last_position;
  2743. XmTextFieldSetString(PSUB_FileNameText(new_w), PSUB_FileName(new_w));
  2744. last_position = XmTextFieldGetLastPosition(PSUB_FileNameText(new_w));
  2745. XmTextFieldSetInsertionPosition(PSUB_FileNameText(new_w),
  2746. last_position);
  2747. }
  2748. }
  2749. /*
  2750. * ------------------------------------------------------------------------
  2751. * Name: SynthSetPrintDestination
  2752. *
  2753. * Description:
  2754. *
  2755. * Validate the DtNprintDestination resource, and use it to update
  2756. * the print destination radio buttons.
  2757. *
  2758. * Return value:
  2759. *
  2760. * None.
  2761. *
  2762. */
  2763. static void
  2764. SynthSetPrintDestination(
  2765. DtPrintSetupBoxWidget new_w,
  2766. DtPrintSetupBoxWidget current)
  2767. {
  2768. if(PSUB_PrintDestination(new_w) != DtPRINT_TO_PRINTER
  2769. &&
  2770. PSUB_PrintDestination(new_w) != DtPRINT_TO_FILE)
  2771. {
  2772. XmeWarning((Widget)new_w, WARN_PRINT_DESTINATION);
  2773. if(current == (DtPrintSetupBoxWidget)NULL)
  2774. PSUB_PrintDestination(new_w) = DtPRINT_TO_PRINTER;
  2775. else
  2776. PSUB_PrintDestination(new_w) = PSUB_PrintDestination(current);
  2777. }
  2778. if((Widget)NULL != PSUB_DestinationRadioBox(new_w))
  2779. {
  2780. Widget button;
  2781. switch(PSUB_PrintDestination(new_w))
  2782. {
  2783. case DtPRINT_TO_PRINTER:
  2784. button =
  2785. XtNameToWidget(PSUB_DestinationRadioBox(new_w), "button_0");
  2786. XmToggleButtonSetState(button, True, True);
  2787. break;
  2788. case DtPRINT_TO_FILE:
  2789. button =
  2790. XtNameToWidget(PSUB_DestinationRadioBox(new_w), "button_1");
  2791. XmToggleButtonSetState(button, True, True);
  2792. break;
  2793. }
  2794. }
  2795. }
  2796. /*
  2797. * ------------------------------------------------------------------------
  2798. * Name: SynthSetPrinterName
  2799. *
  2800. * Description:
  2801. *
  2802. * Set the passed new_printer_name into the print setup box by
  2803. * updating the Printer Name text field and the modal_printer_name
  2804. * and printer_name instance variables. The verify printer state will
  2805. * be set to DtPRINT_NOT_VERIFIED if the printer_name was updated.
  2806. *
  2807. * new_printer_name must have been previously allocated using one of
  2808. * the Xt memory allocation functions. If the passed new_printer_name
  2809. * is NULL, a default printer name will be used.
  2810. *
  2811. * The old_printer_name is passed to the DtNclosePrintDisplayCallback
  2812. * list, if it is called. The old_printer_name is freed using XtFree.
  2813. *
  2814. * Return value:
  2815. *
  2816. * None.
  2817. *
  2818. */
  2819. static void
  2820. SynthSetPrinterName(
  2821. DtPrintSetupBoxWidget psub,
  2822. String new_printer_name,
  2823. String old_printer_name)
  2824. {
  2825. /*
  2826. * update the printer name in the widget instance structure
  2827. */
  2828. SetNewPrinterName(psub, new_printer_name, old_printer_name);
  2829. /*
  2830. * create a new modal printer name
  2831. */
  2832. XtFree(PSUB_ModalPrinterSpec(psub));
  2833. switch(PSUB_PrintSetupMode(psub))
  2834. {
  2835. case DtPRINT_SETUP_PLAIN:
  2836. /*
  2837. * Ignore the name mode
  2838. */
  2839. PSUB_ModalPrinterSpec(psub) = XtNewString(PSUB_PrinterName(psub));
  2840. break;
  2841. case DtPRINT_SETUP_XP:
  2842. /*
  2843. * Create a modal X Printer Specifier
  2844. */
  2845. PSUB_ModalPrinterSpec(psub) =
  2846. CreateModalPrinterSpec(PSUB_XpPrinterNameMode(psub),
  2847. PSUB_PrinterName(psub));
  2848. break;
  2849. }
  2850. /*
  2851. * Set the modal printer specifier in the Printer Name text field
  2852. */
  2853. if(PSUB_PrinterNameText(psub))
  2854. {
  2855. XtVaSetValues(PSUB_PrinterNameText(psub),
  2856. XmNvalue, PSUB_ModalPrinterSpec(psub),
  2857. NULL);
  2858. XmComboBoxUpdate(PSUB_PrinterNameCombo(psub));
  2859. }
  2860. /*
  2861. * verify the printer; get intial attributes for a new X printer
  2862. * connection
  2863. */
  2864. if(PSUB_VerifyPrinterState(psub) == DtPRINT_NOT_VERIFIED)
  2865. {
  2866. DtPrintSetupData psd;
  2867. Window window;
  2868. memset(&psd, 0, sizeof(DtPrintSetupData));
  2869. /*
  2870. * don't show any messages if this widget isn't mapped
  2871. */
  2872. psd.messages_hint = DtPRINT_HINT_NO_MESSAGES;
  2873. window = XtWindow((Widget)psub);
  2874. if(window)
  2875. {
  2876. XWindowAttributes attr;
  2877. Status status = XGetWindowAttributes(XtDisplay((Widget)psub),
  2878. window, &attr);
  2879. if(status != 0 && attr.map_state == IsViewable)
  2880. psd.messages_hint = DtPRINT_HINT_MESSAGES_OK;
  2881. }
  2882. /*
  2883. * establish a connection to the X printer
  2884. */
  2885. EstablishPrinter(psub, &psd);
  2886. }
  2887. }
  2888. /*
  2889. * ------------------------------------------------------------------------
  2890. * Name: UpdatePrinterNameCallback
  2891. *
  2892. * Description:
  2893. *
  2894. * Kick off a timer proc to establish the selected printer in the
  2895. * widget. This allows the hourglass to be visible while the
  2896. * connection is being established. The hourglass can't be set inside
  2897. * the callback because the combo box list is still popped up with
  2898. * the pointer grabbed... Of course if the user is traversing through
  2899. * the list with the cursor keys, ie. without popping it down,
  2900. * there's nothing we can do to change the cursor...
  2901. *
  2902. * Return value:
  2903. *
  2904. * None.
  2905. *
  2906. */
  2907. static void
  2908. UpdatePrinterNameCallback(
  2909. Widget w,
  2910. XtPointer client_data,
  2911. XtPointer call_data)
  2912. {
  2913. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)client_data;
  2914. if(PSUB_TimeoutId(psub) != (XtIntervalId)NULL)
  2915. XtRemoveTimeOut(PSUB_TimeoutId(psub));
  2916. PSUB_TimeoutId(psub) =
  2917. XtAppAddTimeOut(XtWidgetToApplicationContext(w),
  2918. (unsigned long)0,
  2919. UpdatePrinterNameTimeoutProc,
  2920. (XtPointer)psub);
  2921. }
  2922. /*
  2923. * ------------------------------------------------------------------------
  2924. * Name: UpdatePrinterNameCallback
  2925. *
  2926. * Description:
  2927. *
  2928. * Timeout proc that establishes a printer connection in response to
  2929. * a user selection in the printer name combo box.
  2930. *
  2931. * Return value:
  2932. *
  2933. * None.
  2934. *
  2935. */
  2936. static void
  2937. UpdatePrinterNameTimeoutProc(XtPointer client_data,
  2938. XtIntervalId* id)
  2939. {
  2940. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)client_data;
  2941. DtPrintSetupData psd;
  2942. /*
  2943. * the timeout seems to happen before expose events from the
  2944. * popdown
  2945. */
  2946. XmUpdateDisplay((Widget)psub);
  2947. /*
  2948. * the timeout proc is only called once per XtAppAddTimeOut
  2949. */
  2950. PSUB_TimeoutId(psub) = (XtIntervalId)NULL;
  2951. /*
  2952. * check to see if the printer name has changed (if so,
  2953. * SynthGetPrinterName will close an existing print connection)
  2954. */
  2955. SynthGetPrinterName(psub);
  2956. /*
  2957. * try to establish a connection to a new printer name
  2958. * (the message hint is set so that we don't see error messages from
  2959. * here)
  2960. */
  2961. memset(&psd, 0, sizeof(DtPrintSetupData));
  2962. psd.messages_hint = DtPRINT_HINT_NO_MESSAGES;
  2963. EstablishPrinter(psub, &psd);
  2964. }
  2965. /*
  2966. * ------------------------------------------------------------------------
  2967. * Name: UpdateString
  2968. *
  2969. * Description:
  2970. *
  2971. * Set the label string of a label or button
  2972. *
  2973. * Return value:
  2974. *
  2975. * None.
  2976. *
  2977. */
  2978. static void
  2979. UpdateString(
  2980. Widget w,
  2981. XmString string,
  2982. XmStringDirection direction)
  2983. {
  2984. Arg al[3];
  2985. int ac = 0;
  2986. if (w)
  2987. {
  2988. XtSetArg (al[ac], XmNstringDirection, direction); ac++;
  2989. XtSetArg (al[ac], XmNlabelString, string); ac++;
  2990. XtSetValues (w, al, ac);
  2991. }
  2992. }
  2993. /*
  2994. * ------------------------------------------------------------------------
  2995. * Name: ValidatePrintSetupMode
  2996. *
  2997. * Description:
  2998. *
  2999. * Validate the DtNprintSetupMode resource.
  3000. *
  3001. * Return value:
  3002. *
  3003. * None.
  3004. *
  3005. */
  3006. static void
  3007. ValidatePrintSetupMode(
  3008. DtPrintSetupBoxWidget new_w,
  3009. DtPrintSetupBoxWidget current)
  3010. {
  3011. if(current == (DtPrintSetupBoxWidget)NULL)
  3012. {
  3013. switch(PSUB_PrintSetupMode(new_w))
  3014. {
  3015. case DtPRINT_SETUP_PLAIN:
  3016. case DtPRINT_SETUP_XP:
  3017. break;
  3018. default:
  3019. PSUB_PrintSetupMode(new_w) = SETUP_MODE_DEFAULT;
  3020. XmeWarning((Widget)new_w, WARN_SETUP_MODE);
  3021. break;
  3022. }
  3023. }
  3024. else
  3025. {
  3026. /*
  3027. * prevent changes to the mode
  3028. */
  3029. PSUB_PrintSetupMode(new_w) = PSUB_PrintSetupMode(current);
  3030. XmeWarning((Widget)new_w, WARN_SETUP_MODE_CHANGE);
  3031. }
  3032. }
  3033. /*
  3034. * ------------------------------------------------------------------------
  3035. * Name: ValidateWorkAreaLocation
  3036. *
  3037. * Description:
  3038. *
  3039. * Validate the DtNworkAreaLocation resource.
  3040. *
  3041. * Return value:
  3042. *
  3043. * None.
  3044. *
  3045. */
  3046. static void
  3047. ValidateWorkAreaLocation(
  3048. DtPrintSetupBoxWidget new_w,
  3049. DtPrintSetupBoxWidget current)
  3050. {
  3051. switch(PSUB_WorkAreaLocation(new_w))
  3052. {
  3053. case DtWORK_AREA_NONE:
  3054. case DtWORK_AREA_TOP:
  3055. case DtWORK_AREA_TOP_AND_BOTTOM:
  3056. case DtWORK_AREA_BOTTOM:
  3057. break;
  3058. default:
  3059. XmeWarning((Widget)new_w, WARN_WORK_AREA_LOCATION);
  3060. if(current == (DtPrintSetupBoxWidget)NULL)
  3061. PSUB_WorkAreaLocation(new_w) = WORK_AREA_DEFAULT;
  3062. else
  3063. PSUB_WorkAreaLocation(new_w) = PSUB_WorkAreaLocation(current);
  3064. break;
  3065. }
  3066. }
  3067. /*
  3068. * ------------------------------------------------------------------------
  3069. * Name: _DtPrintSetupBoxCreateBottomSeparator
  3070. *
  3071. * Description:
  3072. *
  3073. * Create the Separator displayed above the bottom work area
  3074. *
  3075. * Return value:
  3076. *
  3077. * None.
  3078. *
  3079. */
  3080. void
  3081. _DtPrintSetupBoxCreateBottomSeparator(DtPrintSetupBoxWidget psub)
  3082. {
  3083. Arg al[10];
  3084. int ac = 0;
  3085. XtSetArg(al[ac], XmNhighlightThickness, 0); ac++;
  3086. PSUB_BottomSeparator(psub) =
  3087. XmCreateSeparatorGadget((Widget) psub,
  3088. "BottomWorkAreaSeparator",
  3089. al, ac);
  3090. }
  3091. /*
  3092. * ------------------------------------------------------------------------
  3093. * Name: _DtPrintSetupBoxCreateButtonSeparator
  3094. *
  3095. * Description:
  3096. *
  3097. * Create the Separator displayed above the buttons.
  3098. *
  3099. * Return value:
  3100. *
  3101. * None.
  3102. *
  3103. */
  3104. void
  3105. _DtPrintSetupBoxCreateButtonSeparator(DtPrintSetupBoxWidget sel)
  3106. {
  3107. Arg al[10];
  3108. int ac = 0;
  3109. XtSetArg(al[ac], XmNhighlightThickness, 0); ac++;
  3110. PSUB_ButtonSeparator(sel) =
  3111. XmCreateSeparatorGadget((Widget) sel, "ButtonSeparator", al, ac);
  3112. }
  3113. /*
  3114. * ------------------------------------------------------------------------
  3115. * Name: _DtPrintSetupBoxCreateCancelButton
  3116. *
  3117. * Description:
  3118. *
  3119. * Create the "Cancel" PushButton.
  3120. *
  3121. * Return value:
  3122. *
  3123. * None.
  3124. *
  3125. */
  3126. void
  3127. _DtPrintSetupBoxCreateCancelButton(
  3128. DtPrintSetupBoxWidget psub)
  3129. {
  3130. PSUB_CancelButton(psub) =
  3131. CreateButtonGadget((Widget)psub, CANCEL_LABEL, "Cancel", XmNONE);
  3132. XtAddCallback(PSUB_CancelButton(psub), XmNactivateCallback,
  3133. PrintSetupBoxCallback, (XtPointer) DtPRINT_CANCEL_BUTTON) ;
  3134. }
  3135. /*
  3136. * ------------------------------------------------------------------------
  3137. * Name: _DtPrintSetupBoxCreateCopiesControl
  3138. *
  3139. * Description:
  3140. *
  3141. * Create the copy count label and spin box.
  3142. *
  3143. * Return value:
  3144. *
  3145. * None.
  3146. *
  3147. */
  3148. void
  3149. _DtPrintSetupBoxCreateCopiesControl(DtPrintSetupBoxWidget psub)
  3150. {
  3151. Widget copies_label;
  3152. Widget copies_text;
  3153. Boolean copies_text_editable;
  3154. /*
  3155. * create a row column to contain the copy count label and spin box
  3156. */
  3157. PSUB_CopiesControl(psub) =
  3158. XtVaCreateWidget("CopiesControl",
  3159. xmRowColumnWidgetClass,
  3160. (Widget)psub,
  3161. XmNorientation, XmHORIZONTAL,
  3162. NULL);
  3163. /*
  3164. * create the label
  3165. */
  3166. copies_label = CreateLabelGadget(PSUB_CopiesControl(psub),
  3167. COPIES_LABEL, "CopiesLabel");
  3168. XtManageChild(copies_label);
  3169. /*
  3170. * spin box
  3171. */
  3172. PSUB_CopiesSpinBox(psub) =
  3173. XtVaCreateManagedWidget("Copies",
  3174. xmSimpleSpinBoxWidgetClass,
  3175. PSUB_CopiesControl(psub) ,
  3176. XmNspinBoxChildType, XmNUMERIC,
  3177. XmNminimumValue, 1,
  3178. XmNmaximumValue, MAX_COPIES,
  3179. XmNposition, 1,
  3180. XmNpositionType, XmPOSITION_VALUE,
  3181. XmNcolumns, 5,
  3182. XmNwrap, False,
  3183. NULL);
  3184. copies_text = NULL;
  3185. copies_text_editable = FALSE;
  3186. XtVaGetValues(
  3187. PSUB_CopiesSpinBox(psub),
  3188. XmNtextField, &copies_text,
  3189. XmNeditable, &copies_text_editable,
  3190. NULL);
  3191. if (copies_text && copies_text_editable)
  3192. XtAddCallback(
  3193. copies_text, XmNvalueChangedCallback,
  3194. CopiesTextValueChangedCallback, (XtPointer) psub);
  3195. }
  3196. /*
  3197. * ------------------------------------------------------------------------
  3198. * Name: _DtPrintSetupBoxCreateDescription
  3199. *
  3200. * Description:
  3201. *
  3202. * Create the printer description.
  3203. *
  3204. * Return value:
  3205. *
  3206. * None.
  3207. *
  3208. */
  3209. void
  3210. _DtPrintSetupBoxCreateDescription(
  3211. DtPrintSetupBoxWidget psub)
  3212. {
  3213. XmRenderTable render_table;
  3214. XFontStruct* font;
  3215. unsigned long char_width;
  3216. XmString empty_label;
  3217. /*
  3218. * create the description label gadget
  3219. */
  3220. empty_label = XmStringCreateLocalized(" ");
  3221. PSUB_Description(psub) =
  3222. XtVaCreateWidget("Description",
  3223. xmLabelWidgetClass,
  3224. (Widget)psub,
  3225. XmNalignment, XmALIGNMENT_BEGINNING,
  3226. XmNlabelString, empty_label,
  3227. NULL);
  3228. XmStringFree(empty_label);
  3229. /*
  3230. * get the maximum character width for the default font of the gadget
  3231. */
  3232. XtVaGetValues(PSUB_Description(psub), XmNrenderTable, &render_table, NULL);
  3233. if(XmeRenderTableGetDefaultFont(render_table, &font))
  3234. {
  3235. Bool success;
  3236. success = XGetFontProperty(font, XA_QUAD_WIDTH, &char_width);
  3237. if(!success || char_width == 0)
  3238. {
  3239. if(font->per_char
  3240. && font->min_char_or_byte2 <= '0'
  3241. && font->max_char_or_byte2 >= '0'
  3242. )
  3243. char_width =
  3244. font->per_char['0' - font->min_char_or_byte2].width;
  3245. else
  3246. char_width = font->max_bounds.width;
  3247. }
  3248. /*
  3249. * set and lock the width of description gadget
  3250. */
  3251. XtVaSetValues(PSUB_Description(psub),
  3252. XmNwidth, (Dimension)(DESCRIPTION_COLUMNS*char_width),
  3253. XmNrecomputeSize, False,
  3254. NULL);
  3255. }
  3256. }
  3257. /*
  3258. * ------------------------------------------------------------------------
  3259. * Name: _DtPrintSetupBoxCreateDescriptionLabel
  3260. *
  3261. * Description:
  3262. *
  3263. * Create the Label for the printer description.
  3264. *
  3265. * Return value:
  3266. *
  3267. * None.
  3268. *
  3269. */
  3270. void
  3271. _DtPrintSetupBoxCreateDescriptionLabel(DtPrintSetupBoxWidget psub)
  3272. {
  3273. PSUB_DescriptionLabel(psub) =
  3274. CreateLabelGadget((Widget) psub,
  3275. DESCRIPTION_LABEL,
  3276. "DescriptionLabel") ;
  3277. }
  3278. /*
  3279. * ------------------------------------------------------------------------
  3280. * Name: _DtPrintSetupBoxCreateDestinationRadioBox
  3281. *
  3282. * Description:
  3283. *
  3284. * Create the "Print to Printer" and "Print to File" radio buttons.
  3285. *
  3286. * Return value:
  3287. *
  3288. * None.
  3289. *
  3290. */
  3291. void
  3292. _DtPrintSetupBoxCreateDestinationRadioBox(DtPrintSetupBoxWidget psub)
  3293. {
  3294. Widget button;
  3295. XmString label;
  3296. PSUB_DestinationRadioBox(psub) =
  3297. XtVaCreateWidget(
  3298. "DestRadioBox",
  3299. xmRowColumnWidgetClass,
  3300. (Widget)psub,
  3301. XmNradioBehavior, True,
  3302. XmNorientation, XmHORIZONTAL,
  3303. XmNpacking, XmPACK_TIGHT,
  3304. NULL);
  3305. label =
  3306. XmStringGenerate((XtPointer)PRINT_TO_PRINTER_LABEL, (XmStringTag)NULL,
  3307. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  3308. button =
  3309. XtVaCreateManagedWidget("button_0",
  3310. xmToggleButtonWidgetClass,
  3311. PSUB_DestinationRadioBox(psub),
  3312. XmNlabelString, label,
  3313. XmNuserData, (XtPointer)DtPRINT_TO_PRINTER,
  3314. NULL);
  3315. XmStringFree(label);
  3316. XtAddCallback(button, XmNvalueChangedCallback,
  3317. DestinationChangedCallback, (XtPointer)psub);
  3318. label = XmStringGenerate((XtPointer)PRINT_TO_FILE_LABEL, (XmStringTag)NULL,
  3319. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  3320. button =
  3321. XtVaCreateManagedWidget("button_1",
  3322. xmToggleButtonWidgetClass,
  3323. PSUB_DestinationRadioBox(psub),
  3324. XmNlabelString, label,
  3325. XmNuserData, (XtPointer)DtPRINT_TO_FILE,
  3326. NULL);
  3327. XmStringFree(label);
  3328. XtAddCallback(button, XmNvalueChangedCallback,
  3329. DestinationChangedCallback, (XtPointer)psub);
  3330. }
  3331. /*
  3332. * ------------------------------------------------------------------------
  3333. * Name: _DtPrintSetupBoxCreateFileNameLabel
  3334. *
  3335. * Description:
  3336. *
  3337. * Create the "Print to File" check box.
  3338. *
  3339. * Return value:
  3340. *
  3341. * None.
  3342. *
  3343. */
  3344. void
  3345. _DtPrintSetupBoxCreateFileNameLabel(DtPrintSetupBoxWidget psub)
  3346. {
  3347. PSUB_FileNameLabel(psub) =
  3348. CreateLabelGadget((Widget)psub, FILE_NAME_LABEL, "FileNameLabel") ;
  3349. }
  3350. /*
  3351. * ------------------------------------------------------------------------
  3352. * Name: _DtPrintSetupBoxCreateFileNameText
  3353. *
  3354. * Description:
  3355. *
  3356. * Create the print to file name text field.
  3357. *
  3358. * Return value:
  3359. *
  3360. * None.
  3361. *
  3362. */
  3363. void
  3364. _DtPrintSetupBoxCreateFileNameText(DtPrintSetupBoxWidget psub)
  3365. {
  3366. PSUB_FileNameText(psub) =
  3367. XtVaCreateWidget("FileName",
  3368. xmTextFieldWidgetClass,
  3369. (Widget)psub,
  3370. XmNcolumns, FILE_NAME_COLUMNS,
  3371. NULL);
  3372. }
  3373. /*
  3374. * ------------------------------------------------------------------------
  3375. * Name: _DtPrintSetupBoxCreateHelpButton
  3376. *
  3377. * Description:
  3378. * Create the "Help" PushButton.
  3379. *
  3380. * Return value:
  3381. *
  3382. * None.
  3383. *
  3384. */
  3385. void
  3386. _DtPrintSetupBoxCreateHelpButton(DtPrintSetupBoxWidget psub)
  3387. {
  3388. PSUB_HelpButton(psub) =
  3389. CreateButtonGadget((Widget)psub, HELP_LABEL, "Help", XmNONE) ;
  3390. /*
  3391. * Remove BulletinBoard Unmanage callback
  3392. */
  3393. XtRemoveAllCallbacks(PSUB_HelpButton(psub), XmNactivateCallback) ;
  3394. XtAddCallback(PSUB_HelpButton (psub), XmNactivateCallback,
  3395. PrintSetupBoxCallback, (XtPointer)DtPRINT_HELP_BUTTON) ;
  3396. }
  3397. /*
  3398. * ------------------------------------------------------------------------
  3399. * Name: _DtPrintSetupBoxCreatePrintButton
  3400. *
  3401. * Description:
  3402. * Create the "Print" PushButton.
  3403. *
  3404. * Return value:
  3405. *
  3406. * None.
  3407. *
  3408. */
  3409. void
  3410. _DtPrintSetupBoxCreatePrintButton(DtPrintSetupBoxWidget psub)
  3411. {
  3412. PSUB_PrintButton(psub) =
  3413. CreateButton((Widget)psub, PRINT_LABEL, "Print", XmNONE) ;
  3414. /*
  3415. * Remove the BulletinBoard unmanage callback. The
  3416. * PrintSetupBoxCallback routine will unmanage the widget if the
  3417. * AutoUnmanage resource is set, but only if the printer name is
  3418. * successfully verified.
  3419. */
  3420. XtRemoveAllCallbacks(PSUB_PrintButton(psub), XmNactivateCallback);
  3421. XtAddCallback(PSUB_PrintButton(psub), XmNactivateCallback,
  3422. PrintSetupBoxCallback, (XtPointer)DtPRINT_PRINT_BUTTON) ;
  3423. }
  3424. /*
  3425. * ------------------------------------------------------------------------
  3426. * Name: _DtPrintSetupBoxCreatePrinterInfoButton
  3427. *
  3428. * Description:
  3429. *
  3430. * Create the "Info..." PushButton
  3431. *
  3432. * Return value:
  3433. *
  3434. * None.
  3435. *
  3436. */
  3437. void
  3438. _DtPrintSetupBoxCreatePrinterInfoButton(DtPrintSetupBoxWidget psub)
  3439. {
  3440. PSUB_PrinterInfoButton(psub) =
  3441. CreateButton((Widget)psub, PRINTER_INFO_LABEL, "Info", XmTAB_GROUP);
  3442. XtRemoveAllCallbacks(PSUB_PrinterInfoButton(psub), XmNactivateCallback);
  3443. XtAddCallback(PSUB_PrinterInfoButton(psub), XmNactivateCallback,
  3444. PrintSetupBoxCallback, (XtPointer) DtPRINT_INFO_BUTTON) ;
  3445. }
  3446. /*
  3447. * ------------------------------------------------------------------------
  3448. * Name: _DtPrintSetupBoxCreatePrinterNameCombo
  3449. *
  3450. * Description:
  3451. *
  3452. * Create the combo box containing the printer name text field and
  3453. * the short printer list.
  3454. *
  3455. * Return value:
  3456. *
  3457. * None.
  3458. *
  3459. */
  3460. void
  3461. _DtPrintSetupBoxCreatePrinterNameCombo(DtPrintSetupBoxWidget psub)
  3462. {
  3463. PSUB_PrinterNameCombo(psub) =
  3464. XtVaCreateWidget("Name", xmComboBoxWidgetClass, (Widget)psub,
  3465. XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX,
  3466. XmNcolumns, PRINTER_NAME_COLUMNS,
  3467. XmNpositionMode, XmZERO_BASED,
  3468. NULL);
  3469. PSUB_PrinterNameText(psub) =
  3470. XtNameToWidget(PSUB_PrinterNameCombo(psub), "*Text");
  3471. /*
  3472. * add a selection callback to the combo box that will cause the
  3473. * selected printer to be set in the PSUB (verified, etc).
  3474. */
  3475. XtAddCallback(PSUB_PrinterNameCombo(psub), XmNselectionCallback,
  3476. UpdatePrinterNameCallback, (XtPointer)psub);
  3477. /*
  3478. * Xp Setup Mode specific initialization
  3479. */
  3480. if(PSUB_PrintSetupMode(psub) == DtPRINT_SETUP_XP)
  3481. {
  3482. String* printer_list;
  3483. Boolean hide_arrow = True;
  3484. /*
  3485. * add a callback to close an existing connection whenever the
  3486. * user modifies the text field.
  3487. */
  3488. XtAddCallback(PSUB_PrinterNameText(psub), XmNvalueChangedCallback,
  3489. ClosePrintConnectionCallback, (XtPointer)psub);
  3490. /*
  3491. * initialize the combo box list
  3492. */
  3493. printer_list = _DtPrintGetXpPrinterList((Widget)psub);
  3494. if(printer_list != (String*)NULL)
  3495. {
  3496. int count;
  3497. /*
  3498. * count the number of printer names in the returned list,
  3499. */
  3500. for(count = 0; printer_list[count] != (String)NULL; count++);
  3501. if(count > 0)
  3502. {
  3503. XmString* printer_xmstr_list;
  3504. int i;
  3505. Widget combo_list;
  3506. /*
  3507. * build a XmString version of the printer list
  3508. */
  3509. printer_xmstr_list =
  3510. (XmString*)XtCalloc(count, sizeof(XmString));
  3511. for(i = 0; i < count; i++)
  3512. printer_xmstr_list[i] =
  3513. XmStringGenerate((XtPointer)printer_list[i],
  3514. (XmStringTag)NULL,
  3515. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  3516. /*
  3517. * get the widget ID of the combo box list
  3518. */
  3519. combo_list =
  3520. XtNameToWidget(PSUB_PrinterNameCombo(psub), "*List");
  3521. if(combo_list)
  3522. {
  3523. int visible_item_count;
  3524. /*
  3525. * get the initial visible item count
  3526. */
  3527. XtVaGetValues(combo_list,
  3528. XmNvisibleItemCount, &visible_item_count,
  3529. NULL);
  3530. /*
  3531. * reduce the visible item count if needed
  3532. */
  3533. if(count < visible_item_count)
  3534. visible_item_count = count;
  3535. /*
  3536. * set the XmString printer list in the combo box list
  3537. */
  3538. XtVaSetValues(combo_list,
  3539. XmNitemCount, count,
  3540. XmNitems, printer_xmstr_list,
  3541. XmNvisibleItemCount, visible_item_count,
  3542. NULL);
  3543. hide_arrow = False;
  3544. }
  3545. for(i = 0; i < count; i++)
  3546. XmStringFree(printer_xmstr_list[i]);
  3547. XtFree((char*)printer_xmstr_list);
  3548. }
  3549. _DtPrintFreeStringList(printer_list);
  3550. }
  3551. if(hide_arrow)
  3552. {
  3553. Dimension text_shadow_thickness;
  3554. XtVaGetValues(PSUB_PrinterNameText(psub),
  3555. XmNshadowThickness, &text_shadow_thickness,
  3556. NULL);
  3557. XtVaSetValues(PSUB_PrinterNameCombo(psub),
  3558. XmNarrowSize, 0,
  3559. XmNarrowSpacing, 0,
  3560. XmNmarginWidth, 0,
  3561. XmNmarginHeight, 0,
  3562. XmNshadowThickness, 0,
  3563. NULL);
  3564. XtVaSetValues(PSUB_PrinterNameText(psub),
  3565. XmNshadowThickness, text_shadow_thickness,
  3566. NULL);
  3567. }
  3568. }
  3569. }
  3570. /*
  3571. * ------------------------------------------------------------------------
  3572. * Name: _DtPrintSetupBoxCreatePrinterNameLabel
  3573. *
  3574. * Description:
  3575. *
  3576. * Create the Label for the printer name.
  3577. *
  3578. * Return value:
  3579. *
  3580. * None.
  3581. *
  3582. */
  3583. void
  3584. _DtPrintSetupBoxCreatePrinterNameLabel(DtPrintSetupBoxWidget psub)
  3585. {
  3586. PSUB_PrinterNameLabel(psub) =
  3587. CreateLabelGadget((Widget) psub,
  3588. PRINTER_NAME_LABEL,
  3589. "NameLabel") ;
  3590. }
  3591. /*
  3592. * ------------------------------------------------------------------------
  3593. * Name: _DtPrintSetupBoxCreateSelectFileButton
  3594. *
  3595. * Description:
  3596. *
  3597. * Create the "Select File..." PushButton
  3598. *
  3599. * Return value:
  3600. *
  3601. * None.
  3602. *
  3603. */
  3604. void
  3605. _DtPrintSetupBoxCreateSelectFileButton(DtPrintSetupBoxWidget psub)
  3606. {
  3607. PSUB_SelectFileButton(psub) =
  3608. CreateButtonGadget((Widget)psub, SELECT_FILE_LABEL,
  3609. "SelectFile", XmTAB_GROUP);
  3610. XtRemoveAllCallbacks(PSUB_SelectFileButton(psub), XmNactivateCallback) ;
  3611. XtAddCallback(PSUB_SelectFileButton(psub), XmNactivateCallback,
  3612. PrintSetupBoxCallback, (XtPointer) DtPRINT_FILES_BUTTON) ;
  3613. }
  3614. /*
  3615. * ------------------------------------------------------------------------
  3616. * Name: _DtPrintSetupBoxCreateSelectPrinterButton
  3617. *
  3618. * Description:
  3619. *
  3620. * Create the "Select Printer..." PushButton
  3621. *
  3622. * Return value:
  3623. *
  3624. * None.
  3625. *
  3626. */
  3627. void
  3628. _DtPrintSetupBoxCreateSelectPrinterButton(DtPrintSetupBoxWidget psub)
  3629. {
  3630. PSUB_SelectPrinterButton(psub) =
  3631. CreateButtonGadget((Widget)psub, SELECT_PRINTER_LABEL,
  3632. "SelectPrinter", XmTAB_GROUP);
  3633. XtRemoveAllCallbacks(PSUB_SelectPrinterButton(psub), XmNactivateCallback);
  3634. XtAddCallback(PSUB_SelectPrinterButton(psub), XmNactivateCallback,
  3635. PrintSetupBoxCallback, (XtPointer) DtPRINT_PRINTERS_BUTTON) ;
  3636. }
  3637. /*
  3638. * ------------------------------------------------------------------------
  3639. * Name: _DtPrintSetupBoxCreateSetupButton
  3640. *
  3641. * Description:
  3642. *
  3643. * Create the "Setup" PushButton.
  3644. *
  3645. * Return value:
  3646. *
  3647. * None.
  3648. *
  3649. */
  3650. void
  3651. _DtPrintSetupBoxCreateSetupButton(DtPrintSetupBoxWidget psub)
  3652. {
  3653. PSUB_SetupButton(psub) =
  3654. CreateButton((Widget) psub, SETUP_LABEL, "Setup", XmNONE);
  3655. /*
  3656. * Remove BulletinBoard Unmanage callback from Setup button
  3657. */
  3658. XtRemoveAllCallbacks(PSUB_SetupButton(psub), XmNactivateCallback) ;
  3659. XtAddCallback(PSUB_SetupButton (psub), XmNactivateCallback,
  3660. PrintSetupBoxCallback, (XtPointer) DtPRINT_SETUP_BUTTON) ;
  3661. }
  3662. /*
  3663. * ------------------------------------------------------------------------
  3664. * Name: _DtPrintSetupBoxCreateTopSeparator
  3665. *
  3666. * Description:
  3667. *
  3668. * Create the Separator displayed below the top work area
  3669. *
  3670. * Return value:
  3671. *
  3672. * None.
  3673. *
  3674. */
  3675. void
  3676. _DtPrintSetupBoxCreateTopSeparator(DtPrintSetupBoxWidget psub)
  3677. {
  3678. Arg al[10];
  3679. int ac = 0;
  3680. XtSetArg(al[ac], XmNhighlightThickness, 0); ac++;
  3681. PSUB_TopSeparator(psub) =
  3682. XmCreateSeparatorGadget((Widget) psub,
  3683. "TopWorkAreaSeparator",
  3684. al, ac);
  3685. }
  3686. /*
  3687. * ------------------------------------------------------------------------
  3688. * Name: _DtPrintSetupBoxGeoMatrixCreate - BulletinBoard class method
  3689. *
  3690. * Description:
  3691. *
  3692. * Return value:
  3693. *
  3694. */
  3695. XmGeoMatrix
  3696. _DtPrintSetupBoxGeoMatrixCreate(
  3697. Widget wid,
  3698. Widget instigator,
  3699. XtWidgetGeometry *desired)
  3700. {
  3701. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget) wid ;
  3702. XmGeoMatrix geoSpec ;
  3703. XmGeoRowLayout layoutPtr ;
  3704. XmKidGeometry boxPtr ;
  3705. XmKidGeometry firstButtonBox ;
  3706. XmKidGeometry boxMark;
  3707. Dimension vspace = BB_MarginHeight(psub);
  3708. int i;
  3709. PSUB_GeoExtension ext;
  3710. int psub_geo_fill = XmGEO_PACK;
  3711. int psub_geo_fit = XmGEO_PROPORTIONAL;
  3712. /*
  3713. * Layout PrintSetupBox XmGeoMatrix.
  3714. * Each row is terminated by leaving an empty XmKidGeometry and
  3715. * moving to the next XmGeoRowLayout.
  3716. */
  3717. geoSpec = _XmGeoMatrixAlloc(DtPSUB_MAX_WIDGETS_VERT,
  3718. psub->composite.num_children,
  3719. sizeof(PSUB_GeoExtensionRec));
  3720. ext = geoSpec->extension;
  3721. geoSpec->composite = (Widget) psub ;
  3722. geoSpec->instigator = (Widget) instigator ;
  3723. if(desired)
  3724. {
  3725. geoSpec->instig_request = *desired ;
  3726. }
  3727. geoSpec->margin_w = BB_MarginWidth(psub) + psub->manager.shadow_thickness;
  3728. geoSpec->margin_h = BB_MarginHeight(psub) + psub->manager.shadow_thickness;
  3729. geoSpec->no_geo_request = _DtPrintSetupBoxNoGeoRequest ;
  3730. layoutPtr = &(geoSpec->layouts->row) ;
  3731. boxPtr = geoSpec->boxes ;
  3732. /*
  3733. * menu bar
  3734. */
  3735. for (i = 0; i < psub->composite.num_children; i++)
  3736. {
  3737. Widget w = psub->composite.children[i];
  3738. if(XmIsRowColumn(w)
  3739. && ((XmRowColumnWidget)w)->row_column.type == XmMENU_BAR
  3740. && w != PSUB_TopWorkArea(psub)
  3741. && w != PSUB_BottomWorkArea(psub)
  3742. && _XmGeoSetupKid(boxPtr, w))
  3743. {
  3744. layoutPtr->fix_up = MenuBarFixUp;
  3745. boxPtr += 2;
  3746. ++layoutPtr;
  3747. vspace = 0; /* fixup space_above of next row. */
  3748. break;
  3749. }
  3750. }
  3751. /*
  3752. * top work area + separator
  3753. */
  3754. if(PSUB_TopWorkArea(psub) != (Widget)NULL)
  3755. {
  3756. if(_XmGeoSetupKid(boxPtr, PSUB_TopWorkArea(psub)))
  3757. {
  3758. layoutPtr->space_above = vspace;
  3759. vspace = BB_MarginHeight(psub);
  3760. boxPtr += 2;
  3761. ++layoutPtr;
  3762. }
  3763. if(_XmGeoSetupKid(boxPtr, PSUB_TopSeparator(psub)))
  3764. {
  3765. layoutPtr->fix_up = SeparatorFixUp;
  3766. layoutPtr->space_above = vspace;
  3767. vspace = BB_MarginHeight(psub);
  3768. boxPtr += 2 ;
  3769. ++layoutPtr ;
  3770. }
  3771. }
  3772. /*
  3773. * printer description label, printer description and printer info
  3774. * button
  3775. */
  3776. boxMark = boxPtr;
  3777. if(_XmGeoSetupKid(boxPtr, PSUB_DescriptionLabel(psub)))
  3778. {
  3779. (ext->pbox)[ext->row_count][0].geo = boxPtr;
  3780. (ext->pbox)[ext->row_count][0].align = PSUB_GEO_ALIGN_RIGHT;
  3781. ++boxPtr;
  3782. }
  3783. if(_XmGeoSetupKid(boxPtr, PSUB_Description(psub)))
  3784. {
  3785. (ext->pbox)[ext->row_count][1].geo = boxPtr;
  3786. (ext->pbox)[ext->row_count][1].align = PSUB_GEO_ALIGN_LEFT;
  3787. ++boxPtr;
  3788. }
  3789. if(_XmGeoSetupKid(boxPtr, PSUB_PrinterInfoButton(psub)))
  3790. {
  3791. (ext->pbox)[ext->row_count][2].geo = boxPtr;
  3792. (ext->pbox)[ext->row_count][2].align = PSUB_GEO_ALIGN_EXPAND;
  3793. ++boxPtr;
  3794. }
  3795. if(boxPtr != boxMark)
  3796. {
  3797. (ext->layout_ptr)[ext->row_count++] = layoutPtr;
  3798. layoutPtr->fix_up = ColumnGeoFixUp;
  3799. layoutPtr->even_width = 0;
  3800. layoutPtr->even_height = 0;
  3801. layoutPtr->fill_mode = psub_geo_fill ;
  3802. layoutPtr->fit_mode = psub_geo_fit ;
  3803. layoutPtr->space_above = vspace;
  3804. vspace = BB_MarginHeight(psub);
  3805. ++boxPtr;
  3806. ++layoutPtr ;
  3807. }
  3808. /*
  3809. * printer name label, printer name, select printer button
  3810. */
  3811. boxMark = boxPtr;
  3812. if(_XmGeoSetupKid(boxPtr, PSUB_PrinterNameLabel(psub)))
  3813. {
  3814. (ext->pbox)[ext->row_count][0].geo = boxPtr;
  3815. (ext->pbox)[ext->row_count][0].align = PSUB_GEO_ALIGN_RIGHT;
  3816. ++boxPtr;
  3817. }
  3818. if(_XmGeoSetupKid(boxPtr, PSUB_PrinterNameCombo(psub)))
  3819. {
  3820. (ext->pbox)[ext->row_count][1].geo = boxPtr;
  3821. (ext->pbox)[ext->row_count][1].align = PSUB_GEO_ALIGN_LEFT;
  3822. ++boxPtr;
  3823. }
  3824. if(_XmGeoSetupKid(boxPtr, PSUB_SelectPrinterButton(psub)))
  3825. {
  3826. (ext->pbox)[ext->row_count][2].geo = boxPtr;
  3827. (ext->pbox)[ext->row_count][2].align = PSUB_GEO_ALIGN_EXPAND;
  3828. ++boxPtr;
  3829. }
  3830. if(boxPtr != boxMark)
  3831. {
  3832. (ext->layout_ptr)[ext->row_count++] = layoutPtr;
  3833. layoutPtr->fix_up = ColumnGeoFixUp;
  3834. layoutPtr->even_width = 0;
  3835. layoutPtr->even_height = 0;
  3836. layoutPtr->fill_mode = psub_geo_fill ;
  3837. layoutPtr->fit_mode = psub_geo_fit ;
  3838. layoutPtr->space_above = vspace;
  3839. vspace = BB_MarginHeight(psub);
  3840. ++boxPtr;
  3841. ++layoutPtr ;
  3842. }
  3843. /*
  3844. * file name label, file name text, select file button
  3845. */
  3846. boxMark = boxPtr;
  3847. if(_XmGeoSetupKid(boxPtr, PSUB_FileNameLabel(psub)))
  3848. {
  3849. (ext->pbox)[ext->row_count][0].geo = boxPtr;
  3850. (ext->pbox)[ext->row_count][0].align = PSUB_GEO_ALIGN_RIGHT;
  3851. ++boxPtr;
  3852. }
  3853. if(_XmGeoSetupKid(boxPtr, PSUB_FileNameText(psub)))
  3854. {
  3855. (ext->pbox)[ext->row_count][1].geo = boxPtr;
  3856. (ext->pbox)[ext->row_count][1].align = PSUB_GEO_ALIGN_LEFT;
  3857. ++boxPtr;
  3858. }
  3859. if(_XmGeoSetupKid(boxPtr, PSUB_SelectFileButton(psub)))
  3860. {
  3861. (ext->pbox)[ext->row_count][2].geo = boxPtr;
  3862. (ext->pbox)[ext->row_count][2].align = PSUB_GEO_ALIGN_EXPAND;
  3863. ++boxPtr;
  3864. }
  3865. if(boxPtr != boxMark)
  3866. {
  3867. (ext->layout_ptr)[ext->row_count++] = layoutPtr;
  3868. layoutPtr->fix_up = ColumnGeoFixUp;
  3869. layoutPtr->even_width = 0;
  3870. layoutPtr->even_height = 0;
  3871. layoutPtr->fill_mode = psub_geo_fill ;
  3872. layoutPtr->fit_mode = psub_geo_fit ;
  3873. layoutPtr->space_above = vspace;
  3874. vspace = BB_MarginHeight(psub);
  3875. ++boxPtr;
  3876. ++layoutPtr ;
  3877. }
  3878. /*
  3879. * copies label and copies field
  3880. */
  3881. boxMark = boxPtr;
  3882. if(_XmGeoSetupKid(boxPtr, PSUB_DestinationRadioBox(psub)))
  3883. {
  3884. ++boxPtr;
  3885. }
  3886. if(_XmGeoSetupKid(boxPtr, PSUB_CopiesControl(psub)))
  3887. {
  3888. ++boxPtr;
  3889. }
  3890. if(boxPtr != boxMark)
  3891. {
  3892. layoutPtr->fill_mode = XmGEO_CENTER ;
  3893. layoutPtr->fit_mode = XmGEO_WRAP ;
  3894. layoutPtr->even_width = 0;
  3895. layoutPtr->even_height = 0;
  3896. layoutPtr->space_between = 10;
  3897. layoutPtr->space_above = vspace;
  3898. vspace = BB_MarginHeight(psub);
  3899. ++boxPtr;
  3900. ++layoutPtr ;
  3901. }
  3902. /*
  3903. * bottom work area + separator
  3904. */
  3905. if(PSUB_BottomWorkArea(psub) != (Widget)NULL)
  3906. {
  3907. if(_XmGeoSetupKid(boxPtr, PSUB_BottomSeparator(psub)))
  3908. {
  3909. layoutPtr->fix_up = SeparatorFixUp;
  3910. layoutPtr->space_above = vspace;
  3911. vspace = BB_MarginHeight(psub);
  3912. boxPtr += 2 ;
  3913. ++layoutPtr ;
  3914. }
  3915. if(_XmGeoSetupKid(boxPtr, PSUB_BottomWorkArea(psub)))
  3916. {
  3917. layoutPtr->space_above = vspace;
  3918. vspace = BB_MarginHeight(psub);
  3919. boxPtr += 2;
  3920. ++layoutPtr;
  3921. }
  3922. }
  3923. /*
  3924. * button separator
  3925. */
  3926. if(_XmGeoSetupKid(boxPtr, PSUB_ButtonSeparator(psub)))
  3927. {
  3928. layoutPtr->fix_up = SeparatorFixUp;
  3929. layoutPtr->space_above = vspace;
  3930. vspace = BB_MarginHeight(psub);
  3931. boxPtr += 2 ;
  3932. ++layoutPtr ;
  3933. }
  3934. /*
  3935. * button row
  3936. */
  3937. firstButtonBox = boxPtr ;
  3938. if(_XmGeoSetupKid(boxPtr, PSUB_PrintButton(psub)))
  3939. {
  3940. ++boxPtr ;
  3941. }
  3942. for(i = 0; i < psub->composite.num_children; i++)
  3943. {
  3944. Widget w = psub->composite.children[i];
  3945. if(IsButton(w)
  3946. &&
  3947. !IsAutoButton(psub,w)
  3948. &&
  3949. w != PSUB_TopWorkArea(psub)
  3950. &&
  3951. w != PSUB_BottomWorkArea(psub)
  3952. )
  3953. {
  3954. if(_XmGeoSetupKid(boxPtr, w))
  3955. {
  3956. ++boxPtr ;
  3957. }
  3958. }
  3959. }
  3960. if(_XmGeoSetupKid(boxPtr, PSUB_SetupButton(psub)))
  3961. {
  3962. ++boxPtr ;
  3963. }
  3964. if(_XmGeoSetupKid(boxPtr, PSUB_CancelButton(psub)))
  3965. {
  3966. ++boxPtr ;
  3967. }
  3968. if(_XmGeoSetupKid(boxPtr, PSUB_HelpButton(psub)))
  3969. {
  3970. ++boxPtr ;
  3971. }
  3972. if(boxPtr != firstButtonBox)
  3973. {
  3974. layoutPtr->fill_mode = XmGEO_CENTER ;
  3975. layoutPtr->fit_mode = XmGEO_WRAP ;
  3976. layoutPtr->space_above = vspace;
  3977. vspace = BB_MarginHeight(psub);
  3978. if(!(psub->print_setup_box.minimize_buttons))
  3979. {
  3980. layoutPtr->even_width = 1 ;
  3981. }
  3982. layoutPtr->even_height = 1 ;
  3983. ++layoutPtr ;
  3984. }
  3985. /*
  3986. * the end.
  3987. */
  3988. layoutPtr->space_above = vspace;
  3989. layoutPtr->end = TRUE ;
  3990. return(geoSpec) ;
  3991. }
  3992. /*
  3993. * ------------------------------------------------------------------------
  3994. * Name: _DtPrintSetupBoxNoGeoRequest
  3995. *
  3996. * Description:
  3997. *
  3998. * Return value:
  3999. *
  4000. */
  4001. Boolean
  4002. _DtPrintSetupBoxNoGeoRequest(
  4003. XmGeoMatrix geoSpec)
  4004. {
  4005. if(BB_InSetValues(geoSpec->composite)
  4006. && (XtClass(geoSpec->composite) == dtPrintSetupBoxWidgetClass))
  4007. {
  4008. return(TRUE) ;
  4009. }
  4010. return(FALSE) ;
  4011. }
  4012. /*
  4013. * ------------------------------------------------------------------------
  4014. * Name: _DtPrintSetupBoxGetCopies
  4015. *
  4016. * Description:
  4017. *
  4018. * Update the location pointed to by "value" with the current value
  4019. * of the Copies spin box.
  4020. *
  4021. * Return value:
  4022. *
  4023. * None.
  4024. *
  4025. */
  4026. void
  4027. _DtPrintSetupBoxGetCopies(
  4028. Widget wid,
  4029. int resource_offset,
  4030. XtArgVal *value)
  4031. {
  4032. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget) wid ;
  4033. int copies;
  4034. if(PSUB_CopiesSpinBox(psub) != (Widget)NULL)
  4035. {
  4036. XtVaGetValues(PSUB_CopiesSpinBox(psub),
  4037. XmNposition, &copies,
  4038. NULL);
  4039. *value = (XtArgVal)copies;
  4040. }
  4041. else
  4042. {
  4043. *value = (XtArgVal)PSUB_Copies(psub);
  4044. }
  4045. }
  4046. /*
  4047. * ------------------------------------------------------------------------
  4048. * Name: _DtPrintSetupBoxGetDescription
  4049. *
  4050. * Description:
  4051. *
  4052. * Update the description instance variable based on the current
  4053. * value of the Printer Description label gadget.
  4054. *
  4055. * Return value:
  4056. *
  4057. * None.
  4058. *
  4059. */
  4060. void
  4061. _DtPrintSetupBoxGetDescription(
  4062. Widget wid,
  4063. int resource_offset,
  4064. XtArgVal *value)
  4065. {
  4066. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget) wid ;
  4067. XmString data ;
  4068. if(PSUB_Description(psub) != (Widget)NULL)
  4069. {
  4070. XtVaGetValues((Widget)PSUB_Description(psub),
  4071. XmNlabelString, &data,
  4072. NULL);
  4073. *value = (XtArgVal)data;
  4074. }
  4075. else
  4076. {
  4077. *value = (XtArgVal)NULL;
  4078. }
  4079. }
  4080. /*
  4081. * ------------------------------------------------------------------------
  4082. * Name: _DtPrintSetupBoxGetFileName
  4083. *
  4084. * Description:
  4085. *
  4086. * Return value:
  4087. *
  4088. * None.
  4089. *
  4090. */
  4091. void
  4092. _DtPrintSetupBoxGetFileName(
  4093. Widget w,
  4094. int resource_offset,
  4095. XtArgVal *value)
  4096. {
  4097. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)w;
  4098. SynthGetFileName(psub);
  4099. *value = (XtArgVal)PSUB_FileName(psub);
  4100. }
  4101. /*
  4102. * ------------------------------------------------------------------------
  4103. * Name: _DtPrintSetupBoxGetPrinterName
  4104. *
  4105. * Description:
  4106. *
  4107. * Return value:
  4108. *
  4109. * None.
  4110. *
  4111. */
  4112. void
  4113. _DtPrintSetupBoxGetPrinterName(
  4114. Widget w,
  4115. int resource_offset,
  4116. XtArgVal *value)
  4117. {
  4118. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)w;
  4119. SynthGetPrinterName(psub);
  4120. *value = (XtArgVal)PSUB_PrinterName(psub);
  4121. }
  4122. /*
  4123. * ------------------------------------------------------------------------
  4124. * Name: DtCreatePrintSetupBox
  4125. *
  4126. * Description:
  4127. *
  4128. * DtCreatePrintSetupBox is a convenience function that creates an
  4129. * unmanaged instance of a DtPrintSetupBox widget, and returns its
  4130. * widget ID.
  4131. *
  4132. * Arguments:
  4133. *
  4134. * parent
  4135. * Specifies the parent widget ID.
  4136. *
  4137. * name
  4138. * Specifies the name of the created widget.
  4139. *
  4140. * args
  4141. * Specifies the argument list.
  4142. *
  4143. * n
  4144. * Specifies the number of attribute/value pairs in arglist.
  4145. *
  4146. * Return value:
  4147. *
  4148. * Returns the DtPrintSetupBox widget ID.
  4149. *
  4150. */
  4151. Widget
  4152. DtCreatePrintSetupBox(
  4153. Widget p,
  4154. String name,
  4155. ArgList args,
  4156. Cardinal n)
  4157. {
  4158. return XtCreateWidget(name, dtPrintSetupBoxWidgetClass, p, args, n);
  4159. }
  4160. /*
  4161. * ------------------------------------------------------------------------
  4162. * Name: DtCreatePrintSetupDialog
  4163. *
  4164. * Description:
  4165. *
  4166. * DtCreatePrintSetupDialog is a convenience function that creates an
  4167. * instance of a dialog containing a DtPrintSetupBox widget, and
  4168. * returns the DtPrintSetupBox widget ID.
  4169. *
  4170. * Arguments:
  4171. *
  4172. * parent
  4173. * Specifies the parent widget ID.
  4174. *
  4175. * name
  4176. * Specifies the name of the created widget.
  4177. *
  4178. * args
  4179. * Specifies the argument list.
  4180. *
  4181. * n
  4182. * Specifies the number of attribute/value pairs in arglist.
  4183. *
  4184. * Return value:
  4185. *
  4186. * Returns the DtPrintSetupBox widget ID.
  4187. *
  4188. */
  4189. Widget
  4190. DtCreatePrintSetupDialog(
  4191. Widget parent,
  4192. String name,
  4193. ArgList args,
  4194. Cardinal n)
  4195. {
  4196. return XmeCreateClassDialog(dtPrintSetupBoxWidgetClass,
  4197. parent, name, args, n);
  4198. }
  4199. /*
  4200. * ------------------------------------------------------------------------
  4201. * Name: DtPrintCopySetupData
  4202. *
  4203. * Description:
  4204. *
  4205. * DtPrintCopySetupData is used to copy the DtPrintSetupData
  4206. * structure pointed to by 'source' to the DtPrintSetupData structure
  4207. * pointed to by 'target'. Elements in 'target' are updated only if
  4208. * different than the corresponding element in 'source'. For elements
  4209. * that point to allocated memory, DtPrintCopySetupData allocates new
  4210. * memory for those elements updated in 'target'. Existing elements
  4211. * in 'target' are freed using XtFree. All elements in a
  4212. * DtPrintSetupData structure can be freed by calling
  4213. * DtPrintFreeSetupData.
  4214. *
  4215. * If 'source' or 'target' is NULL the copy will not be performed.
  4216. *
  4217. * Arguments:
  4218. *
  4219. * target
  4220. * A pointer to the DtPrintSetupData structure to copy to.
  4221. *
  4222. * source
  4223. * A pointer to the DtPrintSetupData structure to copy from.
  4224. *
  4225. * Return value:
  4226. *
  4227. * The target pointer.
  4228. *
  4229. */
  4230. DtPrintSetupData*
  4231. DtPrintCopySetupData(
  4232. DtPrintSetupData* target,
  4233. const DtPrintSetupData* source)
  4234. {
  4235. if(source != (DtPrintSetupData*)NULL
  4236. &&
  4237. target != (DtPrintSetupData*)NULL)
  4238. {
  4239. if((source->printer_name == (String)NULL
  4240. ||
  4241. target->printer_name == (String)NULL)
  4242. ? True
  4243. : strcmp(source->printer_name, target->printer_name) != 0)
  4244. {
  4245. XtFree(target->printer_name);
  4246. target->printer_name = XtNewString(source->printer_name);
  4247. }
  4248. target->print_display = source->print_display;
  4249. #if 0 && defined(PRINTING_SUPPORTED)
  4250. target->print_context = source->print_context;
  4251. #endif /* PRINTING_SUPPORTED */
  4252. target->destination = source->destination;
  4253. target->messages_hint = source->messages_hint;
  4254. if((source->dest_info == (String)NULL
  4255. ||
  4256. target->dest_info == (String)NULL)
  4257. ? True
  4258. : strcmp(source->dest_info, target->dest_info) != 0)
  4259. {
  4260. XtFree(target->dest_info);
  4261. target->dest_info = XtNewString(source->dest_info);
  4262. }
  4263. }
  4264. return target;
  4265. }
  4266. /*
  4267. * ------------------------------------------------------------------------
  4268. * Name: DtPrintFillSetupData
  4269. *
  4270. * Description:
  4271. *
  4272. * DtPrintFillSetupData is used to obtain an X printer connection in
  4273. * order to initiate an X printing job in situations other than
  4274. * direct interaction with a DtPrintSetupBox (e.g. a "quick print"
  4275. * button on a toolbar). This printer connection information can be
  4276. * obtained from an existing DtPrintSetupBox widget instance, or if a
  4277. * DtPrintSetupBox widget instance is unavailable,
  4278. * DtPrintFillSetupData will provide a new X printer connection.
  4279. *
  4280. * Arguments:
  4281. *
  4282. * psub
  4283. * The widget ID of a DtPrintSetupBox, or NULL if no
  4284. * DtPrintSetupBox is available.
  4285. *
  4286. * print_data
  4287. * A pointer to an existing DtPrintSetupData structure that
  4288. * DtPrintFillSetupData will update with valid X printer
  4289. * connection information.
  4290. *
  4291. * Return value:
  4292. *
  4293. * DtPRINT_SUCCESS
  4294. * The X printer connection was successfully obtained.
  4295. *
  4296. * DtPRINT_FAILURE
  4297. * The X printer connection could not be established. The
  4298. * specific reason has been reported by the print setup box to
  4299. * the user.
  4300. *
  4301. * DtPRINT_INVALID_DISPLAY
  4302. * The indicated X print server could not be found.
  4303. *
  4304. * DtPRINT_NOT_XP_DISPLAY
  4305. * The indicated X server does not support the X Printing
  4306. * Extension.
  4307. *
  4308. * DtPRINT_NO_PRINTER
  4309. * The indicated printer could not be found on the X print
  4310. * server.
  4311. *
  4312. * DtPRINT_NO_DEFAULT
  4313. * A default printer could not be determined.
  4314. *
  4315. * DtPRINT_BAD_PARM
  4316. * The value passed for print_data is NULL.
  4317. *
  4318. */
  4319. XtEnum DtPrintFillSetupData(
  4320. Widget w,
  4321. DtPrintSetupData* print_data)
  4322. {
  4323. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)w;
  4324. if(print_data == (DtPrintSetupData*)NULL)
  4325. return DtPRINT_BAD_PARM;
  4326. if(psub == (DtPrintSetupBoxWidget)NULL)
  4327. {
  4328. XtEnum status;
  4329. String new_printer_spec;
  4330. Display* new_display;
  4331. #if 0 && defined(PRINTING_SUPPORTED)
  4332. XPContext new_context;
  4333. #endif /* PRINTING_SUPPORTED */
  4334. /*
  4335. * GUI-less printing; verify the printer name and establish the
  4336. * print connection without involving the print setup box.
  4337. */
  4338. status = _DtPrintVerifyXPrinter(NULL,
  4339. print_data->printer_name,
  4340. &new_printer_spec,
  4341. &new_display
  4342. #if 0 && defined(PRINTING_SUPPORTED)
  4343. ,&new_context
  4344. #endif /* PRINTING_SUPPORTED */
  4345. );
  4346. if(status == DtPRINT_SUCCESS)
  4347. {
  4348. print_data->print_display = new_display;
  4349. #if 0 && defined(PRINTING_SUPPORTED)
  4350. print_data->print_context = new_context;
  4351. #endif /* PRINTING_SUPPORTED */
  4352. }
  4353. if(new_printer_spec != (String)NULL)
  4354. {
  4355. XtFree(print_data->printer_name);
  4356. print_data->printer_name = new_printer_spec;
  4357. }
  4358. return status;
  4359. }
  4360. else
  4361. {
  4362. DtPrintSetupData psd;
  4363. XtEnum status;
  4364. _DtPrintWidgetToAppContext((Widget)psub);
  4365. /*
  4366. * return if the passed widget's setup mode is not Xp
  4367. */
  4368. if(PSUB_PrintSetupMode(psub) != DtPRINT_SETUP_XP)
  4369. return DtPRINT_BAD_PARM;
  4370. /*
  4371. * intialize an internal version of the print setup data struct
  4372. */
  4373. memset(&psd, 0, sizeof(DtPrintSetupData));
  4374. /*
  4375. * get the latest printer name from the widget
  4376. */
  4377. _DtPrintAppLock(app);
  4378. SynthGetPrinterName(psub);
  4379. /*
  4380. * check to see if the passed printer name is different than
  4381. * the psub printer name
  4382. */
  4383. if(print_data->printer_name != (String)NULL)
  4384. {
  4385. if((PSUB_PrinterName(psub) == NULL)
  4386. ? True
  4387. : strcmp(print_data->printer_name, PSUB_PrinterName(psub)) != 0)
  4388. {
  4389. /*
  4390. * if different, set the passed printer name into the
  4391. * passed print setup box widget
  4392. */
  4393. SynthSetPrinterName(psub,
  4394. XtNewString(print_data->printer_name),
  4395. PSUB_PrinterName(psub));
  4396. }
  4397. }
  4398. /*
  4399. * establish a connection to the X printer
  4400. */
  4401. psd.messages_hint = DtPRINT_HINT_NO_MESSAGES;
  4402. status = EstablishPrinter(psub, &psd);
  4403. if(status == DtPRINT_SUCCESS)
  4404. {
  4405. /*
  4406. * set printing attributes
  4407. */
  4408. SetPrintAttributes(psub);
  4409. /*
  4410. * setup the destination info
  4411. */
  4412. SetPSDDestination(psub, &psd);
  4413. /*
  4414. * update the passed print setup data struct based on the
  4415. * internal version of the print setup data struct
  4416. */
  4417. DtPrintCopySetupData(print_data, &psd);
  4418. }
  4419. else
  4420. {
  4421. /*
  4422. * Unable to establish the printer connection; manage the
  4423. * print setup box in order to present the error box created
  4424. * by EstablishPrinter() to the user, allowing the user to
  4425. * select a new printer or cancel.
  4426. */
  4427. XtManageChild((Widget)psub);
  4428. /*
  4429. * if the default verifyPrintProc created an error box,
  4430. * display it. If the app installed its own verify proc, the
  4431. * app will need to check the return status of
  4432. * DtPrintFillSetupData, and manage its error dialog itself.
  4433. */
  4434. _DtPrintDefProcManageErrorBox(&PSUB_DefaultProcData(psub));
  4435. }
  4436. _DtPrintAppUnlock(app);
  4437. return status;
  4438. }
  4439. }
  4440. /*
  4441. * ------------------------------------------------------------------------
  4442. * Name: DtPrintFreeSetupData
  4443. *
  4444. * Description:
  4445. *
  4446. * DtPrintFreeSetupData calls XtFree to deallocate memory pointed to
  4447. * by elements of the DtPrintSetupData structure indicated by
  4448. * 'target'. 'target' is then re-initialized to zeros.
  4449. *
  4450. * Arguments:
  4451. *
  4452. * target
  4453. * points to the DtPrintSetupData structure whose elements are to
  4454. * be freed.
  4455. *
  4456. * Return value:
  4457. *
  4458. * None.
  4459. *
  4460. */
  4461. void DtPrintFreeSetupData(
  4462. DtPrintSetupData* target)
  4463. {
  4464. XtFree(target->printer_name);
  4465. XtFree(target->dest_info);
  4466. memset(target, 0, sizeof(DtPrintSetupData));
  4467. }
  4468. /*
  4469. * ------------------------------------------------------------------------
  4470. * Name: DtPrintResetConnection
  4471. *
  4472. * Arguments:
  4473. *
  4474. * psub
  4475. * The DtPrintSetupBox widget ID.
  4476. *
  4477. * mode
  4478. * Indicates whether DtPrintResetConnection should close the X
  4479. * print server connection, or simply cause the DtPrintSetupBox
  4480. * to cease managing the connection.
  4481. *
  4482. * Description:
  4483. *
  4484. * DtPrintResetConnection is intended to be used by applications that
  4485. * fork a child process to perform the print rendering
  4486. * operation. After the fork is performed, the parent process will
  4487. * close its X print server connection, and maintain its connection
  4488. * to the video X server. The forked child on the other hand will
  4489. * close its video X server connection and perform the rendering
  4490. * operation on the X print server connection.
  4491. *
  4492. * Valid values for the 'mode' parameter are:
  4493. *
  4494. * DtPRINT_CLOSE_CONNECTION
  4495. * Set by the parent process when the application forks a
  4496. * child to perform the print rendering. This will cause the
  4497. * DtNclosePrintDisplayCallback list set for the passed
  4498. * DtPrintSetupBox to be called.
  4499. *
  4500. * DtPRINT_RELEASE_CONNECTION
  4501. * Set when the application wishes to destroy the
  4502. * DtPrintSetupBox widget instance and still perform print
  4503. * rendering using the X print server connection initiated by
  4504. * the widget. For example, the child process of an
  4505. * application that forks to perform print rendering will
  4506. * close the video display connection (thereby destroying the
  4507. * DtPrintSetupBox widget) prior to print rendering.
  4508. *
  4509. * Return value:
  4510. *
  4511. * DtPRINT_SUCCESS
  4512. * DtPrintResetConnection was successful.
  4513. *
  4514. * DtPRINT_NO_CONNECTION
  4515. * An open X print server connection is not currently being
  4516. * managed by the DtPrintSetupBox.
  4517. *
  4518. * DtPRINT_BAD_PARM
  4519. * The value passed for wid is NULL, or an invalid mode was
  4520. * passed.
  4521. *
  4522. */
  4523. XtEnum
  4524. DtPrintResetConnection(
  4525. Widget w,
  4526. DtPrintResetConnectionMode mode)
  4527. {
  4528. DtPrintSetupBoxWidget psub = (DtPrintSetupBoxWidget)w;
  4529. _DtPrintWidgetToAppContext((Widget)psub);
  4530. if(psub == (DtPrintSetupBoxWidget)NULL)
  4531. return DtPRINT_BAD_PARM;
  4532. _DtPrintAppLock(app);
  4533. if(PSUB_PrintSetupMode(psub) != DtPRINT_SETUP_XP)
  4534. {
  4535. _DtPrintAppUnlock(app);
  4536. return DtPRINT_BAD_PARM;
  4537. }
  4538. if(PSUB_Display(psub) == (Display*)NULL)
  4539. {
  4540. _DtPrintAppUnlock(app);
  4541. return DtPRINT_NO_CONNECTION;
  4542. }
  4543. switch(mode)
  4544. {
  4545. case DtPRINT_RELEASE_CONNECTION:
  4546. /*
  4547. * simply disavow knowledge of the X print connection
  4548. */
  4549. PSUB_Display(psub) = (Display*)NULL;
  4550. #if 0 && defined(PRINTING_SUPPORTED)
  4551. PSUB_Context(psub) = (XPContext)NULL;
  4552. #endif /* PRINTING_SUPPORTED */
  4553. break;
  4554. case DtPRINT_CLOSE_CONNECTION:
  4555. /*
  4556. * call the widget's close print connection routine
  4557. */
  4558. ClosePrintConnection(psub, PSUB_PrinterName(psub), True);
  4559. break;
  4560. default:
  4561. _DtPrintAppUnlock(app);
  4562. return DtPRINT_BAD_PARM;
  4563. }
  4564. /*
  4565. * cause the printer to be re-verified if new connection is
  4566. * is required later, and return
  4567. */
  4568. PSUB_VerifyPrinterState(psub) = DtPRINT_NOT_VERIFIED;
  4569. _DtPrintAppUnlock(app);
  4570. return DtPRINT_SUCCESS;
  4571. }