PrinterBox.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345
  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. /* $XConsortium: PrinterBox.c /main/10 1996/11/20 12:59:48 cde-hp $ */
  24. /*
  25. * dtpdm/PrinterBox.c
  26. */
  27. /*
  28. * (c) Copyright 1996 Digital Equipment Corporation.
  29. * (c) Copyright 1996 Hewlett-Packard Company.
  30. * (c) Copyright 1996 International Business Machines Corp.
  31. * (c) Copyright 1996 Sun Microsystems, Inc.
  32. * (c) Copyright 1996 Novell, Inc.
  33. * (c) Copyright 1996 FUJITSU LIMITED.
  34. * (c) Copyright 1996 Hitachi.
  35. */
  36. #include <Xm/XmAll.h>
  37. #include <Dt/DtNlUtils.h>
  38. #include "PrinterBox.h"
  39. #include "PdmMsgs.h"
  40. #ifndef CDE_INSTALLATION_TOP
  41. #define CDE_INSTALLATION_TOP "/usr/dt"
  42. #endif
  43. #define ICON_INSTALL_DIR CDE_INSTALLATION_TOP "/appconfig/icons/C/"
  44. #ifndef MAX
  45. # define MAX(a, b) ((a) > (b) ? (a) : (b))
  46. #endif /* ! MAX */
  47. /*
  48. * PrinterBox-specific data - PdmSetupBox.subclass_data
  49. */
  50. typedef struct
  51. {
  52. /*
  53. * child controls
  54. */
  55. struct _OrientCtl* orient_ctl;
  56. struct _PlexCtl* plex_ctl;
  57. struct _TrayCtl* tray_ctl;
  58. struct _SizeCtl* size_ctl;
  59. /*
  60. * attribute values
  61. */
  62. const char* printer_model;
  63. char* document_format;
  64. PdmOidList* document_attrs_supported;
  65. PdmOidList* orientations_supported;
  66. PdmOid orientation;
  67. PdmOidList* plexes_supported;
  68. PdmOid plex;
  69. PdmOid default_input_tray;
  70. PdmOid default_medium;
  71. PdmOidList* input_trays;
  72. PdmOidList* tray_sizes;
  73. PdmOidLinkedList* sizes_supported;
  74. } PdmPrinterBoxData;
  75. /*
  76. * orientations control
  77. */
  78. typedef struct _OrientCtl
  79. {
  80. Widget widget;
  81. Widget frame_label;
  82. Widget option_menu;
  83. Widget icon_label;
  84. int selected_item;
  85. const PdmOidList* orientations_supported;
  86. PdmOidList* dummy_orientations_supported;
  87. struct _PdmPixmapList* pixmap_list;
  88. struct _PdmPixmapList* i_pixmap_list;
  89. struct _PlexCtl* plex_ctl;
  90. } OrientCtl;
  91. /*
  92. * plexes control
  93. */
  94. typedef struct _PlexCtl
  95. {
  96. Widget widget;
  97. Widget frame_label;
  98. Widget option_menu;
  99. Widget icon_label;
  100. int selected_item;
  101. const PdmOidList* plexes_supported;
  102. PdmOidList* dummy_plexes_supported;
  103. struct _PdmPixmapList** pixmap_list_ptr;
  104. struct _PdmPixmapList* portrait_pixmap_list;
  105. struct _PdmPixmapList* landscape_pixmap_list;
  106. struct _PdmPixmapList** i_pixmap_list_ptr;
  107. struct _PdmPixmapList* i_portrait_pixmap_list;
  108. struct _PdmPixmapList* i_landscape_pixmap_list;
  109. } PlexCtl;
  110. /*
  111. * input trays control
  112. */
  113. typedef struct _TrayCtl
  114. {
  115. Widget widget;
  116. Widget frame_label;
  117. Widget option_menu;
  118. int selected_item;
  119. const PdmOidList* input_trays;
  120. const PdmOidList* tray_sizes;
  121. struct _SizeCtl* size_ctl;
  122. } TrayCtl;
  123. /*
  124. * page size control
  125. */
  126. typedef struct _SizeCtlSortRec
  127. {
  128. const char* str;
  129. PdmOid oid;
  130. } SizeCtlSortRec, *SizeCtlSortList;
  131. typedef struct _SizeCtl
  132. {
  133. Widget widget;
  134. Widget frame_label;
  135. Widget list_box;
  136. Widget radio_box;
  137. Widget ready_radio;
  138. Widget supported_radio;
  139. PdmOidList* sizes_ready;
  140. PdmOidList* sizes_supported;
  141. PdmOid selected_size;
  142. enum {
  143. SIZECTL_UNSUPPORTED,
  144. SIZECTL_SIZES_READY,
  145. SIZECTL_SIZES_SUPPORTED } selected_list;
  146. Boolean single_size_mode;
  147. XmStringTable sizes_ready_xmstr;
  148. XmStringTable sizes_supported_xmstr;
  149. } SizeCtl;
  150. /*
  151. * list of pixmaps
  152. */
  153. typedef struct _PdmPixmapList
  154. {
  155. Pixmap* pixmap;
  156. char** image_name;
  157. int count;
  158. Screen* screen;
  159. Pixel foreground, background;
  160. Pixmap stipple;
  161. } PdmPixmapList;
  162. /*
  163. * PrinterBox-specific fallback resources
  164. */
  165. static String PdmPrinterBoxFallbackResources[] =
  166. {
  167. "*PrinterSetup*LoadedAllowed.button_0.labelString: Loaded in Printer",
  168. "*PrinterSetup*LoadedAllowed.button_1.labelString: All Sizes",
  169. "*PrinterSetup*OrientationLabel.labelString: Page Orientation",
  170. "*PrinterSetup*PageSizeLabel.labelString: Page Size",
  171. "*PrinterSetup*PlexLabel.labelString: Printed Sides",
  172. "*PrinterSetup*DocumentFormatLabel.labelString: Format:",
  173. "*PrinterSetup*PrinterModelLabel.labelString: Printer Model:",
  174. "*PrinterSetup*TrayLabel.labelString: Tray",
  175. "*PrinterSetup.locationId: PrinterSetup",
  176. "*PrinterSetup*OrientCtlTop.PortraitIconFileName: "
  177. ICON_INSTALL_DIR "portrait.pm",
  178. "*PrinterSetup*OrientCtlTop.LandscapeIconFileName: "
  179. ICON_INSTALL_DIR "landscap.pm",
  180. "*PrinterSetup*OrientCtlTop.ReversePortraitIconFileName: "
  181. ICON_INSTALL_DIR "rportrai.pm",
  182. "*PrinterSetup*OrientCtlTop.ReverseLandscapeIconFileName: "
  183. ICON_INSTALL_DIR "rlandsca.pm",
  184. "*PrinterSetup*PlexCtlTop.SimplexPortraitIconFileName: "
  185. ICON_INSTALL_DIR "psimplex.pm",
  186. "*PrinterSetup*PlexCtlTop.SimplexLandscapeIconFileName: "
  187. ICON_INSTALL_DIR "lsimplex.pm",
  188. "*PrinterSetup*PlexCtlTop.DuplexPortraitIconFileName: "
  189. ICON_INSTALL_DIR "pduplex.pm",
  190. "*PrinterSetup*PlexCtlTop.DuplexLandscapeIconFileName: "
  191. ICON_INSTALL_DIR "lduplex.pm",
  192. "*PrinterSetup*PlexCtlTop.TumblePortraitIconFileName: "
  193. ICON_INSTALL_DIR "ptumble.pm",
  194. "*PrinterSetup*PlexCtlTop.TumbleLandscapeIconFileName: "
  195. ICON_INSTALL_DIR "ltumble.pm",
  196. "*PrinterTab.compoundString: Printer",
  197. "*PrinterTab.labelString: Printer"
  198. };
  199. /*
  200. * Printer Setup Box static function declarations
  201. */
  202. static void PdmPrinterBoxDelete(PdmSetupBox* me);
  203. static void PdmPrinterBoxCreate(PdmSetupBox* me, Widget parent);
  204. static PdmStatus PdmPrinterBoxVerifyAttr(PdmSetupBox* me, PdmXp* pdm_xp);
  205. static void PdmPrinterBoxGetAttr(PdmSetupBox* me, PdmXp* pdm_xp);
  206. static void PdmPrinterBoxSetAttr(PdmSetupBox* me, PdmXp* pdm_xp);
  207. static Widget PdmPrinterBoxCreateWindow(PdmSetupBox* me, Widget parent);
  208. static void PdmPrinterBoxResizeCB(Widget w,
  209. XtPointer client_data,
  210. XtPointer call_data);
  211. /*
  212. * Orientation Control methods
  213. */
  214. static OrientCtl* OrientCtlNew(PlexCtl* plex_ctl);
  215. static void OrientCtlDelete(OrientCtl* me);
  216. static void OrientCtlCreate(OrientCtl* me,
  217. Widget parent,
  218. PdmOid orientation,
  219. const PdmOidList* document_attrs_supported,
  220. const PdmOidList* orientations_supported);
  221. static void OrientCtlCreateWindow(OrientCtl* me, Widget parent);
  222. #define OrientCtlGetWidget(me) ((me)->widget)
  223. static void OrientCtlCreatePulldown(OrientCtl* me);
  224. static void OrientCtlDisable(OrientCtl* me);
  225. static void OrientCtlUpdateIcon(OrientCtl* me);
  226. static PdmOid OrientCtlGetOrientation(OrientCtl* me);
  227. static void OrientCtlResizeCB(Widget w,
  228. XtPointer client_data, XtPointer call_data);
  229. static void OrientCtlSetSelectedItem(OrientCtl* me, int selected_item);
  230. static void OrientCtlSelectCB(Widget w, XtPointer client_d, XtPointer call_d);
  231. static void OrientCtlInitPixmapList(OrientCtl* me);
  232. /*
  233. * Plex Control methods
  234. */
  235. static PlexCtl* PlexCtlNew();
  236. static void PlexCtlDelete(PlexCtl* me);
  237. static void PlexCtlCreate(PlexCtl* me,
  238. Widget parent,
  239. PdmOid plex,
  240. const PdmOidList* document_attrs_supported,
  241. const PdmOidList* plexes_supported);
  242. static void PlexCtlCreateWindow(PlexCtl* me, Widget parent);
  243. static void PlexCtlDisable(PlexCtl* me);
  244. #define PlexCtlGetWidget(me) ((me)->widget)
  245. static void PlexCtlCreatePulldown(PlexCtl* me);
  246. static void PlexCtlUpdateIcon(PlexCtl* me);
  247. static PdmOid PlexCtlGetPlex(PlexCtl* me);
  248. static void PlexCtlResizeCB(Widget w,
  249. XtPointer client_data, XtPointer call_data);
  250. static void PlexCtlSetSelectedItem(PlexCtl* me, int selected_item);
  251. static void PlexCtlSelectCB(Widget w, XtPointer client_d, XtPointer call_d);
  252. static void PlexCtlSetOrientation(PlexCtl* me, PdmOid orientation);
  253. static void PlexCtlInitPixmapLists(PlexCtl* me);
  254. /*
  255. * Tray Control methods
  256. */
  257. static TrayCtl* TrayCtlNew(SizeCtl* size_ctl);
  258. static void TrayCtlDelete(TrayCtl* me);
  259. static void TrayCtlCreate(TrayCtl* me,
  260. Widget parent,
  261. PdmOid default_input_tray,
  262. PdmOid default_medium,
  263. const PdmOidList* document_attrs_supported,
  264. const PdmOidList* input_trays,
  265. const PdmOidList* tray_sizes);
  266. static void TrayCtlCreateWindow(TrayCtl* me, Widget parent);
  267. #define TrayCtlGetWidget(me) ((me)->widget)
  268. static PdmOid TrayCtlGetTray(TrayCtl* me);
  269. static void TrayCtlDisable(TrayCtl* me);
  270. static void TrayCtlResizeCB(Widget w,
  271. XtPointer client_data, XtPointer call_data);
  272. static void TrayCtlCreatePulldown(TrayCtl* me);
  273. static void TrayCtlSetSelectedItem(TrayCtl* me, int selected_item);
  274. static void TrayCtlSelectCB(Widget w, XtPointer client_d, XtPointer call_d);
  275. /*
  276. * Size Control methods
  277. */
  278. static SizeCtl* SizeCtlNew();
  279. static void SizeCtlDelete(SizeCtl* me);
  280. static int SizeCtlStrColl(const void* e1, const void* e2);
  281. static void SizeCtlSetSizeLists(PdmOidList** oids,
  282. XmStringTable* xmstrs,
  283. PdmOidLinkedList* oids_ll);
  284. static void SizeCtlCreate(SizeCtl* me,
  285. Widget parent,
  286. PdmOid default_medium,
  287. const PdmOidList* document_attrs_supported,
  288. const PdmOidList* tray_sizes,
  289. PdmOidLinkedList* sizes_supported);
  290. static void SizeCtlCreateWindow(SizeCtl* me, Widget parent);
  291. #define SizeCtlGetWidget(me) ((me)->widget)
  292. static void SizeCtlUpdate(SizeCtl* me);
  293. static PdmOid SizeCtlGetSize(SizeCtl* me);
  294. static void SizeCtlResizeCB(Widget w,
  295. XtPointer client_data, XtPointer call_data);
  296. static void SizeCtlSetSingleSizeMode(SizeCtl* me, PdmOid size);
  297. static void SizeCtlSetMultiSizeMode(SizeCtl* me);
  298. static void SizeCtlReadyChangedCB(Widget w,
  299. XtPointer client_data, XtPointer call_data);
  300. static void SizeCtlSupportedChangedCB(Widget w,
  301. XtPointer client_data,
  302. XtPointer call_data);
  303. static void SizeCtlSelectCB(Widget w,
  304. XtPointer client_data,
  305. XtPointer call_data);
  306. /*
  307. * pixmap list functions
  308. */
  309. static PdmPixmapList* PdmPixmapListNew(int count, Widget w, Boolean stipple);
  310. static void PdmPixmapListDelete(PdmPixmapList* me);
  311. static Pixmap PdmPixmapListGetPixmap(PdmPixmapList* me, int i);
  312. #define PdmPixmapListCount(me) ((me)->count)
  313. static void PdmPixmapListSetImageName(PdmPixmapList* me,
  314. const char* name,
  315. int i);
  316. /*
  317. * option menu list creation function
  318. */
  319. static Widget
  320. CreateOptionMenuPulldown(String pulldown_name,
  321. Widget option_menu,
  322. XtCallbackProc activate_proc,
  323. XtPointer user_data,
  324. XmString* item_list,
  325. int item_count,
  326. int initial_item);
  327. /*
  328. * XmString / oid utilities
  329. */
  330. static XmString* CreateXmStringsFromOidList(const PdmOidList* list);
  331. static void FreeXmStringList(XmString* list, int count);
  332. /*
  333. * utility to help determine maximum icon size
  334. */
  335. static void
  336. IconMaxDimension(Widget icon_label,
  337. PdmPixmapList* pixmap_list, int i,
  338. Dimension* max_width, Dimension* max_height);
  339. /*
  340. * utility to position list box initial selection
  341. */
  342. static void SetListBoxSelection(Widget list_box, int position);
  343. /*
  344. * utility to grab icon file names out of the Xrm resource database
  345. */
  346. static String GetIconFileName(Widget w, String resource_name);
  347. /*
  348. * ------------------------------------------------------------------------
  349. * Name: PdmPrinterBoxNew
  350. *
  351. * Description:
  352. *
  353. * Creates a new PdmPrinterBox (PdmSetupBox) instance structure.
  354. *
  355. * Return value:
  356. *
  357. * The new PdmPrinterBox instance structure.
  358. *
  359. */
  360. PdmSetupBox*
  361. PdmPrinterBoxNew(void)
  362. {
  363. PdmSetupBox* me = (PdmSetupBox*)XtCalloc(1, sizeof(PdmSetupBox));
  364. PdmPrinterBoxData* data;
  365. me->delete_proc = PdmPrinterBoxDelete;
  366. me->create_proc = PdmPrinterBoxCreate;
  367. me->verify_attr_proc = PdmPrinterBoxVerifyAttr;
  368. me->get_attr_proc = PdmPrinterBoxGetAttr;
  369. me->set_attr_proc = PdmPrinterBoxSetAttr;
  370. me->fallback_resources = PdmPrinterBoxFallbackResources;
  371. me->fallback_resources_count = XtNumber(PdmPrinterBoxFallbackResources);
  372. me->tab_name = "PrinterTab";
  373. me->subclass_data = (XtPointer)XtCalloc(1, sizeof(PdmPrinterBoxData));
  374. data = (PdmPrinterBoxData*)me->subclass_data;
  375. data->plex_ctl = PlexCtlNew();
  376. data->orient_ctl = OrientCtlNew(data->plex_ctl);
  377. data->size_ctl = SizeCtlNew();
  378. data->tray_ctl = TrayCtlNew(data->size_ctl);
  379. return me;
  380. }
  381. /*
  382. * ------------------------------------------------------------------------
  383. * Name: PdmPrinterBoxDelete
  384. *
  385. * Description:
  386. *
  387. * Frees the passed PdmPrinterBox (PdmSetupBox) instance structure.
  388. *
  389. * Return value:
  390. *
  391. * None.
  392. *
  393. */
  394. static void
  395. PdmPrinterBoxDelete(PdmSetupBox* me)
  396. {
  397. if(me != (PdmSetupBox*)NULL)
  398. {
  399. PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
  400. XtFree(data->document_format);
  401. PdmOidListDelete(data->document_attrs_supported);
  402. PdmOidListDelete(data->orientations_supported);
  403. PdmOidListDelete(data->plexes_supported);
  404. PdmOidListDelete(data->input_trays);
  405. PdmOidListDelete(data->tray_sizes);
  406. PdmOidLinkedListDelete(data->sizes_supported);
  407. OrientCtlDelete(data->orient_ctl);
  408. PlexCtlDelete(data->plex_ctl);
  409. SizeCtlDelete(data->size_ctl);
  410. TrayCtlDelete(data->tray_ctl);
  411. XtFree((char*)data);
  412. XtFree((char*)me);
  413. }
  414. }
  415. /*
  416. * ------------------------------------------------------------------------
  417. * Name: PdmPrinterBoxCreate
  418. *
  419. * Description:
  420. *
  421. * Creates the PDM Printer options setup box.
  422. *
  423. * Return value:
  424. *
  425. * The passed PdmPrinterBox (PdmSetupBox) instance structure.
  426. *
  427. */
  428. static void
  429. PdmPrinterBoxCreate(PdmSetupBox* me, Widget parent)
  430. {
  431. me->widget = PdmPrinterBoxCreateWindow(me, parent);
  432. XtManageChild(me->widget);
  433. }
  434. /*
  435. * ------------------------------------------------------------------------
  436. * Name: PdmPrinterBoxVerifyAttr
  437. *
  438. * Description:
  439. *
  440. *
  441. *
  442. * Return value:
  443. *
  444. * PDM_SUCCESS if all of the Printer options selected are OK.
  445. *
  446. * PDM_FAILURE if any of the Printer options are invalid.
  447. *
  448. */
  449. static PdmStatus
  450. PdmPrinterBoxVerifyAttr(PdmSetupBox* me, PdmXp* pdm_xp)
  451. {
  452. return PDM_SUCCESS;
  453. }
  454. /*
  455. * ------------------------------------------------------------------------
  456. * Name: PdmPrinterBoxGetAttr
  457. *
  458. * Description:
  459. *
  460. *
  461. *
  462. * Return value:
  463. *
  464. * None.
  465. *
  466. */
  467. static void
  468. PdmPrinterBoxGetAttr(PdmSetupBox* me, PdmXp* pdm_xp)
  469. {
  470. PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
  471. const char* strval;
  472. PdmOidMediumSS* medium_ss_supported;
  473. PdmOidTrayMediumList* input_trays_medium = NULL;
  474. #if 0 && defined(PRINTING_SUPPORTED)
  475. /*
  476. * printer model description
  477. */
  478. data->printer_model =
  479. PdmXpGetStringValue(pdm_xp, XPPrinterAttr, pdmoid_att_printer_model);
  480. /*
  481. * document format
  482. */
  483. strval = PdmXpGetStringValue(pdm_xp, XPDocAttr,
  484. pdmoid_att_document_format);
  485. data->document_format = PdmOidDocumentFormatParse(strval);
  486. #endif /* PRINTING_SUPPORTED */
  487. if((char*)NULL == data->document_format)
  488. {
  489. /*
  490. * document format not specified, try to obtain
  491. * document-formats-supported, and obtain up the default from it
  492. */
  493. #if 0 && defined(PRINTING_SUPPORTED)
  494. strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
  495. pdmoid_att_document_formats_supported);
  496. data->document_format = PdmOidDocumentFormatDefault(strval);
  497. #endif /* PRINTING_SUPPORTED */
  498. }
  499. /*
  500. * document attributes supported
  501. */
  502. #if 0 && defined(PRINTING_SUPPORTED)
  503. strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
  504. pdmoid_att_document_attributes_supported);
  505. data->document_attrs_supported = PdmOidListNew(strval);
  506. /*
  507. * content orientation supported
  508. */
  509. strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
  510. pdmoid_att_content_orientations_supported);
  511. data->orientations_supported = PdmOidListNew(strval);
  512. /*
  513. * orientation
  514. */
  515. data->orientation =
  516. PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_content_orientation);
  517. /*
  518. * plexes supported
  519. */
  520. strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
  521. pdmoid_att_plexes_supported);
  522. data->plexes_supported = PdmOidListNew(strval);
  523. /*
  524. * plex
  525. */
  526. data->plex = PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_plex);
  527. /*
  528. * default input tray, default medium
  529. */
  530. data->default_input_tray =
  531. PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_default_input_tray);
  532. data->default_medium =
  533. PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_default_medium);
  534. /*
  535. * medium source sizes supported
  536. */
  537. strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
  538. pdmoid_att_medium_source_sizes_supported);
  539. medium_ss_supported = PdmOidMediumSSNew(strval);
  540. /*
  541. * input trays medium
  542. */
  543. strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
  544. pdmoid_att_input_trays_medium);
  545. input_trays_medium = PdmOidTrayMediumListNew(strval);
  546. /*
  547. * build input trays and page sizes ready lists
  548. */
  549. PdmOidMediumSSGetTraysSizes(medium_ss_supported, input_trays_medium,
  550. &data->input_trays, &data->tray_sizes);
  551. /*
  552. * build list of supported page sizes
  553. */
  554. data->sizes_supported = PdmOidMediumSSGetAllSizes(medium_ss_supported);
  555. /*
  556. * clean up
  557. */
  558. PdmOidMediumSSDelete(medium_ss_supported);
  559. PdmOidTrayMediumListDelete(input_trays_medium);
  560. #endif /* PRINTING_SUPPORTED */
  561. }
  562. /*
  563. * ------------------------------------------------------------------------
  564. * Name: PdmPrinterBoxSetAttr
  565. *
  566. * Description:
  567. *
  568. *
  569. *
  570. * Return value:
  571. *
  572. * None.
  573. *
  574. */
  575. static void
  576. PdmPrinterBoxSetAttr(PdmSetupBox* me, PdmXp* pdm_xp)
  577. {
  578. #if 0 && defined(PRINTING_SUPPORTED)
  579. PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
  580. /*
  581. * orientation
  582. */
  583. PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_content_orientation,
  584. OrientCtlGetOrientation(data->orient_ctl));
  585. /*
  586. * plex
  587. */
  588. PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_plex,
  589. PlexCtlGetPlex(data->plex_ctl));
  590. /*
  591. * page size
  592. */
  593. PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_default_medium,
  594. SizeCtlGetSize(data->size_ctl));
  595. /*
  596. * input tray
  597. */
  598. PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_default_input_tray,
  599. TrayCtlGetTray(data->tray_ctl));
  600. #endif /* PRINTING_SUPPORTED */
  601. }
  602. /*
  603. * ------------------------------------------------------------------------
  604. * Name: PdmPrinterBoxCreateWindow
  605. *
  606. * Description:
  607. *
  608. * Creates the PDM Printer options setup box window.
  609. *
  610. * Return value:
  611. *
  612. * Widget ID of the new Printer setup box.
  613. *
  614. */
  615. static Widget
  616. PdmPrinterBoxCreateWindow(PdmSetupBox* me, Widget parent)
  617. {
  618. PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
  619. Widget manager;
  620. Widget row;
  621. Widget w;
  622. Widget draw_area;
  623. XmString label;
  624. /*
  625. * create the manager for the Printer Setup Box
  626. */
  627. manager = XtVaCreateManagedWidget(
  628. "PrinterSetup",
  629. xmRowColumnWidgetClass,
  630. parent,
  631. NULL);
  632. /*
  633. * create the printer model row
  634. */
  635. if(data->printer_model != (const char*)NULL)
  636. {
  637. char* desc;
  638. char* ptr;
  639. row = XtVaCreateManagedWidget(
  640. "PrinterModelRow",
  641. xmRowColumnWidgetClass,
  642. manager,
  643. XmNorientation, XmHORIZONTAL,
  644. NULL);
  645. /*
  646. * create the printer model label
  647. */
  648. w = XtVaCreateManagedWidget("PrinterModelLabel",
  649. xmLabelGadgetClass,
  650. row,
  651. NULL);
  652. /*
  653. * create the printer model using just the 1st line
  654. */
  655. desc = XtNewString(data->printer_model);
  656. ptr = Dt_strchr(desc, '\n');
  657. if(ptr != NULL)
  658. *ptr = '\0';
  659. label = XmStringCreateLocalized(desc);
  660. XtFree(desc);
  661. w = XtVaCreateManagedWidget("PrinterModel",
  662. xmLabelGadgetClass,
  663. row,
  664. XmNlabelString, label,
  665. NULL);
  666. XmStringFree(label);
  667. }
  668. /*
  669. * create the document format row
  670. */
  671. if((char*)NULL != data->document_format)
  672. {
  673. /*
  674. * create the document format row
  675. */
  676. row = XtVaCreateManagedWidget(
  677. "DocumentFormatRow",
  678. xmRowColumnWidgetClass,
  679. manager,
  680. XmNorientation, XmHORIZONTAL,
  681. NULL);
  682. /*
  683. * create the document format label
  684. */
  685. w = XtVaCreateManagedWidget("DocumentFormatLabel",
  686. xmLabelGadgetClass,
  687. row,
  688. NULL);
  689. /*
  690. * create the document format
  691. */
  692. label = XmStringCreateLocalized(data->document_format);
  693. w = XtVaCreateManagedWidget("DocumentFormat",
  694. xmLabelGadgetClass,
  695. row,
  696. XmNlabelString, label,
  697. NULL);
  698. XmStringFree(label);
  699. }
  700. /*
  701. * orientation / plex / tray / sides
  702. */
  703. draw_area = XtVaCreateWidget("PrinterSetupControls",
  704. xmDrawingAreaWidgetClass,
  705. manager,
  706. NULL);
  707. XtAddCallback(draw_area, XmNresizeCallback,
  708. PdmPrinterBoxResizeCB, (XtPointer)me);
  709. /*
  710. * orientation control
  711. */
  712. OrientCtlCreate(data->orient_ctl,
  713. draw_area,
  714. data->orientation,
  715. data->document_attrs_supported,
  716. data->orientations_supported);
  717. /*
  718. * page size control
  719. */
  720. SizeCtlCreate(data->size_ctl,
  721. draw_area,
  722. data->default_medium,
  723. data->document_attrs_supported,
  724. data->tray_sizes,
  725. data->sizes_supported);
  726. /*
  727. * plex control
  728. */
  729. PlexCtlCreate(data->plex_ctl,
  730. draw_area,
  731. data->plex,
  732. data->document_attrs_supported,
  733. data->plexes_supported);
  734. /*
  735. * input tray control
  736. */
  737. TrayCtlCreate(data->tray_ctl,
  738. draw_area,
  739. data->default_input_tray,
  740. data->default_medium,
  741. data->document_attrs_supported,
  742. data->input_trays,
  743. data->tray_sizes);
  744. XtManageChild(draw_area);
  745. /*
  746. * return the new Printer Setup Box
  747. */
  748. return manager;
  749. }
  750. /*
  751. * ------------------------------------------------------------------------
  752. * Name: PdmPrinterBoxResizeCB
  753. *
  754. * Description:
  755. *
  756. *
  757. *
  758. * Return value:
  759. *
  760. * None.
  761. *
  762. */
  763. static void
  764. PdmPrinterBoxResizeCB(Widget w,
  765. XtPointer client_data,
  766. XtPointer call_data)
  767. {
  768. PdmSetupBox* me = (PdmSetupBox*)client_data;
  769. PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
  770. typedef struct {
  771. XtArgVal /* Position */ x, y;
  772. XtArgVal /* Dimension */ width, height;
  773. } PdmRect;
  774. PdmRect rt, rs, ro, rp, c1, c2, r1, r2;
  775. /*
  776. * retrieve child dimensions
  777. */
  778. XtVaGetValues(TrayCtlGetWidget(data->tray_ctl),
  779. XmNx, &rt.x,
  780. XmNy, &rt.y,
  781. XmNwidth, &rt.width,
  782. XmNheight, &rt.height,
  783. NULL);
  784. XtVaGetValues(SizeCtlGetWidget(data->size_ctl),
  785. XmNx, &rs.x,
  786. XmNy, &rs.y,
  787. XmNwidth, &rs.width,
  788. XmNheight, &rs.height,
  789. NULL);
  790. XtVaGetValues(OrientCtlGetWidget(data->orient_ctl),
  791. XmNx, &ro.x,
  792. XmNy, &ro.y,
  793. XmNwidth, &ro.width,
  794. XmNheight, &ro.height,
  795. NULL);
  796. XtVaGetValues(PlexCtlGetWidget(data->plex_ctl),
  797. XmNx, &rp.x,
  798. XmNy, &rp.y,
  799. XmNwidth, &rp.width,
  800. XmNheight, &rp.height,
  801. NULL);
  802. /*
  803. * calculate rows and columns dimensions
  804. */
  805. r1.x = r2.x = c1.x = 0;
  806. r1.y = c1.y = c2.y = 0;
  807. r1.height = MAX(ro.height, rp.height);
  808. r2.height = MAX(rs.height, rt.height);
  809. c1.width = MAX(ro.width, rs.width);
  810. c2.width = MAX(rp.width, rt.width);
  811. r2.y = r1.height + 5;
  812. c2.x = c1.width + 3;
  813. r1.width = r2.width = c2.x + c2.width;
  814. c1.height = c2.height = r2.y + r2.height;
  815. /*
  816. * position the children
  817. */
  818. XtVaSetValues(OrientCtlGetWidget(data->orient_ctl),
  819. XmNx, c1.x,
  820. XmNy, r1.y,
  821. XmNwidth, c1.width,
  822. XmNheight, r1.height,
  823. NULL);
  824. XtVaSetValues(PlexCtlGetWidget(data->plex_ctl),
  825. XmNx, c2.x,
  826. XmNy, r1.y,
  827. XmNwidth, c2.width,
  828. XmNheight, r1.height,
  829. NULL);
  830. XtVaSetValues(SizeCtlGetWidget(data->size_ctl),
  831. XmNx, c1.x,
  832. XmNy, r2.y,
  833. XmNwidth, c1.width,
  834. XmNheight, r2.height,
  835. NULL);
  836. XtVaSetValues(TrayCtlGetWidget(data->tray_ctl),
  837. XmNx, c2.x,
  838. XmNy, r2.y,
  839. XmNwidth, c2.width,
  840. XmNheight, r2.height,
  841. NULL);
  842. /*
  843. * resize the drawing area to accommodate the new layout
  844. */
  845. XtVaSetValues(w,
  846. XmNwidth, r1.width,
  847. XmNheight, c1.height,
  848. NULL);
  849. }
  850. /*
  851. * ------------------------------------------------------------------------
  852. * Name: OrientCtlNew
  853. *
  854. * Description:
  855. *
  856. *
  857. *
  858. * Return value:
  859. *
  860. *
  861. *
  862. */
  863. static OrientCtl*
  864. OrientCtlNew(PlexCtl* plex_ctl)
  865. {
  866. OrientCtl* me = (OrientCtl*)XtCalloc(1, sizeof(OrientCtl));
  867. me->plex_ctl = plex_ctl;
  868. return me;
  869. }
  870. /*
  871. * ------------------------------------------------------------------------
  872. * Name: OrientCtlDelete
  873. *
  874. * Description:
  875. *
  876. *
  877. *
  878. * Return value:
  879. *
  880. *
  881. *
  882. */
  883. static void
  884. OrientCtlDelete(OrientCtl* me)
  885. {
  886. PdmOidListDelete(me->dummy_orientations_supported);
  887. PdmPixmapListDelete(me->pixmap_list);
  888. PdmPixmapListDelete(me->i_pixmap_list);
  889. XtFree((char*)me);
  890. }
  891. /*
  892. * ------------------------------------------------------------------------
  893. * Name: OrientCtlCreate
  894. *
  895. * Description:
  896. *
  897. *
  898. *
  899. * Return value:
  900. *
  901. *
  902. *
  903. */
  904. static void
  905. OrientCtlCreate(OrientCtl* me,
  906. Widget parent,
  907. PdmOid orientation,
  908. const PdmOidList* document_attrs_supported,
  909. const PdmOidList* orientations_supported)
  910. {
  911. Boolean supported;
  912. /*
  913. * determine if setting the content orientation is supported
  914. */
  915. if(PdmOidListHasOid(document_attrs_supported,
  916. pdmoid_att_content_orientation)
  917. &&
  918. PdmOidListCount(orientations_supported) > 0)
  919. {
  920. supported = True;
  921. me->orientations_supported = orientations_supported;
  922. }
  923. else
  924. {
  925. supported = False;
  926. /*
  927. * dummy up a list to be presented (insensitive)
  928. */
  929. me->dummy_orientations_supported =
  930. PdmOidListNew(PdmOidString(pdmoid_val_content_orientation_portrait));
  931. me->orientations_supported = me->dummy_orientations_supported;
  932. orientation = pdmoid_none;
  933. }
  934. /*
  935. * set the initially selected list item
  936. */
  937. OrientCtlSetSelectedItem(me,
  938. PdmOidListGetIndex(me->orientations_supported,
  939. orientation));
  940. /*
  941. * create the orientations control window
  942. */
  943. OrientCtlCreateWindow(me, parent);
  944. /*
  945. * initialize the window components
  946. */
  947. OrientCtlCreatePulldown(me);
  948. OrientCtlInitPixmapList(me);
  949. OrientCtlUpdateIcon(me);
  950. /*
  951. * if content-orientation is not supported, disable the control
  952. */
  953. if(!supported)
  954. OrientCtlDisable(me);
  955. }
  956. /*
  957. * ------------------------------------------------------------------------
  958. * Name: OrientCtlCreateWindow
  959. *
  960. * Description:
  961. *
  962. *
  963. *
  964. * Return value:
  965. *
  966. *
  967. *
  968. */
  969. static void
  970. OrientCtlCreateWindow(OrientCtl* me,
  971. Widget parent)
  972. {
  973. Widget control_manager;
  974. /*
  975. * orientation frame
  976. */
  977. me->widget = XtVaCreateManagedWidget("OrientCtlTop",
  978. xmFrameWidgetClass,
  979. parent,
  980. XmNshadowType, XmSHADOW_ETCHED_IN,
  981. NULL);
  982. /*
  983. * orientation label
  984. */
  985. me->frame_label =
  986. XtVaCreateManagedWidget("OrientationLabel",
  987. xmLabelWidgetClass,
  988. me->widget,
  989. XmNframeChildType, XmFRAME_TITLE_CHILD,
  990. NULL);
  991. /*
  992. * orientation controls manager
  993. */
  994. control_manager =
  995. XtVaCreateManagedWidget("OrientationControls",
  996. xmDrawingAreaWidgetClass,
  997. me->widget,
  998. XmNframeChildType, XmFRAME_WORKAREA_CHILD,
  999. NULL);
  1000. XtAddCallback(control_manager, XmNresizeCallback, OrientCtlResizeCB, me);
  1001. /*
  1002. * orientations option menu
  1003. */
  1004. me->option_menu =
  1005. XtVaCreateManagedWidget("OrientationOptionMenu",
  1006. xmRowColumnWidgetClass,
  1007. control_manager,
  1008. XmNmarginHeight, 0,
  1009. XmNrowColumnType, XmMENU_OPTION,
  1010. NULL);
  1011. /*
  1012. * orientation icon
  1013. */
  1014. me->icon_label =
  1015. XtVaCreateManagedWidget("OrientationIcon",
  1016. xmLabelWidgetClass,
  1017. control_manager,
  1018. XmNlabelType, XmPIXMAP,
  1019. XmNalignment, XmALIGNMENT_CENTER,
  1020. NULL);
  1021. }
  1022. /*
  1023. * ------------------------------------------------------------------------
  1024. * Name: OrientCtlDisable
  1025. *
  1026. * Description:
  1027. *
  1028. * Disable the orientation controls.
  1029. *
  1030. * Return value:
  1031. *
  1032. * None.
  1033. *
  1034. */
  1035. static void
  1036. OrientCtlDisable(OrientCtl* me)
  1037. {
  1038. XtSetSensitive(me->frame_label, False);
  1039. XtSetSensitive(me->option_menu, False);
  1040. XtSetSensitive(me->icon_label, False);
  1041. }
  1042. /*
  1043. * ------------------------------------------------------------------------
  1044. * Name: OrientCtlResizeCB
  1045. *
  1046. * Description:
  1047. *
  1048. *
  1049. *
  1050. * Return value:
  1051. *
  1052. * None.
  1053. *
  1054. */
  1055. static void
  1056. OrientCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
  1057. {
  1058. OrientCtl* me = (OrientCtl*)client_data;
  1059. XtArgVal /* Dimension */ height, width, margin_width, new_width;
  1060. XtArgVal /* Position */ menu_x, menu_y, icon_x, icon_y;
  1061. XtArgVal /* Dimension */ menu_h, menu_w, icon_h, icon_w;
  1062. /*
  1063. * get current layout info
  1064. */
  1065. XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
  1066. XmNmarginWidth, &margin_width,
  1067. NULL);
  1068. XtVaGetValues(me->option_menu, XmNheight, &menu_h, XmNwidth, &menu_w,
  1069. NULL);
  1070. XtVaGetValues(me->icon_label, XmNheight, &icon_h, XmNwidth, &icon_w,
  1071. NULL);
  1072. /*
  1073. * position controls side by side
  1074. */
  1075. menu_x = 0;
  1076. icon_x = menu_x + menu_w;
  1077. /*
  1078. * center vertically
  1079. */
  1080. menu_y = (height - menu_h) / 2;
  1081. icon_y = (height - icon_h) / 2;
  1082. /*
  1083. * set new positions
  1084. */
  1085. XtVaSetValues(me->option_menu, XmNx, menu_x, XmNy, menu_y, NULL);
  1086. XtVaSetValues(me->icon_label, XmNx, icon_x, XmNy, icon_y, NULL);
  1087. /*
  1088. * update drawing area width
  1089. */
  1090. new_width = menu_x + menu_w + icon_w + margin_width;
  1091. if(new_width > width)
  1092. XtVaSetValues(w, XmNwidth, new_width, NULL);
  1093. }
  1094. /*
  1095. * ------------------------------------------------------------------------
  1096. * Name: OrientCtlCreatePulldown
  1097. *
  1098. * Description:
  1099. *
  1100. *
  1101. *
  1102. * Return value:
  1103. *
  1104. *
  1105. *
  1106. */
  1107. static void
  1108. OrientCtlCreatePulldown(OrientCtl* me)
  1109. {
  1110. XmString* list;
  1111. int count;
  1112. /*
  1113. * create a list of XmStrings for the content orientations
  1114. */
  1115. list = CreateXmStringsFromOidList(me->orientations_supported);
  1116. /*
  1117. * create the option menu pulldown
  1118. */
  1119. count = PdmOidListCount(me->orientations_supported);
  1120. CreateOptionMenuPulldown("OrientationOptions",
  1121. me->option_menu,
  1122. OrientCtlSelectCB,
  1123. (XtPointer)me,
  1124. list, count,
  1125. me->selected_item);
  1126. /*
  1127. * clean up
  1128. */
  1129. FreeXmStringList(list, count);
  1130. }
  1131. /*
  1132. * ------------------------------------------------------------------------
  1133. * Name: OrientCtlSelectCB
  1134. *
  1135. * Description:
  1136. *
  1137. *
  1138. *
  1139. * Return value:
  1140. *
  1141. *
  1142. *
  1143. */
  1144. static void
  1145. OrientCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
  1146. {
  1147. OrientCtl* me;
  1148. XtArgVal /* int */ selected_item = (XtArgVal)client_data;
  1149. XtVaGetValues(w, XmNuserData, &me, NULL);
  1150. OrientCtlSetSelectedItem(me, selected_item);
  1151. OrientCtlUpdateIcon(me);
  1152. }
  1153. /*
  1154. * ------------------------------------------------------------------------
  1155. * Name: OrientCtlInitPixmapList
  1156. *
  1157. * Description:
  1158. *
  1159. *
  1160. *
  1161. * Return value:
  1162. *
  1163. *
  1164. *
  1165. */
  1166. static void
  1167. OrientCtlInitPixmapList(OrientCtl* me)
  1168. {
  1169. int i;
  1170. const char* image_name;
  1171. int count;
  1172. Dimension max_width = 0;
  1173. Dimension max_height = 0;
  1174. /*
  1175. * initialize the list of pixmaps based on the supported orientations
  1176. */
  1177. count = PdmOidListCount(me->orientations_supported);
  1178. me->pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
  1179. me->i_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
  1180. for(i = 0; i < count; i++)
  1181. {
  1182. switch(PdmOidListGetOid(me->orientations_supported, i))
  1183. {
  1184. case pdmoid_val_content_orientation_portrait:
  1185. image_name = GetIconFileName(me->widget, "PortraitIconFileName");
  1186. break;
  1187. case pdmoid_val_content_orientation_landscape:
  1188. image_name = GetIconFileName(me->widget, "LandscapeIconFileName");
  1189. break;
  1190. case pdmoid_val_content_orientation_reverse_portrait:
  1191. image_name =
  1192. GetIconFileName(me->widget, "ReversePortraitIconFileName");
  1193. break;
  1194. case pdmoid_val_content_orientation_reverse_landscape:
  1195. image_name =
  1196. GetIconFileName(me->widget, "ReverseLandscapeIconFileName");
  1197. break;
  1198. default:
  1199. continue;
  1200. }
  1201. PdmPixmapListSetImageName(me->pixmap_list, image_name, i);
  1202. PdmPixmapListSetImageName(me->i_pixmap_list, image_name, i);
  1203. IconMaxDimension(me->icon_label,
  1204. me->pixmap_list, i,
  1205. &max_width, &max_height);
  1206. }
  1207. XtVaSetValues(me->icon_label,
  1208. XmNwidth, max_width,
  1209. XmNheight, max_height,
  1210. XmNrecomputeSize, False,
  1211. NULL);
  1212. }
  1213. /*
  1214. * ------------------------------------------------------------------------
  1215. * Name: OrientCtlSetSelectedItem
  1216. *
  1217. * Description:
  1218. *
  1219. *
  1220. *
  1221. * Return value:
  1222. *
  1223. *
  1224. *
  1225. */
  1226. static void
  1227. OrientCtlSetSelectedItem(OrientCtl* me, int selected_item)
  1228. {
  1229. if(selected_item == -1)
  1230. me->selected_item = 0;
  1231. else
  1232. me->selected_item = selected_item;
  1233. if(me->plex_ctl != (PlexCtl*)NULL)
  1234. PlexCtlSetOrientation(me->plex_ctl, OrientCtlGetOrientation(me));
  1235. }
  1236. /*
  1237. * ------------------------------------------------------------------------
  1238. * Name: OrientCtlUpdateIcon
  1239. *
  1240. * Description:
  1241. *
  1242. *
  1243. *
  1244. * Return value:
  1245. *
  1246. *
  1247. *
  1248. */
  1249. static void
  1250. OrientCtlUpdateIcon(OrientCtl* me)
  1251. {
  1252. if(me->icon_label != (Widget)NULL)
  1253. XtVaSetValues(me->icon_label,
  1254. XmNlabelPixmap,
  1255. PdmPixmapListGetPixmap(me->pixmap_list,
  1256. me->selected_item),
  1257. XmNlabelInsensitivePixmap,
  1258. PdmPixmapListGetPixmap(me->i_pixmap_list,
  1259. me->selected_item),
  1260. NULL);
  1261. }
  1262. /*
  1263. * ------------------------------------------------------------------------
  1264. * Name: OrientCtlGetOrientation
  1265. *
  1266. * Description:
  1267. *
  1268. *
  1269. *
  1270. * Return value:
  1271. *
  1272. *
  1273. *
  1274. */
  1275. static PdmOid
  1276. OrientCtlGetOrientation(OrientCtl* me)
  1277. {
  1278. if(me->orientations_supported == me->dummy_orientations_supported)
  1279. return pdmoid_none;
  1280. else
  1281. return PdmOidListGetOid(me->orientations_supported, me->selected_item);
  1282. }
  1283. /*
  1284. * ------------------------------------------------------------------------
  1285. * Name: PlexCtlNew
  1286. *
  1287. * Description:
  1288. *
  1289. *
  1290. *
  1291. * Return value:
  1292. *
  1293. *
  1294. *
  1295. */
  1296. static PlexCtl*
  1297. PlexCtlNew(void)
  1298. {
  1299. PlexCtl* me = (PlexCtl*)XtCalloc(1, sizeof(PlexCtl));
  1300. me->pixmap_list_ptr = &me->portrait_pixmap_list;
  1301. me->i_pixmap_list_ptr = &me->i_portrait_pixmap_list;
  1302. return me;
  1303. }
  1304. /*
  1305. * ------------------------------------------------------------------------
  1306. * Name: PlexCtlDelete
  1307. *
  1308. * Description:
  1309. *
  1310. *
  1311. *
  1312. * Return value:
  1313. *
  1314. *
  1315. *
  1316. */
  1317. static void
  1318. PlexCtlDelete(PlexCtl* me)
  1319. {
  1320. PdmOidListDelete(me->dummy_plexes_supported);
  1321. PdmPixmapListDelete(me->portrait_pixmap_list);
  1322. PdmPixmapListDelete(me->i_portrait_pixmap_list);
  1323. PdmPixmapListDelete(me->landscape_pixmap_list);
  1324. PdmPixmapListDelete(me->i_landscape_pixmap_list);
  1325. XtFree((char*)me);
  1326. }
  1327. /*
  1328. * ------------------------------------------------------------------------
  1329. * Name: PlexCtlCreate
  1330. *
  1331. * Description:
  1332. *
  1333. *
  1334. *
  1335. * Return value:
  1336. *
  1337. *
  1338. *
  1339. */
  1340. static void
  1341. PlexCtlCreate(PlexCtl* me,
  1342. Widget parent,
  1343. PdmOid plex,
  1344. const PdmOidList* document_attrs_supported,
  1345. const PdmOidList* plexes_supported)
  1346. {
  1347. Boolean supported;
  1348. /*
  1349. * determine if setting the content orientation is supported
  1350. */
  1351. if(PdmOidListHasOid(document_attrs_supported, pdmoid_att_plex)
  1352. &&
  1353. PdmOidListCount(plexes_supported) > 0)
  1354. {
  1355. supported = True;
  1356. me->plexes_supported = plexes_supported;
  1357. }
  1358. else
  1359. {
  1360. supported = False;
  1361. /*
  1362. * dummy up a list to be presented (insensitive)
  1363. */
  1364. me->dummy_plexes_supported =
  1365. PdmOidListNew(PdmOidString(pdmoid_val_plex_simplex));
  1366. me->plexes_supported = me->dummy_plexes_supported;
  1367. plex = pdmoid_none;
  1368. }
  1369. /*
  1370. * set the initially selected list item
  1371. */
  1372. PlexCtlSetSelectedItem(me, PdmOidListGetIndex(me->plexes_supported, plex));
  1373. /*
  1374. * create the plexes control window
  1375. */
  1376. PlexCtlCreateWindow(me, parent);
  1377. /*
  1378. * initialize the window components
  1379. */
  1380. PlexCtlCreatePulldown(me);
  1381. PlexCtlInitPixmapLists(me);
  1382. PlexCtlUpdateIcon(me);
  1383. /*
  1384. * if plex is not supported, disable the control
  1385. */
  1386. if(!supported)
  1387. PlexCtlDisable(me);
  1388. }
  1389. /*
  1390. * ------------------------------------------------------------------------
  1391. * Name: PlexCtlCreateWindow
  1392. *
  1393. * Description:
  1394. *
  1395. *
  1396. *
  1397. * Return value:
  1398. *
  1399. *
  1400. *
  1401. */
  1402. static void
  1403. PlexCtlCreateWindow(PlexCtl* me,
  1404. Widget parent)
  1405. {
  1406. Widget control_manager;
  1407. /*
  1408. * plex frame
  1409. */
  1410. me->widget = XtVaCreateManagedWidget("PlexCtlTop",
  1411. xmFrameWidgetClass,
  1412. parent,
  1413. XmNshadowType, XmSHADOW_ETCHED_IN,
  1414. NULL);
  1415. /*
  1416. * plex label
  1417. */
  1418. me->frame_label =
  1419. XtVaCreateManagedWidget("PlexLabel",
  1420. xmLabelGadgetClass,
  1421. me->widget,
  1422. XmNframeChildType, XmFRAME_TITLE_CHILD,
  1423. NULL);
  1424. /*
  1425. * plex controls manager
  1426. */
  1427. control_manager =
  1428. XtVaCreateManagedWidget(
  1429. "PlexControls",
  1430. xmDrawingAreaWidgetClass,
  1431. me->widget,
  1432. XmNframeChildType, XmFRAME_WORKAREA_CHILD,
  1433. NULL);
  1434. XtAddCallback(control_manager, XmNresizeCallback, PlexCtlResizeCB, me);
  1435. /*
  1436. * plexes option menu
  1437. */
  1438. me->option_menu =
  1439. XtVaCreateManagedWidget("PlexOptionMenu",
  1440. xmRowColumnWidgetClass,
  1441. control_manager,
  1442. XmNrowColumnType, XmMENU_OPTION,
  1443. XmNmarginHeight, 0,
  1444. NULL);
  1445. /*
  1446. * plex icon
  1447. */
  1448. me->icon_label =
  1449. XtVaCreateManagedWidget("PlexIcon",
  1450. xmLabelWidgetClass,
  1451. control_manager,
  1452. XmNlabelType, XmPIXMAP,
  1453. XmNalignment, XmALIGNMENT_CENTER,
  1454. NULL);
  1455. }
  1456. /*
  1457. * ------------------------------------------------------------------------
  1458. * Name: PlexCtlDisable
  1459. *
  1460. * Description:
  1461. *
  1462. * Disable the plex controls.
  1463. *
  1464. * Return value:
  1465. *
  1466. * None.
  1467. *
  1468. */
  1469. static void
  1470. PlexCtlDisable(PlexCtl* me)
  1471. {
  1472. XtSetSensitive(me->frame_label, False);
  1473. XtSetSensitive(me->option_menu, False);
  1474. XtSetSensitive(me->icon_label, False);
  1475. }
  1476. /*
  1477. * ------------------------------------------------------------------------
  1478. * Name: PlexCtlResizeCB
  1479. *
  1480. * Description:
  1481. *
  1482. *
  1483. *
  1484. * Return value:
  1485. *
  1486. * None.
  1487. *
  1488. */
  1489. static void
  1490. PlexCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
  1491. {
  1492. PlexCtl* me = (PlexCtl*)client_data;
  1493. XtArgVal /* Dimension */ height, width, margin_width, new_width;
  1494. XtArgVal /* Position */ menu_x, menu_y, icon_x, icon_y;
  1495. XtArgVal /* Dimension */ menu_h, menu_w, icon_h, icon_w;
  1496. /*
  1497. * get current layout info
  1498. */
  1499. XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
  1500. XmNmarginWidth, &margin_width,
  1501. NULL);
  1502. XtVaGetValues(me->option_menu, XmNheight, &menu_h, XmNwidth, &menu_w,
  1503. NULL);
  1504. XtVaGetValues(me->icon_label, XmNheight, &icon_h, XmNwidth, &icon_w,
  1505. NULL);
  1506. /*
  1507. * position controls side by side
  1508. */
  1509. menu_x = 0;
  1510. icon_x = menu_x + menu_w;
  1511. /*
  1512. * center vertically
  1513. */
  1514. menu_y = (height - menu_h) / 2;
  1515. icon_y = (height - icon_h) / 2;
  1516. /*
  1517. * set new positions
  1518. */
  1519. XtVaSetValues(me->option_menu, XmNx, menu_x, XmNy, menu_y, NULL);
  1520. XtVaSetValues(me->icon_label, XmNx, icon_x, XmNy, icon_y, NULL);
  1521. /*
  1522. * update drawing area width
  1523. */
  1524. new_width = menu_x + menu_w + icon_w + margin_width;
  1525. if(new_width > width)
  1526. XtVaSetValues(w, XmNwidth, new_width, NULL);
  1527. }
  1528. /*
  1529. * ------------------------------------------------------------------------
  1530. * Name: PlexCtlCreatePulldown
  1531. *
  1532. * Description:
  1533. *
  1534. *
  1535. *
  1536. * Return value:
  1537. *
  1538. *
  1539. *
  1540. */
  1541. static void
  1542. PlexCtlCreatePulldown(PlexCtl* me)
  1543. {
  1544. XmString* list;
  1545. int count;
  1546. /*
  1547. * build a list of Xm strings for the supported plexes
  1548. */
  1549. list = CreateXmStringsFromOidList(me->plexes_supported);
  1550. /*
  1551. * create the option menu pulldown
  1552. */
  1553. count = PdmOidListCount(me->plexes_supported);
  1554. CreateOptionMenuPulldown("PlexOptions",
  1555. me->option_menu,
  1556. PlexCtlSelectCB,
  1557. (XtPointer)me,
  1558. list, count,
  1559. me->selected_item);
  1560. /*
  1561. * clean up
  1562. */
  1563. FreeXmStringList(list, count);
  1564. }
  1565. /*
  1566. * ------------------------------------------------------------------------
  1567. * Name: PlexCtlSelectCB
  1568. *
  1569. * Description:
  1570. *
  1571. *
  1572. *
  1573. * Return value:
  1574. *
  1575. *
  1576. *
  1577. */
  1578. static void
  1579. PlexCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
  1580. {
  1581. PlexCtl* me;
  1582. XtArgVal /* int */ selected_item = (XtArgVal)client_data;
  1583. XtVaGetValues(w, XmNuserData, &me, NULL);
  1584. PlexCtlSetSelectedItem(me, selected_item);
  1585. PlexCtlUpdateIcon(me);
  1586. }
  1587. /*
  1588. * ------------------------------------------------------------------------
  1589. * Name: PlexCtlSetOrientation
  1590. *
  1591. * Description:
  1592. *
  1593. *
  1594. *
  1595. * Return value:
  1596. *
  1597. *
  1598. *
  1599. */
  1600. static void
  1601. PlexCtlSetOrientation(PlexCtl* me,
  1602. PdmOid orientation)
  1603. {
  1604. switch(orientation)
  1605. {
  1606. case pdmoid_val_content_orientation_landscape:
  1607. case pdmoid_val_content_orientation_reverse_landscape:
  1608. me->pixmap_list_ptr = &me->landscape_pixmap_list;
  1609. me->i_pixmap_list_ptr = &me->i_landscape_pixmap_list;
  1610. break;
  1611. default:
  1612. me->pixmap_list_ptr = &me->portrait_pixmap_list;
  1613. me->i_pixmap_list_ptr = &me->i_portrait_pixmap_list;
  1614. break;
  1615. }
  1616. PlexCtlUpdateIcon(me);
  1617. }
  1618. /*
  1619. * ------------------------------------------------------------------------
  1620. * Name: PlexCtlInitPixmapLists
  1621. *
  1622. * Description:
  1623. *
  1624. *
  1625. *
  1626. * Return value:
  1627. *
  1628. *
  1629. *
  1630. */
  1631. static void
  1632. PlexCtlInitPixmapLists(PlexCtl* me)
  1633. {
  1634. int i;
  1635. const char* portrait_image_name;
  1636. const char* landscape_image_name;
  1637. int count;
  1638. Dimension max_width = 0;
  1639. Dimension max_height = 0;
  1640. /*
  1641. * initialize the list of pixmaps based on the list of plexes
  1642. */
  1643. count = PdmOidListCount(me->plexes_supported);
  1644. me->portrait_pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
  1645. me->i_portrait_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
  1646. me->landscape_pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
  1647. me->i_landscape_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
  1648. for(i = 0; i < count; i++)
  1649. {
  1650. switch(PdmOidListGetOid(me->plexes_supported, i))
  1651. {
  1652. case pdmoid_val_plex_simplex:
  1653. portrait_image_name =
  1654. GetIconFileName(me->widget, "SimplexPortraitIconFileName");
  1655. landscape_image_name =
  1656. GetIconFileName(me->widget, "SimplexLandscapeIconFileName");
  1657. break;
  1658. case pdmoid_val_plex_duplex:
  1659. portrait_image_name =
  1660. GetIconFileName(me->widget, "DuplexPortraitIconFileName");
  1661. landscape_image_name =
  1662. GetIconFileName(me->widget, "DuplexLandscapeIconFileName");
  1663. break;
  1664. case pdmoid_val_plex_tumble:
  1665. portrait_image_name =
  1666. GetIconFileName(me->widget, "TumblePortraitIconFileName");
  1667. landscape_image_name =
  1668. GetIconFileName(me->widget, "TumbleLandscapeIconFileName");
  1669. break;
  1670. default:
  1671. continue;
  1672. }
  1673. PdmPixmapListSetImageName(me->portrait_pixmap_list,
  1674. portrait_image_name, i);
  1675. PdmPixmapListSetImageName(me->i_portrait_pixmap_list,
  1676. portrait_image_name, i);
  1677. PdmPixmapListSetImageName(me->landscape_pixmap_list,
  1678. landscape_image_name, i);
  1679. PdmPixmapListSetImageName(me->i_landscape_pixmap_list,
  1680. landscape_image_name, i);
  1681. IconMaxDimension(me->icon_label,
  1682. me->portrait_pixmap_list, i,
  1683. &max_width, &max_height);
  1684. IconMaxDimension(me->icon_label,
  1685. me->landscape_pixmap_list, i,
  1686. &max_width, &max_height);
  1687. }
  1688. XtVaSetValues(me->icon_label,
  1689. XmNwidth, max_width,
  1690. XmNheight, max_height,
  1691. XmNrecomputeSize, False,
  1692. NULL);
  1693. }
  1694. /*
  1695. * ------------------------------------------------------------------------
  1696. * Name: PlexCtlSetSelectedItem
  1697. *
  1698. * Description:
  1699. *
  1700. *
  1701. *
  1702. * Return value:
  1703. *
  1704. *
  1705. *
  1706. */
  1707. static void
  1708. PlexCtlSetSelectedItem(PlexCtl* me, int selected_item)
  1709. {
  1710. if(selected_item == -1)
  1711. me->selected_item = 0;
  1712. else
  1713. me->selected_item = selected_item;
  1714. }
  1715. /*
  1716. * ------------------------------------------------------------------------
  1717. * Name: PlexCtlUpdateIcon
  1718. *
  1719. * Description:
  1720. *
  1721. *
  1722. *
  1723. * Return value:
  1724. *
  1725. *
  1726. *
  1727. */
  1728. static void
  1729. PlexCtlUpdateIcon(PlexCtl* me)
  1730. {
  1731. if(me->icon_label != (Widget)NULL)
  1732. XtVaSetValues(me->icon_label,
  1733. XmNlabelPixmap,
  1734. PdmPixmapListGetPixmap(*me->pixmap_list_ptr,
  1735. me->selected_item),
  1736. XmNlabelInsensitivePixmap,
  1737. PdmPixmapListGetPixmap(*me->i_pixmap_list_ptr,
  1738. me->selected_item),
  1739. NULL);
  1740. }
  1741. /*
  1742. * ------------------------------------------------------------------------
  1743. * Name: PlexCtlGetPlex
  1744. *
  1745. * Description:
  1746. *
  1747. *
  1748. *
  1749. * Return value:
  1750. *
  1751. *
  1752. *
  1753. */
  1754. static PdmOid
  1755. PlexCtlGetPlex(PlexCtl* me)
  1756. {
  1757. if(me->plexes_supported == me->dummy_plexes_supported)
  1758. return pdmoid_none;
  1759. else
  1760. return PdmOidListGetOid(me->plexes_supported, me->selected_item);
  1761. }
  1762. /*
  1763. * ------------------------------------------------------------------------
  1764. * Name: TrayCtlNew
  1765. *
  1766. * Description:
  1767. *
  1768. *
  1769. *
  1770. * Return value:
  1771. *
  1772. *
  1773. *
  1774. */
  1775. static TrayCtl*
  1776. TrayCtlNew(SizeCtl* size_ctl)
  1777. {
  1778. TrayCtl* me = (TrayCtl*)XtCalloc(1, sizeof(TrayCtl));
  1779. me->size_ctl = size_ctl;
  1780. return me;
  1781. }
  1782. /*
  1783. * ------------------------------------------------------------------------
  1784. * Name: TrayCtlDelete
  1785. *
  1786. * Description:
  1787. *
  1788. *
  1789. *
  1790. * Return value:
  1791. *
  1792. *
  1793. *
  1794. */
  1795. static void
  1796. TrayCtlDelete(TrayCtl* me)
  1797. {
  1798. XtFree((char*)me);
  1799. }
  1800. /*
  1801. * ------------------------------------------------------------------------
  1802. * Name: TrayCtlCreate
  1803. *
  1804. * Description:
  1805. *
  1806. *
  1807. *
  1808. * Return value:
  1809. *
  1810. *
  1811. *
  1812. */
  1813. static void
  1814. TrayCtlCreate(TrayCtl* me,
  1815. Widget parent,
  1816. PdmOid default_input_tray,
  1817. PdmOid default_medium,
  1818. const PdmOidList* document_attrs_supported,
  1819. const PdmOidList* input_trays,
  1820. const PdmOidList* tray_sizes)
  1821. {
  1822. Boolean supported;
  1823. /*
  1824. * save the trays and sizes list pointers
  1825. */
  1826. me->input_trays = input_trays;
  1827. me->tray_sizes = tray_sizes;
  1828. /*
  1829. * determine if setting the input tray is supported
  1830. */
  1831. if(PdmOidListHasOid(document_attrs_supported,
  1832. pdmoid_att_default_input_tray)
  1833. &&
  1834. PdmOidListCount(me->input_trays) > 0)
  1835. {
  1836. supported = True;
  1837. }
  1838. else
  1839. supported = False;
  1840. /*
  1841. * set the initially selected list item
  1842. */
  1843. if(default_medium != pdmoid_none)
  1844. {
  1845. /*
  1846. * default-medium has precedence; set "Auto-select" (index 0)
  1847. */
  1848. TrayCtlSetSelectedItem(me, 0);
  1849. }
  1850. else
  1851. {
  1852. int i = PdmOidListGetIndex(me->input_trays, default_input_tray);
  1853. if(!supported || i == -1)
  1854. /*
  1855. * default-input-tray unsupported or not found in list; set
  1856. * "Auto-select" (index 0)
  1857. */
  1858. TrayCtlSetSelectedItem(me, 0);
  1859. else
  1860. /*
  1861. * Select the list item corresponding to default-input-tray -
  1862. * ie. add 1 to the input trays list index since the option
  1863. * menu is always built with "Auto-select" as the first
  1864. * entry, followed by the input trays list entries.
  1865. */
  1866. TrayCtlSetSelectedItem(me, i+1);
  1867. }
  1868. /*
  1869. * create the tray control window
  1870. */
  1871. TrayCtlCreateWindow(me, parent);
  1872. /*
  1873. * initialize the window components
  1874. */
  1875. TrayCtlCreatePulldown(me);
  1876. /*
  1877. * if tray selection is not supported, disable the control
  1878. */
  1879. if(!supported)
  1880. TrayCtlDisable(me);
  1881. }
  1882. /*
  1883. * ------------------------------------------------------------------------
  1884. * Name: TrayCtlCreateWindow
  1885. *
  1886. * Description:
  1887. *
  1888. *
  1889. *
  1890. * Return value:
  1891. *
  1892. *
  1893. *
  1894. */
  1895. static void
  1896. TrayCtlCreateWindow(TrayCtl* me, Widget parent)
  1897. {
  1898. Widget control_manager;
  1899. /*
  1900. * tray frame
  1901. */
  1902. me->widget = XtVaCreateManagedWidget("TrayCtlTop",
  1903. xmFrameWidgetClass,
  1904. parent,
  1905. XmNshadowType, XmSHADOW_ETCHED_IN,
  1906. NULL);
  1907. /*
  1908. * tray label
  1909. */
  1910. me->frame_label
  1911. = XtVaCreateManagedWidget("TrayLabel",
  1912. xmLabelGadgetClass,
  1913. me->widget,
  1914. XmNframeChildType, XmFRAME_TITLE_CHILD,
  1915. NULL);
  1916. /*
  1917. * tray controls manager
  1918. */
  1919. control_manager =
  1920. XtVaCreateManagedWidget("TrayControls",
  1921. xmDrawingAreaWidgetClass,
  1922. me->widget,
  1923. XmNframeChildType, XmFRAME_WORKAREA_CHILD,
  1924. NULL);
  1925. XtAddCallback(control_manager, XmNresizeCallback, TrayCtlResizeCB, me);
  1926. /*
  1927. * trays option menu
  1928. */
  1929. me->option_menu =
  1930. XtVaCreateManagedWidget("TrayOptionMenu",
  1931. xmRowColumnWidgetClass,
  1932. control_manager,
  1933. XmNmarginHeight, 0,
  1934. XmNrowColumnType, XmMENU_OPTION,
  1935. NULL);
  1936. }
  1937. /*
  1938. * ------------------------------------------------------------------------
  1939. * Name: TrayCtlDisable
  1940. *
  1941. * Description:
  1942. *
  1943. * Disable the input tray controls.
  1944. *
  1945. * Return value:
  1946. *
  1947. * None.
  1948. *
  1949. */
  1950. static void
  1951. TrayCtlDisable(TrayCtl* me)
  1952. {
  1953. XtSetSensitive(me->frame_label, False);
  1954. XtSetSensitive(me->option_menu, False);
  1955. }
  1956. /*
  1957. * ------------------------------------------------------------------------
  1958. * Name: TrayCtlResizeCB
  1959. *
  1960. * Description:
  1961. *
  1962. *
  1963. *
  1964. * Return value:
  1965. *
  1966. * None.
  1967. *
  1968. */
  1969. static void
  1970. TrayCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
  1971. {
  1972. TrayCtl* me = (TrayCtl*)client_data;
  1973. XtArgVal /* Dimension */ height, menu_h;
  1974. XtArgVal /* Position */ menu_y;
  1975. /*
  1976. * get current layout info
  1977. */
  1978. XtVaGetValues(w, XmNheight, &height, NULL);
  1979. XtVaGetValues(me->option_menu, XmNheight, &menu_h, NULL);
  1980. /*
  1981. * center vertically
  1982. */
  1983. menu_y = (height - menu_h) / 2;
  1984. /*
  1985. * set new position
  1986. */
  1987. XtVaSetValues(me->option_menu, XmNx, 0, XmNy, menu_y, NULL);
  1988. }
  1989. /*
  1990. * ------------------------------------------------------------------------
  1991. * Name: TrayCtlGetTray
  1992. *
  1993. * Description:
  1994. *
  1995. *
  1996. *
  1997. * Return value:
  1998. *
  1999. *
  2000. *
  2001. */
  2002. static PdmOid
  2003. TrayCtlGetTray(TrayCtl* me)
  2004. {
  2005. if(me->selected_item == 0)
  2006. return pdmoid_none;
  2007. else
  2008. return PdmOidListGetOid(me->input_trays, me->selected_item - 1);
  2009. }
  2010. /*
  2011. * ------------------------------------------------------------------------
  2012. * Name: TrayCtlCreatePulldown
  2013. *
  2014. * Description:
  2015. *
  2016. *
  2017. *
  2018. * Return value:
  2019. *
  2020. *
  2021. *
  2022. */
  2023. static void
  2024. TrayCtlCreatePulldown(TrayCtl* me)
  2025. {
  2026. XmString* xmstr_list;
  2027. int count;
  2028. PdmOid oid;
  2029. const char* str;
  2030. int i;
  2031. /*
  2032. * create a list of XmStrings for the Auto-select item plus the list
  2033. * of specific trays
  2034. */
  2035. count = 1 + PdmOidListCount(me->input_trays);
  2036. xmstr_list = (XmString*)XtCalloc(count, sizeof(XmString));
  2037. /*
  2038. * set the "Auto-select" item as the first item
  2039. */
  2040. i = 0;
  2041. xmstr_list[i++] = XmStringCreateLocalized((char*)PDM_MSG_TRAY_AUTO_SELECT);
  2042. /*
  2043. * add the input trays
  2044. */
  2045. for(; i < count; i++)
  2046. {
  2047. oid = PdmOidListGetOid(me->input_trays, i-1);
  2048. str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
  2049. PdmOidMsgNum(oid),
  2050. PdmOidDefaultMsg(oid));
  2051. xmstr_list[i] = XmStringCreateLocalized((char*)str);
  2052. }
  2053. /*
  2054. * create the option menu pulldown
  2055. */
  2056. CreateOptionMenuPulldown("TrayOptions",
  2057. me->option_menu,
  2058. TrayCtlSelectCB,
  2059. (XtPointer)me,
  2060. xmstr_list, count,
  2061. me->selected_item);
  2062. /*
  2063. * clean up
  2064. */
  2065. FreeXmStringList(xmstr_list, count);
  2066. }
  2067. /*
  2068. * ------------------------------------------------------------------------
  2069. * Name: TrayCtlSetSelectedItem
  2070. *
  2071. * Description:
  2072. *
  2073. *
  2074. *
  2075. * Return value:
  2076. *
  2077. *
  2078. *
  2079. */
  2080. static void
  2081. TrayCtlSetSelectedItem(TrayCtl* me, int selected_item)
  2082. {
  2083. if(selected_item == -1)
  2084. me->selected_item = 0;
  2085. else
  2086. me->selected_item = selected_item;
  2087. /*
  2088. * update the page size control accordingly
  2089. */
  2090. if(me->selected_item == 0)
  2091. SizeCtlSetMultiSizeMode(me->size_ctl);
  2092. else
  2093. SizeCtlSetSingleSizeMode(me->size_ctl,
  2094. PdmOidListGetOid(me->tray_sizes,
  2095. me->selected_item - 1));
  2096. }
  2097. /*
  2098. * ------------------------------------------------------------------------
  2099. * Name: TrayCtlSelectCB
  2100. *
  2101. * Description:
  2102. *
  2103. *
  2104. *
  2105. * Return value:
  2106. *
  2107. *
  2108. *
  2109. */
  2110. static void
  2111. TrayCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
  2112. {
  2113. TrayCtl* me;
  2114. XtArgVal /* int */ selected_item = (XtArgVal)client_data;
  2115. XtVaGetValues(w, XmNuserData, &me, NULL);
  2116. TrayCtlSetSelectedItem(me, selected_item);
  2117. }
  2118. /*
  2119. * ------------------------------------------------------------------------
  2120. * Name: SizeCtlNew
  2121. *
  2122. * Description:
  2123. *
  2124. *
  2125. *
  2126. * Return value:
  2127. *
  2128. *
  2129. *
  2130. */
  2131. static SizeCtl*
  2132. SizeCtlNew(void)
  2133. {
  2134. SizeCtl* me = (SizeCtl*)XtCalloc(1, sizeof(SizeCtl));
  2135. return me;
  2136. }
  2137. /*
  2138. * ------------------------------------------------------------------------
  2139. * Name: SizeCtlDelete
  2140. *
  2141. * Description:
  2142. *
  2143. *
  2144. *
  2145. * Return value:
  2146. *
  2147. *
  2148. *
  2149. */
  2150. static void
  2151. SizeCtlDelete(SizeCtl* me)
  2152. {
  2153. if(me != (SizeCtl*)NULL)
  2154. {
  2155. if(me->sizes_ready_xmstr != (XmString*)NULL)
  2156. FreeXmStringList(me->sizes_ready_xmstr,
  2157. PdmOidListCount(me->sizes_ready));
  2158. if(me->sizes_supported_xmstr != (XmString*)NULL)
  2159. FreeXmStringList(me->sizes_supported_xmstr,
  2160. PdmOidListCount(me->sizes_supported));
  2161. PdmOidListDelete(me->sizes_ready);
  2162. PdmOidListDelete(me->sizes_supported);
  2163. XtFree((char*)me);
  2164. }
  2165. }
  2166. /*
  2167. * ------------------------------------------------------------------------
  2168. * Name: SizeCtlStrColl
  2169. *
  2170. * Description:
  2171. *
  2172. * An adaptor for using strcoll on SizeCtlSortRec's with qsort.
  2173. *
  2174. * Return value:
  2175. *
  2176. * The return value for strcoll given the strings in the passed
  2177. * SizeCtlSortRec's.
  2178. *
  2179. */
  2180. static int
  2181. SizeCtlStrColl(const void* e1, const void* e2)
  2182. {
  2183. const SizeCtlSortRec *r1 = e1, *r2 = e2;
  2184. return strcoll(r1->str, r2->str);
  2185. }
  2186. /*
  2187. * ------------------------------------------------------------------------
  2188. * Name: SizeCtlSetSizeLists
  2189. *
  2190. * Description:
  2191. *
  2192. * Creates a sorted XmStringTable and PdmOidList using
  2193. * the oids from the passed PdmOidLinkedList. The newly created lists
  2194. * are returned via the 'oids' and 'xmstrs' parms.
  2195. *
  2196. * Return value:
  2197. *
  2198. * None.
  2199. *
  2200. */
  2201. static void
  2202. SizeCtlSetSizeLists(PdmOidList** oid_list,
  2203. XmStringTable* xmstrs,
  2204. PdmOidLinkedList* oid_ll)
  2205. {
  2206. int count;
  2207. count = PdmOidLinkedListCount(oid_ll);
  2208. if(count == 0)
  2209. {
  2210. *oid_list = (PdmOidList*)NULL;
  2211. *xmstrs = (XmStringTable)NULL;
  2212. }
  2213. else
  2214. {
  2215. SizeCtlSortList sort_list;
  2216. int i;
  2217. PdmOid oid;
  2218. /*
  2219. * sort the passed sizes
  2220. */
  2221. sort_list = (SizeCtlSortList)XtCalloc(count, sizeof(SizeCtlSortRec));
  2222. for(i = 0, oid = PdmOidLinkedListFirstOid(oid_ll);
  2223. i < count;
  2224. i++, oid = PdmOidLinkedListNextOid(oid_ll))
  2225. {
  2226. sort_list[i].oid = oid;
  2227. sort_list[i].str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
  2228. PdmOidMsgNum(oid),
  2229. PdmOidDefaultMsg(oid));
  2230. }
  2231. qsort(sort_list, count, sizeof(SizeCtlSortRec), SizeCtlStrColl);
  2232. /*
  2233. * create the return lists of oids and XmStrings
  2234. */
  2235. *oid_list = (PdmOidList*)XtCalloc(1, sizeof(PdmOidList));
  2236. (*oid_list)->list = (PdmOid*)XtCalloc(count, sizeof(PdmOid));
  2237. (*oid_list)->count = count;
  2238. *xmstrs = (XmStringTable)XtCalloc(count, sizeof(XmString));
  2239. for(i = 0; i < count; i++)
  2240. {
  2241. ((*oid_list)->list)[i] = sort_list[i].oid;
  2242. (*xmstrs)[i] = XmStringCreateLocalized((char*)sort_list[i].str);
  2243. }
  2244. XtFree((char*)sort_list);
  2245. }
  2246. }
  2247. /*
  2248. * ------------------------------------------------------------------------
  2249. * Name: SizeCtlCreate
  2250. *
  2251. * Description:
  2252. *
  2253. *
  2254. *
  2255. * Return value:
  2256. *
  2257. *
  2258. *
  2259. */
  2260. static void
  2261. SizeCtlCreate(SizeCtl* me,
  2262. Widget parent,
  2263. PdmOid default_medium,
  2264. const PdmOidList* document_attrs_supported,
  2265. const PdmOidList* tray_sizes,
  2266. PdmOidLinkedList* sizes_supported)
  2267. {
  2268. Boolean supported;
  2269. int i;
  2270. PdmOid oid;
  2271. PdmOidLinkedList* sizes_ready_ll;
  2272. /*
  2273. * initialize the selected size
  2274. */
  2275. me->selected_size = default_medium;
  2276. /*
  2277. * build the sizes ready list using unique elements of the tray sizes
  2278. * list
  2279. */
  2280. sizes_ready_ll = PdmOidLinkedListNew();
  2281. for(i = 0; i < PdmOidListCount(tray_sizes); i++)
  2282. {
  2283. oid = PdmOidListGetOid(tray_sizes, i);
  2284. if(!PdmOidLinkedListHasOid(sizes_ready_ll, oid))
  2285. {
  2286. PdmOidLinkedListAddOid(sizes_ready_ll, oid);
  2287. }
  2288. }
  2289. /*
  2290. * determine if setting the medium is supported
  2291. */
  2292. if(!PdmOidListHasOid(document_attrs_supported,
  2293. pdmoid_att_default_medium)
  2294. ||
  2295. PdmOidLinkedListCount(sizes_supported) == 0)
  2296. {
  2297. me->selected_list = SIZECTL_UNSUPPORTED;
  2298. }
  2299. else
  2300. {
  2301. /*
  2302. * default to the ready list
  2303. */
  2304. me->selected_list = SIZECTL_SIZES_READY;
  2305. }
  2306. /*
  2307. * create the XmString versions of the sizes lists
  2308. */
  2309. SizeCtlSetSizeLists(&me->sizes_ready, &me->sizes_ready_xmstr,
  2310. sizes_ready_ll);
  2311. PdmOidLinkedListDelete(sizes_ready_ll);
  2312. SizeCtlSetSizeLists(&me->sizes_supported, &me->sizes_supported_xmstr,
  2313. sizes_supported);
  2314. /*
  2315. * create the size control window
  2316. */
  2317. SizeCtlCreateWindow(me, parent);
  2318. /*
  2319. * update the control state
  2320. */
  2321. SizeCtlUpdate(me);
  2322. }
  2323. /*
  2324. * ------------------------------------------------------------------------
  2325. * Name: SizeCtlCreateWindow
  2326. *
  2327. * Description:
  2328. *
  2329. *
  2330. *
  2331. * Return value:
  2332. *
  2333. *
  2334. *
  2335. */
  2336. static void
  2337. SizeCtlCreateWindow(SizeCtl* me, Widget parent)
  2338. {
  2339. Arg args[15];
  2340. Cardinal n;
  2341. Widget control_manager;
  2342. Widget hscroll;
  2343. XmString default_xmstr = (XmString)NULL;
  2344. /*
  2345. * page size frame
  2346. */
  2347. me->widget = XtVaCreateManagedWidget("PageSizeCtlTop",
  2348. xmFrameWidgetClass,
  2349. parent,
  2350. XmNshadowType, XmSHADOW_ETCHED_IN,
  2351. NULL);
  2352. /*
  2353. * page size label
  2354. */
  2355. me->frame_label
  2356. = XtVaCreateManagedWidget("PageSizeLabel",
  2357. xmLabelGadgetClass,
  2358. me->widget,
  2359. XmNframeChildType, XmFRAME_TITLE_CHILD,
  2360. NULL);
  2361. /*
  2362. * page size controls manager
  2363. */
  2364. control_manager =
  2365. XtVaCreateManagedWidget("PageSizeControls",
  2366. xmDrawingAreaWidgetClass,
  2367. me->widget,
  2368. XmNframeChildType, XmFRAME_WORKAREA_CHILD,
  2369. NULL);
  2370. XtAddCallback(control_manager, XmNresizeCallback, SizeCtlResizeCB, me);
  2371. /*
  2372. * page sizes list box
  2373. */
  2374. n = 0;
  2375. XtSetArg(args[n], XmNvisibleItemCount, 3); n++;
  2376. XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); n++;
  2377. XtSetArg(args[n], XmNhorizontalScrollBar, NULL); n++;
  2378. /*
  2379. * set the supported sizes list in the list box, in order to lock
  2380. * down the maximum dimensions - the list box does not support
  2381. * changes to the list size policy after creation
  2382. */
  2383. if(me->selected_list == SIZECTL_UNSUPPORTED)
  2384. {
  2385. /*
  2386. * unsupported, use "Default"
  2387. */
  2388. default_xmstr =
  2389. XmStringCreateLocalized((char*)PDM_MSG_SIZE_DEFAULT);
  2390. XtSetArg(args[n], XmNitemCount, 1); n++;
  2391. XtSetArg(args[n], XmNitems, &default_xmstr); n++;
  2392. }
  2393. else
  2394. {
  2395. XtSetArg(args[n], XmNitems, me->sizes_supported_xmstr); n++;
  2396. XtSetArg(args[n], XmNitemCount,
  2397. PdmOidListCount(me->sizes_supported)); n++;
  2398. }
  2399. XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++;
  2400. me->list_box = XmCreateScrolledList(control_manager, "PageSizes", args, n);
  2401. if((XmString)NULL != default_xmstr) XmStringFree(default_xmstr);
  2402. XtAddCallback(me->list_box, XmNbrowseSelectionCallback,
  2403. SizeCtlSelectCB, (XtPointer)me);
  2404. /*
  2405. * hide the horizontal scroll bar, since the width of the list has
  2406. * been set to accommodate the widest item.
  2407. */
  2408. hscroll = XtNameToWidget(XtParent(me->list_box), "*HorScrollBar");
  2409. XtVaSetValues(hscroll,
  2410. XmNmappedWhenManaged, False,
  2411. XmNx, 0, XmNy, 0, XmNwidth, 1, XmNheight, 1,
  2412. NULL);
  2413. /*
  2414. * manage the scrolled list
  2415. */
  2416. XtManageChild(me->list_box);
  2417. XtManageChild(XtParent(me->list_box));
  2418. /*
  2419. * loaded / allowed sizes radio buttons
  2420. */
  2421. me->radio_box = XtVaCreateWidget(
  2422. "LoadedAllowed",
  2423. xmRowColumnWidgetClass,
  2424. control_manager,
  2425. XmNradioBehavior, True,
  2426. NULL);
  2427. me->ready_radio = XtVaCreateManagedWidget("button_0",
  2428. xmToggleButtonWidgetClass,
  2429. me->radio_box,
  2430. NULL);
  2431. XtAddCallback(me->ready_radio, XmNvalueChangedCallback,
  2432. SizeCtlReadyChangedCB, (XtPointer)me);
  2433. me->supported_radio = XtVaCreateManagedWidget("button_1",
  2434. xmToggleButtonWidgetClass,
  2435. me->radio_box,
  2436. NULL);
  2437. XtAddCallback(me->supported_radio, XmNvalueChangedCallback,
  2438. SizeCtlSupportedChangedCB, (XtPointer)me);
  2439. XtManageChild(me->radio_box);
  2440. }
  2441. /*
  2442. * ------------------------------------------------------------------------
  2443. * Name: SizeCtlUpdate
  2444. *
  2445. * Description:
  2446. *
  2447. * Update the state of the size control
  2448. *
  2449. * Return value:
  2450. *
  2451. * None.
  2452. *
  2453. */
  2454. static void
  2455. SizeCtlUpdate(SizeCtl* me)
  2456. {
  2457. Boolean frame_label_sensitive = False;
  2458. Boolean list_box_sensitive = False;
  2459. Boolean list_box_traverse = False;
  2460. Boolean ready_radio_sensitive = False;
  2461. Boolean supported_radio_sensitive = False;
  2462. /*
  2463. * clear the current list
  2464. */
  2465. XmListDeleteAllItems(me->list_box);
  2466. if(me->single_size_mode)
  2467. {
  2468. XmString item;
  2469. PdmOid oid = me->selected_size;
  2470. item =
  2471. XmStringCreateLocalized((char*)
  2472. DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
  2473. PdmOidMsgNum(oid),
  2474. PdmOidDefaultMsg(oid)));
  2475. XmListAddItem(me->list_box, item, 0);
  2476. XmListSelectPos(me->list_box, 0, False);
  2477. XmStringFree(item);
  2478. if(me->selected_list != SIZECTL_UNSUPPORTED)
  2479. {
  2480. frame_label_sensitive = True;
  2481. list_box_sensitive = True;
  2482. me->selected_list = SIZECTL_SIZES_READY;
  2483. XmToggleButtonSetState(me->ready_radio, True, False);
  2484. XmToggleButtonSetState(me->supported_radio, False, False);
  2485. }
  2486. }
  2487. else
  2488. {
  2489. if(me->selected_list == SIZECTL_UNSUPPORTED)
  2490. {
  2491. XmString default_item;
  2492. default_item =
  2493. XmStringCreateLocalized((char*)PDM_MSG_SIZE_DEFAULT);
  2494. XmListAddItem(me->list_box, default_item, 0);
  2495. XmListSelectPos(me->list_box, 0, False);
  2496. XmStringFree(default_item);
  2497. }
  2498. else
  2499. {
  2500. XmString* list;
  2501. int count;
  2502. int pos;
  2503. /*
  2504. * set control sensitivities
  2505. */
  2506. frame_label_sensitive = True;
  2507. supported_radio_sensitive = True;
  2508. list_box_sensitive = True;
  2509. list_box_traverse = True;
  2510. if(PdmOidListCount(me->sizes_ready) > 0)
  2511. ready_radio_sensitive = True;
  2512. /*
  2513. * check to see if the selected size is supported
  2514. */
  2515. if(!PdmOidListHasOid(me->sizes_supported, me->selected_size))
  2516. {
  2517. /*
  2518. * the selected size is not supported
  2519. */
  2520. if(PdmOidListCount(me->sizes_ready) > 0)
  2521. {
  2522. /*
  2523. * use the 1st entry in the ready list
  2524. */
  2525. me->selected_size =
  2526. PdmOidListGetOid(me->sizes_ready, 0);
  2527. me->selected_list = SIZECTL_SIZES_READY;
  2528. }
  2529. else
  2530. {
  2531. /*
  2532. * the ready list is empty, use the 1st entry in the
  2533. * supported list
  2534. */
  2535. me->selected_size =
  2536. PdmOidListGetOid(me->sizes_supported, 0);
  2537. me->selected_list = SIZECTL_SIZES_SUPPORTED;
  2538. }
  2539. }
  2540. else if(me->selected_list == SIZECTL_SIZES_READY
  2541. &&
  2542. !PdmOidListHasOid(me->sizes_ready, me->selected_size))
  2543. {
  2544. /*
  2545. * the selected size is not in the ready list; use the
  2546. * supported list instead
  2547. */
  2548. me->selected_list = SIZECTL_SIZES_SUPPORTED;
  2549. }
  2550. /*
  2551. * set the appropriate radio button and update the list
  2552. */
  2553. if(me->selected_list == SIZECTL_SIZES_READY)
  2554. {
  2555. XmToggleButtonSetState(me->ready_radio, True, False);
  2556. XmToggleButtonSetState(me->supported_radio, False, False);
  2557. list = me->sizes_ready_xmstr;
  2558. count = PdmOidListCount(me->sizes_ready);
  2559. pos = 1 + PdmOidListGetIndex(me->sizes_ready,
  2560. me->selected_size);
  2561. }
  2562. else
  2563. {
  2564. XmToggleButtonSetState(me->supported_radio, True, False);
  2565. XmToggleButtonSetState(me->ready_radio, False, False);
  2566. list = me->sizes_supported_xmstr;
  2567. count = PdmOidListCount(me->sizes_supported);
  2568. pos = 1 + PdmOidListGetIndex(me->sizes_supported,
  2569. me->selected_size);
  2570. }
  2571. XmListAddItemsUnselected(me->list_box, list, count, 0);
  2572. SetListBoxSelection(me->list_box, pos);
  2573. }
  2574. }
  2575. /*
  2576. * update control sensitivities
  2577. */
  2578. XtSetSensitive(me->frame_label, frame_label_sensitive);
  2579. XtSetSensitive(me->list_box, list_box_sensitive);
  2580. XtVaSetValues(me->list_box, XmNtraversalOn, list_box_traverse, NULL);
  2581. XtSetSensitive(me->ready_radio, ready_radio_sensitive);
  2582. XtSetSensitive(me->supported_radio, supported_radio_sensitive);
  2583. }
  2584. /*
  2585. * ------------------------------------------------------------------------
  2586. * Name: SizeCtlResizeCB
  2587. *
  2588. * Description:
  2589. *
  2590. *
  2591. *
  2592. * Return value:
  2593. *
  2594. * None.
  2595. *
  2596. */
  2597. static void
  2598. SizeCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
  2599. {
  2600. SizeCtl* me = (SizeCtl*)client_data;
  2601. XtArgVal /* Dimension */ height, width, margin_width, new_width;
  2602. XtArgVal /* Position */ list_x, list_y, radio_x, radio_y;
  2603. XtArgVal /* Dimension */ list_h, list_w, radio_h, radio_w;
  2604. Widget scrolled_list = XtParent(me->list_box);
  2605. /*
  2606. * get current layout info
  2607. */
  2608. XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
  2609. XmNmarginWidth, &margin_width,
  2610. NULL);
  2611. XtVaGetValues(scrolled_list, XmNheight, &list_h, XmNwidth, &list_w, NULL);
  2612. XtVaGetValues(me->radio_box, XmNheight, &radio_h, XmNwidth, &radio_w,
  2613. NULL);
  2614. /*
  2615. * position controls side by side
  2616. */
  2617. list_x = margin_width;
  2618. radio_x = list_x + list_w;
  2619. /*
  2620. * center vertically
  2621. */
  2622. list_y = (height - list_h) / 2;
  2623. radio_y = (height - radio_h) / 2;
  2624. /*
  2625. * set new positions
  2626. */
  2627. XtVaSetValues(scrolled_list, XmNx, list_x, XmNy, list_y, NULL);
  2628. XtVaSetValues(me->radio_box, XmNx, radio_x, XmNy, radio_y, NULL);
  2629. /*
  2630. * update drawing area width and height
  2631. */
  2632. new_width = list_x + list_w + radio_w;
  2633. if(new_width > width)
  2634. XtVaSetValues(w, XmNwidth, new_width, NULL);
  2635. }
  2636. /*
  2637. * ------------------------------------------------------------------------
  2638. * Name: SizeCtlSetSingleSizeMode
  2639. *
  2640. * Description:
  2641. *
  2642. *
  2643. *
  2644. * Return value:
  2645. *
  2646. *
  2647. *
  2648. */
  2649. static void
  2650. SizeCtlSetSingleSizeMode(SizeCtl* me, PdmOid size)
  2651. {
  2652. if(size != pdmoid_none)
  2653. {
  2654. me->single_size_mode = True;
  2655. me->selected_size = size;
  2656. SizeCtlUpdate(me);
  2657. }
  2658. }
  2659. /*
  2660. * ------------------------------------------------------------------------
  2661. * Name: SizeCtlSetMultiSizeMode
  2662. *
  2663. * Description:
  2664. *
  2665. *
  2666. *
  2667. * Return value:
  2668. *
  2669. *
  2670. *
  2671. */
  2672. static void
  2673. SizeCtlSetMultiSizeMode(SizeCtl* me)
  2674. {
  2675. me->single_size_mode = False;
  2676. SizeCtlUpdate(me);
  2677. }
  2678. /*
  2679. * ------------------------------------------------------------------------
  2680. * Name: SizeCtlGetSize
  2681. *
  2682. * Description:
  2683. *
  2684. *
  2685. *
  2686. * Return value:
  2687. *
  2688. *
  2689. *
  2690. */
  2691. static PdmOid
  2692. SizeCtlGetSize(SizeCtl* me)
  2693. {
  2694. if(me->single_size_mode || me->selected_list == SIZECTL_UNSUPPORTED)
  2695. return pdmoid_none;
  2696. else
  2697. return me->selected_size;
  2698. }
  2699. /*
  2700. * ------------------------------------------------------------------------
  2701. * Name: SizeCtlReadyChangedCB
  2702. *
  2703. * Description:
  2704. *
  2705. *
  2706. *
  2707. * Return value:
  2708. *
  2709. *
  2710. *
  2711. */
  2712. static void
  2713. SizeCtlReadyChangedCB(Widget w,
  2714. XtPointer client_data,
  2715. XtPointer call_data)
  2716. {
  2717. XmToggleButtonCallbackStruct* cbs =
  2718. (XmToggleButtonCallbackStruct*)call_data;
  2719. if(cbs->set)
  2720. {
  2721. SizeCtl* me = (SizeCtl*)client_data;
  2722. me->selected_list = SIZECTL_SIZES_READY;
  2723. if(!PdmOidListHasOid(me->sizes_ready, me->selected_size))
  2724. me->selected_size = pdmoid_none;
  2725. SizeCtlUpdate(me);
  2726. }
  2727. }
  2728. /*
  2729. * ------------------------------------------------------------------------
  2730. * Name: SizeCtlSupportedChangedCB
  2731. *
  2732. * Description:
  2733. *
  2734. *
  2735. *
  2736. * Return value:
  2737. *
  2738. *
  2739. *
  2740. */
  2741. static void
  2742. SizeCtlSupportedChangedCB(Widget w,
  2743. XtPointer client_data,
  2744. XtPointer call_data)
  2745. {
  2746. XmToggleButtonCallbackStruct* cbs =
  2747. (XmToggleButtonCallbackStruct*)call_data;
  2748. if(cbs->set)
  2749. {
  2750. SizeCtl* me = (SizeCtl*)client_data;
  2751. me->selected_list = SIZECTL_SIZES_SUPPORTED;
  2752. SizeCtlUpdate(me);
  2753. }
  2754. }
  2755. /*
  2756. * ------------------------------------------------------------------------
  2757. * Name: SizeCtlSelectCB
  2758. *
  2759. * Description:
  2760. *
  2761. *
  2762. *
  2763. * Return value:
  2764. *
  2765. *
  2766. *
  2767. */
  2768. static void
  2769. SizeCtlSelectCB(Widget w,
  2770. XtPointer client_data,
  2771. XtPointer call_data)
  2772. {
  2773. XmListCallbackStruct* cbs = (XmListCallbackStruct*)call_data;
  2774. SizeCtl* me = (SizeCtl*)client_data;
  2775. if(!me->single_size_mode)
  2776. {
  2777. switch(me->selected_list)
  2778. {
  2779. case SIZECTL_SIZES_READY:
  2780. me->selected_size =
  2781. PdmOidListGetOid(me->sizes_ready, cbs->item_position - 1);
  2782. break;
  2783. case SIZECTL_SIZES_SUPPORTED:
  2784. me->selected_size =
  2785. PdmOidListGetOid(me->sizes_supported, cbs->item_position - 1);
  2786. break;
  2787. }
  2788. }
  2789. }
  2790. /*
  2791. * ------------------------------------------------------------------------
  2792. * Name: CreateOptionMenuPulldown
  2793. *
  2794. * Description:
  2795. *
  2796. *
  2797. *
  2798. * Return value:
  2799. *
  2800. *
  2801. *
  2802. */
  2803. static Widget
  2804. CreateOptionMenuPulldown(String pulldown_name,
  2805. Widget option_menu,
  2806. XtCallbackProc activate_proc,
  2807. XtPointer user_data,
  2808. XmString* item_list,
  2809. int item_count,
  2810. int initial_item)
  2811. {
  2812. Widget cascade_button;
  2813. Widget button;
  2814. Widget initial_selected = (Widget)NULL;
  2815. Widget pulldown;
  2816. char button_name[48];
  2817. int i;
  2818. pulldown =
  2819. XmCreatePulldownMenu(XtParent(option_menu), pulldown_name, NULL, 0);
  2820. for(i = 0; i < item_count; i++)
  2821. {
  2822. sprintf(button_name, "button_%d", i);
  2823. button = XtVaCreateManagedWidget(button_name,
  2824. xmPushButtonGadgetClass,
  2825. pulldown,
  2826. XmNuserData, user_data,
  2827. XmNlabelString, item_list[i],
  2828. NULL);
  2829. if(activate_proc != (XtCallbackProc)NULL)
  2830. XtAddCallback(button, XmNactivateCallback,
  2831. activate_proc, (XtPointer)(XtArgVal)i);
  2832. if(i == initial_item)
  2833. initial_selected = button;
  2834. }
  2835. XtVaSetValues(option_menu,
  2836. XmNsubMenuId, pulldown,
  2837. XmNmenuHistory, initial_selected,
  2838. NULL);
  2839. return pulldown;
  2840. }
  2841. /*
  2842. * ------------------------------------------------------------------------
  2843. * Name: CreateXmStringsFromOidList
  2844. *
  2845. * Description:
  2846. *
  2847. *
  2848. *
  2849. * Return value:
  2850. *
  2851. *
  2852. *
  2853. */
  2854. static XmString*
  2855. CreateXmStringsFromOidList(const PdmOidList* list)
  2856. {
  2857. int count = PdmOidListCount(list);
  2858. XmString* xmstr_list = (XmString*)NULL;
  2859. if(count > 0)
  2860. {
  2861. int i;
  2862. PdmOid oid;
  2863. const char* str;
  2864. /*
  2865. * build a list of Xm strings for the passed PdmOidList
  2866. */
  2867. xmstr_list = (XmString*)XtCalloc(count, sizeof(XmString));
  2868. for(i = 0; i < count; i++)
  2869. {
  2870. oid = PdmOidListGetOid(list, i);
  2871. str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
  2872. PdmOidMsgNum(oid),
  2873. PdmOidDefaultMsg(oid));
  2874. xmstr_list[i] = XmStringCreateLocalized((char*)str);
  2875. }
  2876. }
  2877. return xmstr_list;
  2878. }
  2879. /*
  2880. * ------------------------------------------------------------------------
  2881. * Name: FreeXmStringList
  2882. *
  2883. * Description:
  2884. *
  2885. *
  2886. *
  2887. * Return value:
  2888. *
  2889. *
  2890. *
  2891. */
  2892. static void
  2893. FreeXmStringList(XmString* list, int count)
  2894. {
  2895. int i;
  2896. for(i = 0; i < count; i++)
  2897. XmStringFree(list[i]);
  2898. XtFree((char*)list);
  2899. }
  2900. /*
  2901. * ------------------------------------------------------------------------
  2902. * Name: IconMaxDimension
  2903. *
  2904. * Description:
  2905. *
  2906. *
  2907. *
  2908. * Return value:
  2909. *
  2910. *
  2911. *
  2912. */
  2913. static void
  2914. IconMaxDimension(Widget icon_label,
  2915. PdmPixmapList* pixmap_list, int i,
  2916. Dimension* max_width, Dimension* max_height)
  2917. {
  2918. Dimension width, height;
  2919. XtArgVal width0, height0;
  2920. /*
  2921. * set the pixmap in the label
  2922. */
  2923. XtVaSetValues(icon_label,
  2924. XmNlabelPixmap, PdmPixmapListGetPixmap(pixmap_list, i),
  2925. NULL);
  2926. /*
  2927. * get the label dimensions
  2928. */
  2929. XtVaGetValues(icon_label,
  2930. XmNwidth, &width0,
  2931. XmNheight, &height0,
  2932. NULL);
  2933. width = (Dimension)width0;
  2934. height = (Dimension)height0;
  2935. /*
  2936. * update the max dimensions
  2937. */
  2938. if(width > *max_width)
  2939. *max_width = width;
  2940. if(height > *max_height)
  2941. *max_height = height;
  2942. }
  2943. /*
  2944. * ------------------------------------------------------------------------
  2945. * Name: PdmPixmapListNew
  2946. *
  2947. * Description:
  2948. *
  2949. *
  2950. *
  2951. * Return value:
  2952. *
  2953. *
  2954. *
  2955. */
  2956. static PdmPixmapList*
  2957. PdmPixmapListNew(int count,
  2958. Widget w,
  2959. Boolean stipple)
  2960. {
  2961. PdmPixmapList* me = (PdmPixmapList*)XtCalloc(1, sizeof(PdmPixmapList));
  2962. XtArgVal fg, bg;
  2963. me->pixmap = (Pixmap*)XtCalloc(count, sizeof(Pixmap));
  2964. me->image_name = (char**)XtCalloc(count, sizeof(char*));
  2965. me->screen = XtScreen(w);
  2966. if(stipple)
  2967. {
  2968. Widget xmscr = XmGetXmScreen(me->screen);
  2969. XtVaGetValues(xmscr, XmNinsensitiveStippleBitmap, &me->stipple, NULL);
  2970. }
  2971. else
  2972. {
  2973. me->stipple = None;
  2974. }
  2975. XtVaGetValues(w,
  2976. XmNforeground, &fg,
  2977. XmNbackground, &bg,
  2978. NULL);
  2979. me->foreground = (Pixel)fg;
  2980. me->background = (Pixel)bg;
  2981. return me;
  2982. }
  2983. /*
  2984. * ------------------------------------------------------------------------
  2985. * Name: PdmPixmapListDelete
  2986. *
  2987. * Description:
  2988. *
  2989. *
  2990. *
  2991. * Return value:
  2992. *
  2993. *
  2994. *
  2995. */
  2996. static void
  2997. PdmPixmapListDelete(PdmPixmapList* me)
  2998. {
  2999. if(me != (PdmPixmapList*)NULL)
  3000. {
  3001. int i;
  3002. for(i = 0; i < PdmPixmapListCount(me); i++)
  3003. {
  3004. if(me->pixmap[i] != (Pixmap)NULL)
  3005. {
  3006. if(me->stipple == None)
  3007. {
  3008. if(me->pixmap[i] != None)
  3009. XmDestroyPixmap(me->screen, me->pixmap[i]);
  3010. }
  3011. else
  3012. {
  3013. if(me->pixmap[i] != None)
  3014. XFreePixmap(DisplayOfScreen(me->screen),
  3015. me->pixmap[i]);
  3016. }
  3017. XtFree((char*)me->image_name[i]);
  3018. }
  3019. }
  3020. XtFree((char*)me->pixmap);
  3021. XtFree((char*)me->image_name);
  3022. XtFree((char*)me);
  3023. }
  3024. }
  3025. /*
  3026. * ------------------------------------------------------------------------
  3027. * Name: PdmPixmapSetImageName
  3028. *
  3029. * Description:
  3030. *
  3031. *
  3032. *
  3033. * Return value:
  3034. *
  3035. *
  3036. *
  3037. */
  3038. static void
  3039. PdmPixmapListSetImageName(PdmPixmapList* me,
  3040. const char* image_name,
  3041. int i)
  3042. {
  3043. me->image_name[i] = XtNewString(image_name);
  3044. }
  3045. /*
  3046. * ------------------------------------------------------------------------
  3047. * Name: PdmPixmapListGetPixmap
  3048. *
  3049. * Description:
  3050. *
  3051. *
  3052. *
  3053. * Return value:
  3054. *
  3055. *
  3056. *
  3057. */
  3058. static Pixmap
  3059. PdmPixmapListGetPixmap(PdmPixmapList* me, int i)
  3060. {
  3061. if(me->pixmap[i] == None)
  3062. {
  3063. me->pixmap[i] = XmGetPixmap(me->screen, me->image_name[i],
  3064. me->foreground, me->background);
  3065. if(me->pixmap[i] == XmUNSPECIFIED_PIXMAP)
  3066. {
  3067. me->pixmap[i] = None;
  3068. }
  3069. else if(me->stipple != None)
  3070. {
  3071. Pixmap xmpixmap = me->pixmap[i];
  3072. Display* display = DisplayOfScreen(me->screen);
  3073. Window root;
  3074. int x, y;
  3075. unsigned int width, height, border_width, depth;
  3076. GC gc;
  3077. XGCValues values;
  3078. /*
  3079. * make a copy of the pixmap cached by motif
  3080. */
  3081. XGetGeometry(display, xmpixmap, &root, &x, &y,
  3082. &width, &height, &border_width, &depth);
  3083. me->pixmap[i] =
  3084. XCreatePixmap(display, xmpixmap, width, height, depth);
  3085. gc = XCreateGC(display, me->pixmap[i], (unsigned long)0, &values);
  3086. XCopyArea(display, xmpixmap, me->pixmap[i], gc,
  3087. 0, 0, width, height, 0, 0);
  3088. /*
  3089. * stipple it
  3090. */
  3091. XSetFillStyle(display, gc, FillStippled);
  3092. XSetStipple(display, gc, me->stipple);
  3093. XFillRectangle(display, me->pixmap[i], gc, 0, 0, width, height);
  3094. /*
  3095. * clean up
  3096. */
  3097. XFreeGC(display, gc);
  3098. XmDestroyPixmap(me->screen, xmpixmap);
  3099. }
  3100. }
  3101. return me->pixmap[i];
  3102. }
  3103. /*
  3104. * ------------------------------------------------------------------------
  3105. * Name: SetListBoxSelection
  3106. *
  3107. * Description:
  3108. *
  3109. *
  3110. * Return value:
  3111. *
  3112. * None.
  3113. *
  3114. */
  3115. static void
  3116. SetListBoxSelection(Widget list_box, int position)
  3117. {
  3118. XtArgVal visible_item_count0, item_count0;
  3119. int visible_item_count;
  3120. int item_count;
  3121. int middle_offset;
  3122. int first_visible_pos;
  3123. /*
  3124. * Scroll the list, making the item at the indicated position
  3125. * visible in the center of the list box, and make
  3126. * it the initial selection.
  3127. */
  3128. XtVaGetValues(list_box,
  3129. XmNitemCount, &item_count0,
  3130. XmNvisibleItemCount, &visible_item_count0,
  3131. NULL);
  3132. item_count = (int)item_count0;
  3133. visible_item_count = (int)visible_item_count0;
  3134. if(item_count > visible_item_count)
  3135. {
  3136. middle_offset = (visible_item_count+1) / 2;
  3137. if(position > middle_offset)
  3138. if(position > item_count - middle_offset)
  3139. first_visible_pos = item_count - visible_item_count +1;
  3140. else
  3141. first_visible_pos = position - middle_offset + 1;
  3142. else
  3143. first_visible_pos = 1;
  3144. XmListSetPos(list_box, first_visible_pos);
  3145. }
  3146. if(position > 0)
  3147. XmListSelectPos(list_box, position, False);
  3148. else
  3149. XmListDeselectAllItems(list_box);
  3150. }
  3151. /*
  3152. * ------------------------------------------------------------------------
  3153. * Name: GetIconFileName
  3154. *
  3155. * Description:
  3156. *
  3157. *
  3158. * Return value:
  3159. *
  3160. * None.
  3161. *
  3162. */
  3163. static String
  3164. GetIconFileName(Widget w, String resource_name)
  3165. {
  3166. String icon_file_name;
  3167. XtResource res_struct;
  3168. res_struct.resource_name = resource_name;
  3169. res_struct.resource_class = resource_name;
  3170. res_struct.resource_type = XmRString;
  3171. res_struct.resource_size = sizeof(String);
  3172. res_struct.resource_offset = 0;
  3173. res_struct.default_type = XmRImmediate;
  3174. res_struct.default_addr = (XtPointer)NULL;
  3175. XtGetApplicationResources(w, (XtPointer)&icon_file_name,
  3176. &res_struct, 1, (ArgList)NULL, 0);
  3177. return icon_file_name;
  3178. }