PsubDefProc.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563
  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: PsubDefProc.c /main/14 1996/12/02 10:51:20 rswiston $ */
  24. /*
  25. * DtPrint/PsubDefProc.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. /*
  37. * ------------------------------------------------------------------------
  38. * Include Files
  39. *
  40. */
  41. #include <stdlib.h>
  42. #include <stdarg.h>
  43. #include <stdio.h>
  44. #include <Xm/XmAll.h>
  45. #include <Dt/HelpDialog.h>
  46. #include <Dt/DtNlUtils.h>
  47. #include <Dt/HourGlass.h>
  48. /*
  49. * PrintSetupBP.h is included only for access to the DtPrintDefProcData
  50. * member of the widget instance structure.
  51. */
  52. #include <Dt/PrintSetupBP.h>
  53. #include <Dt/PsubUtilI.h>
  54. /*
  55. * ------------------------------------------------------------------------
  56. * Constant Definitions
  57. *
  58. */
  59. #define HELP_VOLUME "LibDtPrint"
  60. #define PRINTER_INFO_HELP_ID "PrinterInfo"
  61. #define SELECT_PRINTER_HELP_ID "SelectPrinter"
  62. #define SELECT_FILE_HELP_ID "SelectFile"
  63. /*
  64. * ------------------------------------------------------------------------
  65. * Static Function Declarations
  66. *
  67. */
  68. static XtEnum BuildPrinterLists(
  69. Widget w,
  70. DtPrintDefaultProcData* dpd,
  71. int* item_count);
  72. static XmStringTable BuildPrinterSelectionItems(
  73. Display* display,
  74. DtPrintDefaultProcData* dpd,
  75. int item_count,
  76. String initial_printer,
  77. XmStringTag tag);
  78. static void CloseSelectPrinterInfoConnection(
  79. DtPrintDefaultProcData* dpd);
  80. static int CompareSelectPrinterRecs(const void*,
  81. const void*);
  82. static String CompoundTextToString(
  83. Display* display,
  84. unsigned char* compound_text);
  85. static XtEnum CreateFileSelectionBox(
  86. Widget parent,
  87. Widget psub,
  88. DtPrintDefaultProcData* dpd);
  89. static XtEnum CreatePrinterInfoBox(
  90. Widget parent,
  91. Widget psub,
  92. DtPrintDefaultProcData* dpd);
  93. static XtEnum CreatePrinterSelectionBox(
  94. Widget parent,
  95. Widget psub,
  96. DtPrintDefaultProcData* dpd);
  97. static void DestroyWidgetCB(
  98. Widget w,
  99. XtPointer client_data,
  100. XtPointer call_data);
  101. static void DtPrintDefProcDestroyCB(Widget w,
  102. XtPointer client_data,
  103. XtPointer call_data);
  104. static void ErrorMessageDestroyCB(
  105. Widget w,
  106. XtPointer client_data,
  107. XtPointer call_data);
  108. static String FindSelectedPrinter(
  109. Display* display,
  110. DtPrintDefaultProcData* dpd);
  111. static void FreeSelectPrinterData(
  112. DtPrintDefaultProcData* dpd);
  113. static Widget GetWMShellAncestor(
  114. Widget w);
  115. static void HelpDialogDestroyCB(
  116. Widget w,
  117. XtPointer client_data,
  118. XtPointer call_data);
  119. static void InfoBoxLayoutCB(
  120. Widget widget,
  121. XtPointer client_data,
  122. XtPointer call_data);
  123. static void ParseFileNameSpec(
  124. const char* file_name,
  125. XmString* pattern,
  126. char** name_only);
  127. static void PresentErrorDialog(
  128. Widget w,
  129. String title,
  130. String message,
  131. ...);
  132. static void PresentHelp(
  133. Widget w,
  134. const char* help_volume,
  135. const char* location_id);
  136. static void PresentVerifyError(
  137. Widget w,
  138. XtEnum status,
  139. String printer_spec);
  140. static void PrinterInfoDestroyCB(
  141. Widget w,
  142. XtPointer client_data,
  143. XtPointer call_data);
  144. static void PrinterInfoHelpCB(
  145. Widget w,
  146. XtPointer client_data,
  147. XtPointer call_data);
  148. static void SelectFileDestroyCB(
  149. Widget w,
  150. XtPointer client_data,
  151. XtPointer call_data);
  152. static void SelectFileHelpCB(
  153. Widget w,
  154. XtPointer client_data,
  155. XtPointer call_data);
  156. static void SelectPrinterCB(
  157. Widget w,
  158. XtPointer client_data,
  159. XtPointer call_data);
  160. static void SelectPrinterDestroyCB(
  161. Widget w,
  162. XtPointer client_data,
  163. XtPointer call_data);
  164. static void SelectPrinterHelpCB(
  165. Widget w,
  166. XtPointer client_data,
  167. XtPointer call_data);
  168. static void SelectPrinterInfoCB(
  169. Widget w,
  170. XtPointer client_data,
  171. XtPointer call_data);
  172. static void SelectPrinterItemCB(
  173. Widget w,
  174. XtPointer client_data,
  175. XtPointer call_data);
  176. static void SetListBoxSelection(
  177. Widget list_box,
  178. int position);
  179. static void UpdateFileNameCB(
  180. Widget w,
  181. XtPointer client_data,
  182. XtPointer call_data);
  183. /*
  184. * ------------------------------------------------------------------------
  185. * Name: BuildPrinterLists
  186. *
  187. * Description:
  188. *
  189. * Retrieves lists of printers from the Xp server found in the
  190. * XpServerList resource or XPSERVERLIST env var.
  191. *
  192. * Return value:
  193. *
  194. *
  195. *
  196. */
  197. static XtEnum
  198. BuildPrinterLists(
  199. Widget w,
  200. DtPrintDefaultProcData* dpd,
  201. int* item_count)
  202. {
  203. String* server_list;
  204. int server_count;
  205. int i, j;
  206. Display* display;
  207. int error_base;
  208. int event_base;
  209. #if 0 && defined(PRINTING_SUPPORTED)
  210. XPPrinterList xp_printer_list;
  211. #endif /* PRINTING_SUPPORTED */
  212. DtPrintSelectPrinterList printer_list;
  213. /*
  214. * clean up previous lists if needed
  215. */
  216. FreeSelectPrinterData(dpd);
  217. /*
  218. * get the list of servers
  219. */
  220. server_list = _DtPrintGetXpServerList(w);
  221. if((String*)NULL == server_list)
  222. return DtPRINT_FAILURE;
  223. /*
  224. * get the printer list for each valid Xp server
  225. */
  226. for(server_count = 0;
  227. (String)NULL != server_list[server_count];
  228. server_count++);
  229. dpd->xp_server_list =
  230. (String*)XtCalloc(server_count, sizeof(String));
  231. dpd->printer_lists = (DtPrintSelectPrinterList*)
  232. XtCalloc(server_count, sizeof(DtPrintSelectPrinterList));
  233. dpd->printer_counts =
  234. (int*)XtCalloc(server_count, sizeof(int));
  235. for(i = 0, *item_count = 0; i < server_count; i++)
  236. {
  237. /*
  238. * ensure the server is a valid Xp server
  239. */
  240. display = XOpenDisplay(server_list[i]);
  241. if((Display*)NULL == display)
  242. continue;
  243. #if 0 && defined(PRINTING_SUPPORTED)
  244. if(!XpQueryExtension(display, &event_base, &error_base))
  245. {
  246. #endif /* PRINTING_SUPPORTED */
  247. XCloseDisplay(display);
  248. continue;
  249. #if 0 && defined(PRINTING_SUPPORTED)
  250. }
  251. #endif /* PRINTING_SUPPORTED */
  252. /*
  253. * add the server to the xp server list
  254. */
  255. dpd->xp_server_list[dpd->xp_server_count] =
  256. XtNewString(server_list[i]);
  257. /*
  258. * get the printer list for the server
  259. */
  260. #if 0 && defined(PRINTING_SUPPORTED)
  261. xp_printer_list =
  262. XpGetPrinterList(display, (char*)NULL,
  263. &dpd->printer_counts[dpd->xp_server_count]);
  264. #endif /* PRINTING_SUPPORTED */
  265. /*
  266. * save a copy of the compound text printer name and
  267. * string versions of the name and description for
  268. * eventual use in the printer selection list.
  269. */
  270. dpd->printer_lists[dpd->xp_server_count] = (DtPrintSelectPrinterList)
  271. XtCalloc(dpd->printer_counts[dpd->xp_server_count],
  272. sizeof(DtPrintSelectPrinterRec));
  273. printer_list = dpd->printer_lists[dpd->xp_server_count];
  274. #if 0 && defined(PRINTING_SUPPORTED)
  275. for(j = 0; j < dpd->printer_counts[dpd->xp_server_count]; j++)
  276. {
  277. printer_list[j].printer_name_ct =
  278. XtNewString(xp_printer_list[j].name);
  279. printer_list[j].printer_name =
  280. CompoundTextToString(display,
  281. (unsigned char*)xp_printer_list[j].name);
  282. printer_list[j].description =
  283. CompoundTextToString(display,
  284. (unsigned char*)xp_printer_list[j].desc);
  285. }
  286. XpFreePrinterList(xp_printer_list);
  287. #endif /* PRINTING_SUPPORTED */
  288. /*
  289. * sort the printer list
  290. */
  291. if(0 < dpd->printer_counts[dpd->xp_server_count])
  292. qsort((void*)printer_list,
  293. dpd->printer_counts[dpd->xp_server_count],
  294. sizeof(DtPrintSelectPrinterRec), CompareSelectPrinterRecs);
  295. *item_count += dpd->printer_counts[dpd->xp_server_count];
  296. ++dpd->xp_server_count;
  297. XCloseDisplay(display);
  298. }
  299. _DtPrintFreeStringList(server_list);
  300. if(0 == *item_count)
  301. {
  302. FreeSelectPrinterData(dpd);
  303. return DtPRINT_FAILURE;
  304. }
  305. else
  306. return DtPRINT_SUCCESS;
  307. }
  308. /*
  309. * ------------------------------------------------------------------------
  310. * Name: BuildPrinterSelectionItems
  311. *
  312. * Description:
  313. *
  314. * Builds the list of XmString items (printer name + desc) to be set
  315. * in the printer selection list box.
  316. *
  317. * Return value:
  318. *
  319. * None.
  320. *
  321. */
  322. static XmStringTable
  323. BuildPrinterSelectionItems(
  324. Display* display,
  325. DtPrintDefaultProcData* dpd,
  326. int item_count,
  327. String initial_printer,
  328. XmStringTag tag)
  329. {
  330. XmStringTable items;
  331. int i, j;
  332. char* buf = (char*)NULL;
  333. Cardinal buf_size = 0;
  334. Cardinal new_size;
  335. int current_item;
  336. String name, full_name, desc;
  337. char* server_name;
  338. int server_len;
  339. items = (XmStringTable)XtCalloc(item_count, sizeof(XmString));
  340. for(i = 0, current_item = 0; i < dpd->xp_server_count; i++)
  341. {
  342. server_name = dpd->xp_server_list[i];
  343. server_len = strlen(server_name);
  344. for(j = 0; j < dpd->printer_counts[i]; j++, current_item++)
  345. {
  346. /*
  347. * build a fully qualified X printer specifier
  348. */
  349. name = (dpd->printer_lists[i])[j].printer_name;
  350. (dpd->printer_lists[i])[j].printer_name = (String)NULL;
  351. full_name =
  352. _DtPrintCreateXPrinterSpecifier(name, server_name,
  353. DtPRINT_NET_UNSPECIFIED,
  354. -1, -1);
  355. XtFree(name);
  356. /*
  357. * check to see if this should be the initially selected printer
  358. */
  359. if(dpd->selected_printer == 0
  360. && (String)NULL != initial_printer)
  361. if(strcmp(initial_printer, full_name) == 0)
  362. dpd->selected_printer = current_item + 1;
  363. /*
  364. * convert the printer description
  365. */
  366. desc = (dpd->printer_lists[i])[j].description;
  367. (dpd->printer_lists[i])[j].description = (String)NULL;
  368. if((String)NULL != desc && '\0' != *desc)
  369. {
  370. /*
  371. * chop the description after the 1st line
  372. */
  373. char* ptr = Dt_strchr(desc, '\n');
  374. if((char*)NULL != ptr)
  375. *ptr = '\0';
  376. }
  377. /*
  378. * ensure the format buffer is large enough to contain
  379. * the formatted list item
  380. */
  381. new_size = 2;
  382. new_size += full_name ? strlen(full_name) : 0;
  383. new_size += desc ? strlen(desc) : 0;
  384. if(new_size > buf_size)
  385. {
  386. buf_size = new_size;
  387. buf = XtRealloc(buf, buf_size);
  388. }
  389. /*
  390. * format the item, and add it to the item list
  391. */
  392. sprintf(buf, "%s\t%s",
  393. full_name ? full_name : "",
  394. desc ? desc : "");
  395. XtFree(desc);
  396. XtFree(full_name);
  397. items[current_item] =
  398. XmStringGenerate((XtPointer)buf, (XmStringTag)NULL,
  399. XmMULTIBYTE_TEXT, tag);
  400. }
  401. }
  402. XtFree(buf);
  403. return items;
  404. }
  405. /*
  406. * ------------------------------------------------------------------------
  407. * Name: CloseSelectPrinterInfoConnection
  408. *
  409. * Description:
  410. *
  411. * Close the X printer connection maintained for the Select Printer
  412. * dialog's Printer Information dialog.
  413. *
  414. * Return value:
  415. *
  416. * None.
  417. *
  418. */
  419. static void
  420. CloseSelectPrinterInfoConnection(
  421. DtPrintDefaultProcData* dpd)
  422. {
  423. if((Display*)NULL != dpd->select_printer_info_display)
  424. {
  425. #if 0 && defined(PRINTING_SUPPORTED)
  426. if((XPContext)None != dpd->select_printer_info_context)
  427. {
  428. XpDestroyContext(dpd->select_printer_info_display,
  429. dpd->select_printer_info_context);
  430. dpd->select_printer_info_context = (XPContext)None;
  431. }
  432. #endif /* PRINTING_SUPPORTED */
  433. XCloseDisplay(dpd->select_printer_info_display);
  434. dpd->select_printer_info_display = (Display*)NULL;
  435. }
  436. }
  437. /*
  438. * ------------------------------------------------------------------------
  439. * Name: CompareSelectPrinterRecs
  440. *
  441. * Description:
  442. *
  443. * Compares the printer names in two DtPrintSelectPrinterRecs.
  444. *
  445. * Return value:
  446. *
  447. * Returns an integer greater than, equal to, or less than zero,
  448. * according to whether the printer name in spr1 is greater
  449. * than, equal to, or less than the printer name in spr2.
  450. *
  451. */
  452. static int
  453. CompareSelectPrinterRecs(const void* spr1,
  454. const void* spr2)
  455. {
  456. return strcoll(((DtPrintSelectPrinterRec*)spr1)->printer_name,
  457. ((DtPrintSelectPrinterRec*)spr2)->printer_name);
  458. }
  459. /*
  460. * ------------------------------------------------------------------------
  461. * Name: CompoundTextToString
  462. *
  463. * Description:
  464. *
  465. *
  466. *
  467. * Return value:
  468. *
  469. * None.
  470. *
  471. */
  472. static String
  473. CompoundTextToString(
  474. Display* display,
  475. unsigned char* compound_text)
  476. {
  477. String str = (String)NULL;
  478. if((unsigned char*)NULL != compound_text)
  479. {
  480. XTextProperty text_prop;
  481. char** list;
  482. int count;
  483. text_prop.encoding = XInternAtom(display, "COMPOUND_TEXT", False);
  484. text_prop.format = 8;
  485. text_prop.value = compound_text;
  486. text_prop.nitems = strlen((char*)text_prop.value);
  487. if(Success ==
  488. XmbTextPropertyToTextList(display, &text_prop, &list, &count))
  489. {
  490. if(count > 0)
  491. str = XtNewString(list[0]);
  492. XFreeStringList(list);
  493. }
  494. }
  495. return str;
  496. }
  497. /*
  498. * ------------------------------------------------------------------------
  499. * Name: CreateFileSelectionBox
  500. *
  501. * Description:
  502. *
  503. * Creates the file selection dialog box.
  504. *
  505. * Return value:
  506. *
  507. * None.
  508. *
  509. */
  510. static XtEnum
  511. CreateFileSelectionBox(
  512. Widget parent,
  513. Widget psub,
  514. DtPrintDefaultProcData* dpd)
  515. {
  516. Arg args[15];
  517. Cardinal n;
  518. XmString title_xmstr;
  519. title_xmstr = XmStringCreateLocalized(SELECT_FILE_TITLE);
  520. n = 0;
  521. /*
  522. * dialog resources
  523. */
  524. XtSetArg(args[n], XmNdialogTitle, title_xmstr); n++;
  525. XtSetArg(args[n], XmNdialogStyle,
  526. XmDIALOG_PRIMARY_APPLICATION_MODAL); n++;
  527. XtSetArg(args[n], XmNdeleteResponse, XmUNMAP); n++;
  528. /*
  529. * file selection box resources
  530. */
  531. XtSetArg(args[n], XmNautoUnmanage, True); n++;
  532. /*
  533. * create the file selection box dialog
  534. */
  535. dpd->file_selection_box =
  536. XmCreateFileSelectionDialog(parent, "_PsubDefProcFileSelectionBox",
  537. args, n);
  538. XmStringFree(title_xmstr);
  539. if(dpd->file_selection_box == (Widget)NULL)
  540. return DtPRINT_FAILURE;
  541. /*
  542. * add callbacks
  543. */
  544. XtAddCallback(dpd->file_selection_box, XmNokCallback,
  545. UpdateFileNameCB, (XtPointer)psub);
  546. XtAddCallback(dpd->file_selection_box, XmNhelpCallback,
  547. SelectFileHelpCB, (XtPointer)psub);
  548. XtAddCallback(dpd->file_selection_box, XmNdestroyCallback,
  549. SelectFileDestroyCB, (XtPointer)psub);
  550. /*
  551. * return
  552. */
  553. return DtPRINT_SUCCESS;
  554. }
  555. /*
  556. * ------------------------------------------------------------------------
  557. * Name: CreatePrinterInfoBox
  558. *
  559. * Description:
  560. *
  561. * Creates the printer information dialog box.
  562. *
  563. * Return value:
  564. *
  565. * None.
  566. *
  567. */
  568. static XtEnum
  569. CreatePrinterInfoBox(
  570. Widget parent,
  571. Widget psub,
  572. DtPrintDefaultProcData* dpd)
  573. {
  574. Arg args[15];
  575. Cardinal n;
  576. XmString title_xmstr;
  577. Widget manager;
  578. Widget description_label, description;
  579. Widget name_label, name;
  580. Widget format_label, format;
  581. Widget model_label, model;
  582. XmString label;
  583. title_xmstr = XmStringCreateLocalized(PRINTER_INFO_TITLE);
  584. n = 0;
  585. /*
  586. * dialog resources
  587. */
  588. XtSetArg(args[n], XmNdialogTitle, title_xmstr); n++;
  589. XtSetArg(args[n], XmNdialogStyle,
  590. XmDIALOG_PRIMARY_APPLICATION_MODAL); n++;
  591. XtSetArg(args[n], XmNdeleteResponse, XmUNMAP); n++;
  592. /*
  593. * printer info box resources
  594. */
  595. XtSetArg(args[n], XmNautoUnmanage, True); n++;
  596. /*
  597. * create the dialog
  598. */
  599. dpd->printer_info_box =
  600. XmCreateInformationDialog(parent, "_PsubDefProcPrinterInfoBox",
  601. args, n);
  602. XmStringFree(title_xmstr);
  603. if(dpd->printer_info_box == (Widget)NULL)
  604. return DtPRINT_FAILURE;
  605. /*
  606. * add callbacks
  607. */
  608. XtAddCallback(dpd->printer_info_box, XmNhelpCallback,
  609. PrinterInfoHelpCB, (XtPointer)psub);
  610. XtAddCallback(dpd->printer_info_box, XmNdestroyCallback,
  611. PrinterInfoDestroyCB, (XtPointer)psub);
  612. XtAddCallback(dpd->printer_info_box, XmNmapCallback,
  613. InfoBoxLayoutCB, (XtPointer)dpd);
  614. /*
  615. * unmanage unwanted children
  616. */
  617. XtUnmanageChild(XtNameToWidget(dpd->printer_info_box, "Cancel"));
  618. XtUnmanageChild(XtNameToWidget(dpd->printer_info_box, "Message"));
  619. XtUnmanageChild(XtNameToWidget(dpd->printer_info_box, "Symbol"));
  620. /*
  621. * create the control manager
  622. */
  623. manager =
  624. XtVaCreateManagedWidget("PrinterInfoForm", xmFormWidgetClass,
  625. dpd->printer_info_box,
  626. XmNallowOverlap, False,
  627. NULL);
  628. /*
  629. * printer description
  630. */
  631. label = XmStringCreateLocalized(DESCRIPTION_LABEL);
  632. description_label =
  633. XtVaCreateManagedWidget("DescriptionLabel",
  634. xmLabelWidgetClass,
  635. manager,
  636. XmNlabelString, label,
  637. XmNleftAttachment, XmATTACH_FORM,
  638. XmNtopAttachment, XmATTACH_FORM,
  639. XmNtopOffset, 5,
  640. NULL);
  641. XmStringFree(label);
  642. description =
  643. XtVaCreateManagedWidget("Description",
  644. xmLabelWidgetClass,
  645. manager,
  646. XmNalignment, XmALIGNMENT_BEGINNING,
  647. XmNleftAttachment, XmATTACH_WIDGET,
  648. XmNleftWidget, description_label,
  649. XmNleftOffset, 10,
  650. XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  651. XmNtopWidget, description_label,
  652. NULL);
  653. /*
  654. * printer name
  655. */
  656. label = XmStringCreateLocalized(PRINTER_NAME_LABEL);
  657. name_label =
  658. XtVaCreateManagedWidget("NameLabel",
  659. xmLabelWidgetClass,
  660. manager,
  661. XmNlabelString, label,
  662. XmNleftAttachment, XmATTACH_FORM,
  663. XmNtopAttachment, XmATTACH_WIDGET,
  664. XmNtopWidget, description,
  665. XmNtopOffset, 5,
  666. NULL);
  667. XmStringFree(label);
  668. name =
  669. XtVaCreateManagedWidget("Name",
  670. xmLabelWidgetClass,
  671. manager,
  672. XmNleftAttachment, XmATTACH_WIDGET,
  673. XmNleftWidget, name_label,
  674. XmNleftOffset, 10,
  675. XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  676. XmNtopWidget, name_label,
  677. NULL);
  678. /*
  679. * printer format
  680. */
  681. label = XmStringCreateLocalized(FORMAT_LABEL);
  682. format_label =
  683. XtVaCreateManagedWidget("FormatLabel",
  684. xmLabelWidgetClass,
  685. manager,
  686. XmNlabelString, label,
  687. XmNleftAttachment, XmATTACH_FORM,
  688. XmNtopAttachment, XmATTACH_WIDGET,
  689. XmNtopWidget, name_label,
  690. XmNtopOffset, 5,
  691. NULL);
  692. XmStringFree(label);
  693. format =
  694. XtVaCreateManagedWidget("Format",
  695. xmLabelWidgetClass,
  696. manager,
  697. XmNleftAttachment, XmATTACH_WIDGET,
  698. XmNleftWidget, format_label,
  699. XmNleftOffset, 10,
  700. XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  701. XmNtopWidget, format_label,
  702. NULL);
  703. /*
  704. * printer model
  705. */
  706. label = XmStringCreateLocalized(MODEL_LABEL);
  707. model_label =
  708. XtVaCreateManagedWidget("ModelLabel",
  709. xmLabelWidgetClass,
  710. manager,
  711. XmNlabelString, label,
  712. XmNleftAttachment, XmATTACH_FORM,
  713. XmNtopAttachment, XmATTACH_WIDGET,
  714. XmNtopWidget, format_label,
  715. XmNtopOffset, 5,
  716. NULL);
  717. XmStringFree(label);
  718. model =
  719. XtVaCreateManagedWidget("Model",
  720. xmLabelWidgetClass,
  721. manager,
  722. XmNalignment, XmALIGNMENT_BEGINNING,
  723. XmNleftAttachment, XmATTACH_WIDGET,
  724. XmNleftWidget, model_label,
  725. XmNleftOffset, 10,
  726. XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  727. XmNtopWidget, model_label,
  728. NULL);
  729. /*
  730. * return
  731. */
  732. return DtPRINT_SUCCESS;
  733. }
  734. /*
  735. * ------------------------------------------------------------------------
  736. * Name: CreatePrinterSelectionBox
  737. *
  738. * Description:
  739. *
  740. * Creates the printer selection dialog box.
  741. *
  742. * Return value:
  743. *
  744. * None.
  745. *
  746. */
  747. static XtEnum
  748. CreatePrinterSelectionBox(
  749. Widget parent,
  750. Widget psub,
  751. DtPrintDefaultProcData* dpd)
  752. {
  753. Arg args[15];
  754. Cardinal n;
  755. Widget control;
  756. XmString list_label;
  757. XmString title_xmstr;
  758. XmString info_label;
  759. title_xmstr = XmStringCreateLocalized(MORE_PRINTERS_TITLE);
  760. list_label = XmStringCreateLocalized(PRINTER_LIST_LABEL);
  761. info_label = XmStringCreateLocalized(PRINTER_INFO_LABEL);
  762. n = 0;
  763. /*
  764. * dialog resources
  765. */
  766. XtSetArg(args[n], XmNdialogTitle, title_xmstr); n++;
  767. XtSetArg(args[n], XmNdialogStyle,
  768. XmDIALOG_PRIMARY_APPLICATION_MODAL); n++;
  769. XtSetArg(args[n], XmNdeleteResponse, XmDESTROY); n++;
  770. /*
  771. * selection box resources
  772. */
  773. XtSetArg(args[n], XmNautoUnmanage, True); n++;
  774. XtSetArg(args[n], XmNlistLabelString, list_label); n++;
  775. XtSetArg(args[n], XmNapplyLabelString, info_label); n++;
  776. /*
  777. * create the dialog
  778. */
  779. dpd->printer_selection_box =
  780. XmCreateSelectionDialog(parent, "_PsubDefProcPrinterSelectionBox",
  781. args, n);
  782. XmStringFree(list_label);
  783. XmStringFree(info_label);
  784. XmStringFree(title_xmstr);
  785. if(dpd->printer_selection_box == (Widget)NULL)
  786. return DtPRINT_FAILURE;
  787. /*
  788. * add callbacks
  789. */
  790. XtAddCallback(dpd->printer_selection_box, XmNokCallback,
  791. SelectPrinterCB, (XtPointer)psub);
  792. XtAddCallback(dpd->printer_selection_box, XmNapplyCallback,
  793. SelectPrinterInfoCB, (XtPointer)psub);
  794. XtAddCallback(dpd->printer_selection_box, XmNcancelCallback,
  795. SelectPrinterCB, (XtPointer)psub);
  796. XtAddCallback(dpd->printer_selection_box, XmNhelpCallback,
  797. SelectPrinterHelpCB, (XtPointer)psub);
  798. XtAddCallback(dpd->printer_selection_box, XmNdestroyCallback,
  799. SelectPrinterDestroyCB, (XtPointer)psub);
  800. /*
  801. * get the list box widget ID
  802. */
  803. dpd->printer_list_box =
  804. XtNameToWidget(dpd->printer_selection_box, "*ItemsList");
  805. XtAddCallback(dpd->printer_list_box, XmNbrowseSelectionCallback,
  806. SelectPrinterItemCB, (XtPointer)psub);
  807. /*
  808. * unmanaged unwanted children
  809. */
  810. control = XtNameToWidget(dpd->printer_selection_box, "*Selection");
  811. if(control != (Widget)NULL)
  812. XtUnmanageChild(control);
  813. control = XtNameToWidget(dpd->printer_selection_box, "*Text");
  814. if(control != (Widget)NULL)
  815. XtUnmanageChild(control);
  816. /*
  817. * return
  818. */
  819. return DtPRINT_SUCCESS;
  820. }
  821. /*
  822. * ------------------------------------------------------------------------
  823. * Name: DestroyWidgetCB
  824. *
  825. * Description:
  826. *
  827. * Destroys the Widget passed as client_data.
  828. *
  829. * Return value:
  830. *
  831. * None.
  832. *
  833. */
  834. static void
  835. DestroyWidgetCB(
  836. Widget w,
  837. XtPointer client_data,
  838. XtPointer call_data)
  839. {
  840. XtDestroyWidget((Widget)client_data);
  841. }
  842. /*
  843. * ------------------------------------------------------------------------
  844. * Name: DtPrintDefProcDestroyCB
  845. *
  846. * Description:
  847. *
  848. * Free resources allocated for the default procedure data structure
  849. * in response to the destruction of the DtPrintSetupBox.
  850. *
  851. * Calls destroy callbacks for dialogs *directly* because the dialogs
  852. * aren't children of the DtPrintSetupBox, but instead are more like
  853. * siblings or cousins of the PrintSetupBox whose common ancestor is
  854. * the shell parent of the PrintSetupBox. As such the dialogs may or
  855. * may not otherwise be destroyed when the PrintSetupBox is
  856. * destroyed. Furthermore the 2nd phase of the XtDestroyWidget calls
  857. * made in this routine isn't reached until after the PrintSetupBox
  858. * instance record has been destroyed (as part of the destroy phase
  859. * of which *this* call is a part).
  860. *
  861. * The main reason this is a concern is because data associated with
  862. * these dialogs is stored in the PrintSetupBox widget instance
  863. * structure.
  864. *
  865. * Return value:
  866. *
  867. * None.
  868. *
  869. */
  870. static void
  871. DtPrintDefProcDestroyCB(Widget w,
  872. XtPointer client_data,
  873. XtPointer call_data)
  874. {
  875. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  876. if(dpd->error_message_box)
  877. {
  878. XtRemoveCallback(dpd->error_message_box, XmNdestroyCallback,
  879. ErrorMessageDestroyCB, (XtPointer)w);
  880. XtDestroyWidget(dpd->error_message_box);
  881. ErrorMessageDestroyCB(dpd->error_message_box,
  882. (XtPointer)w, (XtPointer)NULL);
  883. }
  884. if(dpd->help_dialog)
  885. {
  886. XtRemoveCallback(dpd->help_dialog, XmNdestroyCallback,
  887. HelpDialogDestroyCB, (XtPointer)w);
  888. XtDestroyWidget(dpd->help_dialog);
  889. HelpDialogDestroyCB(dpd->help_dialog,
  890. (XtPointer)w, (XtPointer)NULL);
  891. }
  892. if(dpd->file_selection_box)
  893. {
  894. XtRemoveCallback(dpd->file_selection_box, XmNdestroyCallback,
  895. SelectFileDestroyCB, (XtPointer)w);
  896. XtDestroyWidget(dpd->file_selection_box);
  897. SelectFileDestroyCB(dpd->file_selection_box,
  898. (XtPointer)w, (XtPointer)NULL);
  899. }
  900. if(dpd->printer_selection_box)
  901. {
  902. XtRemoveCallback(dpd->printer_selection_box, XmNdestroyCallback,
  903. SelectPrinterDestroyCB, (XtPointer)w);
  904. XtDestroyWidget(dpd->printer_selection_box);
  905. SelectPrinterDestroyCB(dpd->printer_selection_box,
  906. (XtPointer)w, (XtPointer)NULL);
  907. }
  908. if(dpd->printer_info_box)
  909. {
  910. XtRemoveCallback(dpd->printer_info_box, XmNdestroyCallback,
  911. PrinterInfoDestroyCB, (XtPointer)w);
  912. XtDestroyWidget(dpd->printer_info_box);
  913. PrinterInfoDestroyCB(dpd->printer_info_box,
  914. (XtPointer)w, (XtPointer)NULL);
  915. }
  916. }
  917. /*
  918. * ------------------------------------------------------------------------
  919. * Name: ErrorMessageDestroyCB
  920. *
  921. * Description:
  922. *
  923. * Reset the error message widget ID instance data when the message
  924. * box is destroyed.
  925. *
  926. * This callback is considered part of the default resource
  927. * procedures and not part of the setup box widget proper.
  928. *
  929. * Return value:
  930. *
  931. * None.
  932. *
  933. */
  934. static void
  935. ErrorMessageDestroyCB(
  936. Widget w,
  937. XtPointer client_data,
  938. XtPointer call_data)
  939. {
  940. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(client_data);
  941. dpd->error_message_box = (Widget)NULL;
  942. }
  943. /*
  944. * ------------------------------------------------------------------------
  945. * Name: FindSelectedPrinter
  946. *
  947. * Description:
  948. *
  949. * Build a full printer name by locating the currently selected
  950. * printer in the server list and printer list.
  951. *
  952. *
  953. * Return value:
  954. *
  955. * A newly allocated full printer name. It is the caller's
  956. * responsibility to free the returned String by calling XtFree.
  957. *
  958. */
  959. static String
  960. FindSelectedPrinter(
  961. Display* display,
  962. DtPrintDefaultProcData* dpd)
  963. {
  964. int printer_count;
  965. int i;
  966. int printer_index;
  967. /*
  968. * return if any of the structures are not in place
  969. */
  970. if(dpd->xp_server_list == (String*)NULL
  971. ||
  972. dpd->printer_counts == (int*)NULL
  973. ||
  974. dpd->printer_lists == (DtPrintSelectPrinterList*)NULL)
  975. {
  976. return (String)NULL;
  977. }
  978. /*
  979. * find the printer list containing the selected printer
  980. */
  981. if(0 == dpd->selected_printer)
  982. return (String)NULL;
  983. else
  984. printer_index = dpd->selected_printer - 1;
  985. for(i = 0, printer_count = 0; i < dpd->xp_server_count; i++)
  986. {
  987. if(printer_index < printer_count + (dpd->printer_counts)[i])
  988. break;
  989. else
  990. printer_count += (dpd->printer_counts)[i];
  991. }
  992. if(i < dpd->xp_server_count)
  993. {
  994. /*
  995. * build and return the printer name
  996. */
  997. DtPrintSelectPrinterList printer_list;
  998. String printer_spec;
  999. String printer_name;
  1000. char* printer_name_ct;
  1001. char* display_spec;
  1002. display_spec = (dpd->xp_server_list)[i];
  1003. printer_list = (dpd->printer_lists)[i];
  1004. printer_name_ct =
  1005. printer_list[printer_index - printer_count].printer_name_ct;
  1006. printer_name =
  1007. CompoundTextToString(display, (unsigned char*)printer_name_ct);
  1008. if((String)NULL != printer_name)
  1009. {
  1010. printer_spec =
  1011. _DtPrintCreateXPrinterSpecifier(printer_name,
  1012. display_spec,
  1013. DtPRINT_NET_UNSPECIFIED,
  1014. -1, -1);
  1015. XtFree(printer_name);
  1016. return printer_spec;
  1017. }
  1018. }
  1019. return (String)NULL;
  1020. }
  1021. /*
  1022. * ------------------------------------------------------------------------
  1023. * Name: FreeSelectPrinterData
  1024. *
  1025. * Description:
  1026. *
  1027. * Deallocate and reset data items associated with the printer
  1028. * selection dialog.
  1029. *
  1030. * Return value:
  1031. *
  1032. * None.
  1033. */
  1034. static void
  1035. FreeSelectPrinterData(
  1036. DtPrintDefaultProcData* dpd)
  1037. {
  1038. int i, j;
  1039. DtPrintSelectPrinterList printer_list;
  1040. for(i = 0; i < dpd->xp_server_count; i++)
  1041. {
  1042. printer_list = dpd->printer_lists[i];
  1043. for(j = 0; j < dpd->printer_counts[i]; j++)
  1044. {
  1045. XtFree(printer_list[j].printer_name_ct);
  1046. }
  1047. XtFree((char*)printer_list);
  1048. }
  1049. XtFree((char*)dpd->printer_lists);
  1050. dpd->printer_lists = (DtPrintSelectPrinterList*)NULL;
  1051. XtFree((char*)dpd->xp_server_list);
  1052. dpd->xp_server_list = (String*)NULL;
  1053. dpd->xp_server_count = 0;
  1054. dpd->selected_printer = 0;
  1055. }
  1056. /*
  1057. * ------------------------------------------------------------------------
  1058. * Name: GetWMShellAncestor
  1059. *
  1060. * Description:
  1061. *
  1062. * Obtains the widget ID of the closest WMShell ancestor for
  1063. * the passed widget.
  1064. *
  1065. * Return value:
  1066. *
  1067. * The widget ID of the closest WMShell ancestor.
  1068. *
  1069. */
  1070. static Widget
  1071. GetWMShellAncestor(Widget w)
  1072. {
  1073. Widget wmshell_ancestor = XtParent(w);
  1074. while(wmshell_ancestor != (Widget)NULL)
  1075. {
  1076. if(XtIsWMShell(wmshell_ancestor))
  1077. break;
  1078. else
  1079. wmshell_ancestor = XtParent(wmshell_ancestor);
  1080. }
  1081. return wmshell_ancestor;
  1082. }
  1083. /*
  1084. * ------------------------------------------------------------------------
  1085. * Name: HelpDialogDestroyCB
  1086. *
  1087. * Description:
  1088. *
  1089. * Reset the help dialog widget ID instance data when the widget
  1090. * is destroyed.
  1091. *
  1092. * This callback is considered part of the default resource
  1093. * procedures and not part of the setup box widget proper.
  1094. *
  1095. * Return value:
  1096. *
  1097. * None.
  1098. *
  1099. */
  1100. static void
  1101. HelpDialogDestroyCB(
  1102. Widget w,
  1103. XtPointer client_data,
  1104. XtPointer call_data)
  1105. {
  1106. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(client_data);
  1107. dpd->help_dialog = (Widget)NULL;
  1108. }
  1109. /*
  1110. * ------------------------------------------------------------------------
  1111. * Name: InfoBoxLayoutCB
  1112. *
  1113. * Description:
  1114. *
  1115. * Callback to right justify printer information dialog labels at
  1116. * mapping time.
  1117. *
  1118. * Return value:
  1119. *
  1120. * None.
  1121. *
  1122. *
  1123. */
  1124. static void
  1125. InfoBoxLayoutCB(
  1126. Widget widget,
  1127. XtPointer client_data,
  1128. XtPointer call_data)
  1129. {
  1130. DtPrintDefaultProcData* dpd = (DtPrintDefaultProcData*)client_data;
  1131. Widget w[4];
  1132. int i, widest;
  1133. Dimension width, max_width;
  1134. /*
  1135. * only need to do this once after the widget is created
  1136. */
  1137. XtRemoveCallback(widget, XmNmapCallback, InfoBoxLayoutCB, client_data);
  1138. /*
  1139. * get the label widget ids
  1140. */
  1141. w[0] = XtNameToWidget(dpd->printer_info_box,
  1142. "PrinterInfoForm.DescriptionLabel");
  1143. w[1] = XtNameToWidget(dpd->printer_info_box,
  1144. "PrinterInfoForm.NameLabel");
  1145. w[2] = XtNameToWidget(dpd->printer_info_box,
  1146. "PrinterInfoForm.FormatLabel");
  1147. w[3] = XtNameToWidget(dpd->printer_info_box,
  1148. "PrinterInfoForm.ModelLabel");
  1149. /*
  1150. * find the widest label
  1151. */
  1152. for(i = 0, widest = 0, max_width = 0; i < 4; i++)
  1153. {
  1154. XtVaGetValues(w[i], XmNwidth, &width, NULL);
  1155. if(width > max_width)
  1156. {
  1157. widest = i;
  1158. max_width = width;
  1159. }
  1160. }
  1161. /*
  1162. * sever the top attachment on the widest label in order to avoid
  1163. * circular dependencies in form children; apparently one of the form
  1164. * widget's many talents is the inability to manage the vertical and
  1165. * horizontal attachments independently...
  1166. */
  1167. XtVaSetValues(w[widest], XmNtopAttachment, XmATTACH_SELF, NULL);
  1168. /*
  1169. * attach the right side of the smaller labels to the right side of
  1170. * the widest label
  1171. */
  1172. for(i = 0; i < 4; i++)
  1173. if(i != widest)
  1174. XtVaSetValues(w[i],
  1175. XmNleftAttachment, XmATTACH_NONE,
  1176. XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
  1177. XmNrightWidget, w[widest],
  1178. NULL);
  1179. }
  1180. /*
  1181. * ------------------------------------------------------------------------
  1182. * Name: ParseFileNameSpec
  1183. *
  1184. * Description:
  1185. *
  1186. * Parse the passed file name to create a file selection box filter
  1187. * pattern and the name only portion of the full name spec.
  1188. *
  1189. * It is the caller's responsibility to free the allocated memory
  1190. * returned in 'pattern' and 'name_only' using XmStringFree and
  1191. * XtFree respectively.
  1192. *
  1193. * Return value:
  1194. *
  1195. * None.
  1196. *
  1197. *
  1198. */
  1199. static void
  1200. ParseFileNameSpec(const char* file_name,
  1201. XmString* pattern_xmstr,
  1202. char** name_only)
  1203. {
  1204. String ptr;
  1205. String pattern;
  1206. /*
  1207. * start off with a copy of the file name, ensuring there is
  1208. * enough space for the added "*" and the string terminator.
  1209. */
  1210. pattern = XtMalloc(strlen(file_name)+2);
  1211. strcpy(pattern, file_name);
  1212. /*
  1213. * find the last slash
  1214. */
  1215. ptr = DtStrrchr(pattern, '/');
  1216. if(ptr != (String)NULL)
  1217. {
  1218. /*
  1219. * grab the name portion of the file name
  1220. */
  1221. *name_only = XtNewString(ptr+1);
  1222. /*
  1223. * set the wildcard character immediately following the last
  1224. * slash
  1225. */
  1226. strcpy(ptr+1, "*");
  1227. *pattern_xmstr = XmStringCreateLocalized(pattern);
  1228. }
  1229. else
  1230. {
  1231. /*
  1232. * no slash found; use the default pattern
  1233. */
  1234. *pattern_xmstr = (XmString)NULL;
  1235. *name_only = XtNewString(file_name);
  1236. }
  1237. XtFree(pattern);
  1238. }
  1239. /*
  1240. * ------------------------------------------------------------------------
  1241. * Name: PresentErrorDialog
  1242. *
  1243. * Description:
  1244. *
  1245. * This is a utility function that will present an Error Dialog. It
  1246. * takes a title, a message, and a variable list of Strings to
  1247. * include in the message. The message parm is treated like a
  1248. * printf-style format string, except that only the "%s" directive is
  1249. * supported.
  1250. *
  1251. * This function is to be used exclusively by the default
  1252. * resource procedures (e.g. _DtPrintSetupBoxVerifyXPrinterProc).
  1253. *
  1254. * The variable list of String parms must be terminated by
  1255. * (String)NULL.
  1256. *
  1257. * Return Value:
  1258. *
  1259. * None.
  1260. *
  1261. */
  1262. static void
  1263. PresentErrorDialog(
  1264. Widget w,
  1265. String title,
  1266. String message,
  1267. ...)
  1268. {
  1269. Arg args[15];
  1270. Cardinal n;
  1271. String expanded_message;
  1272. String str_n;
  1273. XmString message_xmstr;
  1274. XmString title_xmstr;
  1275. int message_len;
  1276. va_list arg_marker;
  1277. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  1278. Widget wmshell_ancestor;
  1279. WidgetList wmshell_ancestors_children = (WidgetList)NULL;
  1280. wmshell_ancestor = GetWMShellAncestor(w);
  1281. if (wmshell_ancestor)
  1282. {
  1283. n = 0;
  1284. XtSetArg(args[n], XmNchildren, &wmshell_ancestors_children); n++;
  1285. XtGetValues(wmshell_ancestor, args, n);
  1286. }
  1287. if(dpd->error_message_box != (Widget)NULL)
  1288. {
  1289. /*
  1290. * present only one message box
  1291. */
  1292. XtDestroyWidget(dpd->error_message_box);
  1293. }
  1294. title_xmstr = XmStringCreateLocalized(title);
  1295. /*
  1296. * determine length of expanded message
  1297. */
  1298. message_len = strlen(message);
  1299. va_start(arg_marker, message);
  1300. while((str_n = va_arg(arg_marker, String)) != (String)NULL)
  1301. {
  1302. message_len += strlen(str_n);
  1303. }
  1304. va_end(arg_marker);
  1305. ++message_len;
  1306. /*
  1307. * expand the message
  1308. */
  1309. expanded_message = XtMalloc(message_len);
  1310. va_start(arg_marker, message);
  1311. vsprintf(expanded_message, message, arg_marker);
  1312. va_end(arg_marker);
  1313. /*
  1314. * convert message to XmString
  1315. */
  1316. message_xmstr = XmStringCreateLocalized(expanded_message);
  1317. XtFree(expanded_message);
  1318. /*
  1319. * create the error dialog
  1320. */
  1321. n = 0;
  1322. XtSetArg(args[n], XmNdialogTitle, title_xmstr); n++;
  1323. XtSetArg(args[n], XmNmessageString, message_xmstr); n++;
  1324. XtSetArg(args[n], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); n++;
  1325. XtSetArg(args[n], XmNdeleteResponse, XmDESTROY); n++;
  1326. dpd->error_message_box =
  1327. XmCreateErrorDialog(wmshell_ancestors_children ?
  1328. wmshell_ancestors_children[0] :
  1329. wmshell_ancestor,
  1330. "_PsubDefProcErrorMsg", args, n);
  1331. XmStringFree(title_xmstr);
  1332. XmStringFree(message_xmstr);
  1333. XtUnmanageChild(XtNameToWidget(dpd->error_message_box, "Cancel"));
  1334. XtUnmanageChild(XtNameToWidget(dpd->error_message_box, "Help"));
  1335. XtAddCallback(dpd->error_message_box, XmNokCallback,
  1336. DestroyWidgetCB, (XtPointer)dpd->error_message_box);
  1337. XtAddCallback(dpd->error_message_box, XmNcancelCallback,
  1338. DestroyWidgetCB, (XtPointer)dpd->error_message_box);
  1339. XtAddCallback(dpd->error_message_box, XmNdestroyCallback,
  1340. ErrorMessageDestroyCB, (XtPointer)w);
  1341. /*
  1342. * manage the message box according to the hint
  1343. */
  1344. if(DtPRINT_HINT_MESSAGES_OK == dpd->messages_hint)
  1345. XtManageChild(dpd->error_message_box);
  1346. #ifdef XXX_JUNGLE_REMOVE
  1347. /*
  1348. * manage the message box only if the psub is mapped
  1349. * and the focus is not in the printer name field
  1350. */
  1351. {
  1352. XWindowAttributes attr;
  1353. Status status;
  1354. Window window = XtWindow(w);
  1355. if(window)
  1356. {
  1357. status = XGetWindowAttributes(XtDisplay(w), window, &attr);
  1358. if(status == 0 || attr.map_state == IsViewable)
  1359. {
  1360. Widget name_w = XtNameToWidget(w, "Name");
  1361. Widget child;
  1362. for(child = XmGetFocusWidget(w);
  1363. child != wmshell_ancestor && child != name_w
  1364. && child != (Widget)NULL;
  1365. child = XtParent(child));
  1366. if(child != name_w && child != (Widget)NULL)
  1367. XtManageChild(dpd->error_message_box);
  1368. }
  1369. }
  1370. }
  1371. #endif /* XXX_JUNGLE_REMOVE */
  1372. }
  1373. /*
  1374. * ------------------------------------------------------------------------
  1375. * Name: PresentHelp
  1376. *
  1377. * Description:
  1378. *
  1379. * Presents a help dialog whose widget instance may be shared between
  1380. * the default dialogs.
  1381. *
  1382. * Return value:
  1383. *
  1384. * None.
  1385. *
  1386. */
  1387. static void PresentHelp(
  1388. Widget w,
  1389. const char* help_volume,
  1390. const char* location_id)
  1391. {
  1392. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  1393. Widget wmshell_ancestor;
  1394. Widget dialog_shell;
  1395. wmshell_ancestor = GetWMShellAncestor(w);
  1396. if((Widget)NULL == dpd->help_dialog)
  1397. {
  1398. Arg args[5];
  1399. Cardinal n;
  1400. XmString title;
  1401. n = 0;
  1402. title = XmStringCreateLocalized(HELP_DLG_TITLE);
  1403. XtSetArg(args[n], XmNdialogTitle, title); n++;
  1404. dpd->help_dialog =
  1405. DtCreateHelpDialog(wmshell_ancestor, "_PsubDefProcHelpDialog",
  1406. args, n);
  1407. XmStringFree(title);
  1408. XtAddCallback(dpd->help_dialog, XmNdestroyCallback,
  1409. HelpDialogDestroyCB, (XtPointer)w);
  1410. }
  1411. /*
  1412. * set the help volume and location
  1413. */
  1414. XtVaSetValues(dpd->help_dialog,
  1415. DtNhelpVolume, help_volume,
  1416. DtNlocationId, location_id,
  1417. DtNhelpType, DtHELP_TYPE_TOPIC,
  1418. NULL);
  1419. /*
  1420. * pop up the help dialog
  1421. */
  1422. XtManageChild(dpd->help_dialog);
  1423. dialog_shell = XtParent(dpd->help_dialog);
  1424. if(None != XtWindow(dialog_shell))
  1425. XRaiseWindow(XtDisplay(dialog_shell), XtWindow(dialog_shell));
  1426. }
  1427. /*
  1428. * ------------------------------------------------------------------------
  1429. * Name: PresentVerifyError
  1430. *
  1431. * Description:
  1432. *
  1433. * Presents a error dialog appropriate for an error status returned
  1434. * by _DtPrintVerifyXPrinter.
  1435. *
  1436. * Return value:
  1437. *
  1438. * None.
  1439. *
  1440. */
  1441. static void
  1442. PresentVerifyError(
  1443. Widget w,
  1444. XtEnum status,
  1445. String printer_spec)
  1446. {
  1447. String printer_name;
  1448. String display_spec;
  1449. _DtPrintParseXPrinterSpecifier(printer_spec,
  1450. &printer_name,
  1451. &display_spec);
  1452. switch(status)
  1453. {
  1454. case DtPRINT_PRINTER_MISSING:
  1455. PresentErrorDialog(w, INVALID_PRINTER_TITLE,
  1456. PRINTER_MISSING_MESSAGE,
  1457. printer_spec,
  1458. (String)NULL);
  1459. break;
  1460. case DtPRINT_NO_DEFAULT:
  1461. PresentErrorDialog(w, INVALID_PRINTER_TITLE,
  1462. NO_DEFAULT_MESSAGE,
  1463. (String)NULL);
  1464. break;
  1465. case DtPRINT_NO_DEFAULT_DISPLAY:
  1466. PresentErrorDialog(w, INVALID_PRINTER_TITLE,
  1467. NO_DEFAULT_DISPLAY_MESSAGE,
  1468. printer_name,
  1469. (String)NULL);
  1470. break;
  1471. case DtPRINT_NO_PRINTER:
  1472. PresentErrorDialog(w, INVALID_PRINTER_TITLE,
  1473. INVALID_PRINTER_MESSAGE,
  1474. printer_name, display_spec,
  1475. (String)NULL);
  1476. break;
  1477. case DtPRINT_NOT_XP_DISPLAY:
  1478. PresentErrorDialog(w, INVALID_PRINTER_TITLE,
  1479. NOT_XP_DISPLAY_MESSAGE,
  1480. display_spec,
  1481. (String)NULL);
  1482. break;
  1483. case DtPRINT_INVALID_DISPLAY:
  1484. PresentErrorDialog(w, INVALID_PRINTER_TITLE,
  1485. INVALID_DISPLAY_MESSAGE,
  1486. display_spec,
  1487. (String)NULL);
  1488. break;
  1489. }
  1490. XtFree(printer_name);
  1491. XtFree(display_spec);
  1492. }
  1493. /*
  1494. * ------------------------------------------------------------------------
  1495. * Name: PrinterInfoDestroyCB
  1496. *
  1497. * Description:
  1498. *
  1499. * Reset data items used in conjunction with the
  1500. * printer information selection dialog.
  1501. *
  1502. * Return value:
  1503. *
  1504. * None.
  1505. *
  1506. */
  1507. static void
  1508. PrinterInfoDestroyCB(
  1509. Widget w,
  1510. XtPointer client_data,
  1511. XtPointer call_data)
  1512. {
  1513. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(client_data);
  1514. dpd->printer_info_box = (Widget)NULL;
  1515. }
  1516. /*
  1517. * ------------------------------------------------------------------------
  1518. * Name: PrinterInfoHelpCB
  1519. *
  1520. * Description:
  1521. *
  1522. * Display context sensitive help.
  1523. *
  1524. * Return value:
  1525. *
  1526. * None.
  1527. *
  1528. */
  1529. static void
  1530. PrinterInfoHelpCB(
  1531. Widget w,
  1532. XtPointer client_data,
  1533. XtPointer call_data)
  1534. {
  1535. PresentHelp((Widget)client_data, HELP_VOLUME, PRINTER_INFO_HELP_ID);
  1536. }
  1537. /*
  1538. * ------------------------------------------------------------------------
  1539. * Name: SelectFileDestroyCB
  1540. *
  1541. * Description:
  1542. *
  1543. * Reset data items used in conjunction with the
  1544. * file selection dialog.
  1545. *
  1546. * Return value:
  1547. *
  1548. * None.
  1549. *
  1550. */
  1551. static void
  1552. SelectFileDestroyCB(
  1553. Widget w,
  1554. XtPointer client_data,
  1555. XtPointer call_data)
  1556. {
  1557. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(client_data);
  1558. dpd->file_selection_box = (Widget)NULL;
  1559. }
  1560. /*
  1561. * ------------------------------------------------------------------------
  1562. * Name: SelectFileHelpCB
  1563. *
  1564. * Description:
  1565. *
  1566. * Display context sensitive help.
  1567. *
  1568. * Return value:
  1569. *
  1570. * None.
  1571. *
  1572. */
  1573. static void
  1574. SelectFileHelpCB(
  1575. Widget w,
  1576. XtPointer client_data,
  1577. XtPointer call_data)
  1578. {
  1579. PresentHelp((Widget)client_data, HELP_VOLUME, SELECT_FILE_HELP_ID);
  1580. }
  1581. /*
  1582. * ------------------------------------------------------------------------
  1583. * Name: SelectPrinterCB
  1584. *
  1585. * Description:
  1586. *
  1587. * Callback to handle the printer selection box OK and Cancel
  1588. * buttons.
  1589. *
  1590. * Return value:
  1591. *
  1592. * None.
  1593. *
  1594. */
  1595. static void
  1596. SelectPrinterCB(
  1597. Widget w,
  1598. XtPointer client_data,
  1599. XtPointer call_data)
  1600. {
  1601. XmSelectionBoxCallbackStruct* cbs =
  1602. (XmSelectionBoxCallbackStruct*)call_data;
  1603. Widget psub = (Widget)client_data;
  1604. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(psub);
  1605. String printer_spec;
  1606. /*
  1607. * close the info dialog display connection if it's been opened
  1608. */
  1609. CloseSelectPrinterInfoConnection(dpd);
  1610. switch(cbs->reason)
  1611. {
  1612. case XmCR_OK:
  1613. /*
  1614. * set the selected printer name in the PrintSetupBox
  1615. */
  1616. printer_spec = FindSelectedPrinter(XtDisplay(psub), dpd);
  1617. if((String)NULL != printer_spec)
  1618. {
  1619. XtVaSetValues(psub, DtNprinterName, printer_spec, NULL);
  1620. XtFree(printer_spec);
  1621. }
  1622. /*
  1623. * no break
  1624. */
  1625. case XmCR_CANCEL:
  1626. /*
  1627. * deallocate and reset the lists
  1628. */
  1629. FreeSelectPrinterData(dpd);
  1630. if(dpd->printer_list_box != (Widget)NULL)
  1631. XmListDeleteAllItems(dpd->printer_list_box);
  1632. break;
  1633. }
  1634. }
  1635. /*
  1636. * ------------------------------------------------------------------------
  1637. * Name: SelectPrinterDestroyCB
  1638. *
  1639. * Description:
  1640. *
  1641. * Deallocate and reset data items used in conjunction with the
  1642. * printer selection dialog.
  1643. *
  1644. * Return value:
  1645. *
  1646. * None.
  1647. *
  1648. */
  1649. static void
  1650. SelectPrinterDestroyCB(
  1651. Widget w,
  1652. XtPointer client_data,
  1653. XtPointer call_data)
  1654. {
  1655. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(client_data);
  1656. dpd->printer_selection_box = (Widget)NULL;
  1657. dpd->printer_list_box = (Widget)NULL;
  1658. CloseSelectPrinterInfoConnection(dpd);
  1659. FreeSelectPrinterData(dpd);
  1660. }
  1661. /*
  1662. * ------------------------------------------------------------------------
  1663. * Name: SelectPrinterHelpCB
  1664. *
  1665. * Description:
  1666. *
  1667. * Display context sensitive help.
  1668. *
  1669. * Return value:
  1670. *
  1671. * None.
  1672. *
  1673. */
  1674. static void
  1675. SelectPrinterHelpCB(
  1676. Widget w,
  1677. XtPointer client_data,
  1678. XtPointer call_data)
  1679. {
  1680. PresentHelp((Widget)client_data, HELP_VOLUME, SELECT_PRINTER_HELP_ID);
  1681. }
  1682. /*
  1683. * ------------------------------------------------------------------------
  1684. * Name: SelectPrinterInfoCB
  1685. *
  1686. * Description:
  1687. *
  1688. * Callback attached to the printer selection box "Info..."
  1689. * button. The "Info..." button is intended to behave just like the
  1690. * PrintSetupBox "Info..." button, so it is implemented to call the
  1691. * procedure set for the PrintSetupBox DtNprinterInfoProc resource.
  1692. * As such, this function needs to open a new display connection to
  1693. * the print server indicated by the currently selected printer in
  1694. * the list. The connection is not closed until a selection is made
  1695. * in the list, or the printer selection dialog is dismissed. This is
  1696. * because no assumptions about the Printer Info dialog's widget
  1697. * hierarchy can be made.
  1698. *
  1699. * Return value:
  1700. *
  1701. * None.
  1702. *
  1703. */
  1704. static void
  1705. SelectPrinterInfoCB(
  1706. Widget w,
  1707. XtPointer client_data,
  1708. XtPointer call_data)
  1709. {
  1710. Widget psub = (Widget)client_data;
  1711. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(psub);
  1712. DtPrintSetupProc info_proc;
  1713. CloseSelectPrinterInfoConnection(dpd);
  1714. XtVaGetValues(psub, DtNprinterInfoProc, &info_proc, NULL);
  1715. if((DtPrintSetupProc)NULL != info_proc)
  1716. {
  1717. String printer_spec;
  1718. printer_spec = FindSelectedPrinter(XtDisplay(psub), dpd);
  1719. if((String)NULL != printer_spec)
  1720. {
  1721. String new_printer_spec; /*
  1722. * will always be set to NULL by
  1723. * _DtPrintVerifyXPrinter when
  1724. * called from within this routine
  1725. */
  1726. XtEnum status;
  1727. /*
  1728. * open a connection to the X printer
  1729. */
  1730. status =
  1731. _DtPrintVerifyXPrinter(psub,
  1732. printer_spec,
  1733. &new_printer_spec,
  1734. &dpd->select_printer_info_display
  1735. #if 0 && defined(PRINTING_SUPPORTED)
  1736. ,&dpd->select_printer_info_context
  1737. #endif /* PRINTING_SUPPORTED */
  1738. );
  1739. if(status == DtPRINT_SUCCESS)
  1740. {
  1741. DtPrintSetupData psd;
  1742. memset(&psd, 0, sizeof(DtPrintSetupData));
  1743. psd.printer_name = printer_spec;
  1744. psd.print_display = dpd->select_printer_info_display;
  1745. #if 0 && defined(PRINTING_SUPPORTED)
  1746. psd.print_context = dpd->select_printer_info_context;
  1747. #endif /* PRINTING_SUPPORTED */
  1748. (*info_proc)(psub, &psd);
  1749. }
  1750. else
  1751. {
  1752. /*
  1753. * this should only happen if, while a user is viewing
  1754. * the printer selection dialog, a server rehash is
  1755. * performed that deletes the currently selected printer
  1756. */
  1757. PresentVerifyError(w, status, printer_spec);
  1758. }
  1759. XtFree(printer_spec);
  1760. }
  1761. }
  1762. }
  1763. /*
  1764. * ------------------------------------------------------------------------
  1765. * Name: SelectPrinterItemCB
  1766. *
  1767. * Description:
  1768. *
  1769. * Callback to handle the a selection in the printer selection list
  1770. * box.
  1771. *
  1772. * Return value:
  1773. *
  1774. * None.
  1775. *
  1776. */
  1777. static void
  1778. SelectPrinterItemCB(
  1779. Widget w,
  1780. XtPointer client_data,
  1781. XtPointer call_data)
  1782. {
  1783. XmListCallbackStruct* cbs =
  1784. (XmListCallbackStruct*)call_data;
  1785. Widget psub = (Widget)client_data;
  1786. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(psub);
  1787. Widget info_button;
  1788. if(dpd->selected_printer != cbs->item_position)
  1789. {
  1790. dpd->selected_printer = cbs->item_position;
  1791. info_button = XtNameToWidget(dpd->printer_selection_box, "*Apply");
  1792. if(0 == dpd->selected_printer)
  1793. XtSetSensitive(info_button, False);
  1794. else
  1795. XtSetSensitive(info_button, True);
  1796. /*
  1797. * update the default printer info dialog if it is visible
  1798. */
  1799. if(dpd->printer_info_box && XtIsManaged(dpd->printer_info_box))
  1800. SelectPrinterInfoCB(w, client_data, (XtPointer)NULL);
  1801. }
  1802. }
  1803. /*
  1804. * ------------------------------------------------------------------------
  1805. * Name: SetListBoxSelection
  1806. *
  1807. * Description:
  1808. *
  1809. *
  1810. * Return value:
  1811. *
  1812. * None.
  1813. *
  1814. */
  1815. static void
  1816. SetListBoxSelection(Widget list_box, int position)
  1817. {
  1818. int visible_item_count;
  1819. int item_count;
  1820. int middle_offset;
  1821. int first_visible_pos;
  1822. /*
  1823. * Scroll the list, making the item at the indicated position
  1824. * visible in the center of the list box, and make
  1825. * it the initial selection.
  1826. */
  1827. XtVaGetValues(list_box,
  1828. XmNitemCount, &item_count,
  1829. XmNvisibleItemCount, &visible_item_count,
  1830. NULL);
  1831. if(item_count > visible_item_count)
  1832. {
  1833. middle_offset = (visible_item_count+1) / 2;
  1834. if(position > middle_offset)
  1835. if(position > item_count - middle_offset)
  1836. first_visible_pos = item_count - visible_item_count +1;
  1837. else
  1838. first_visible_pos = position - middle_offset + 1;
  1839. else
  1840. first_visible_pos = 1;
  1841. XmListSetPos(list_box, first_visible_pos);
  1842. }
  1843. if(position > 0)
  1844. XmListSelectPos(list_box, position, True);
  1845. else
  1846. XmListDeselectAllItems(list_box);
  1847. }
  1848. /*
  1849. * ------------------------------------------------------------------------
  1850. * Name: UpdateFileNameCB
  1851. *
  1852. * Description:
  1853. *
  1854. * Updates the PrintSetupBox fileName resource based on the selection
  1855. * make in the file selection box.
  1856. *
  1857. * Return value:
  1858. *
  1859. * None.
  1860. *
  1861. */
  1862. static void
  1863. UpdateFileNameCB(
  1864. Widget w,
  1865. XtPointer client_data,
  1866. XtPointer call_data)
  1867. {
  1868. Widget text_field;
  1869. Widget psub = (Widget)client_data;
  1870. String file_name;
  1871. /*
  1872. * get the file name from the file selection box text field
  1873. */
  1874. text_field = XtNameToWidget(w, "Text");
  1875. if(text_field)
  1876. {
  1877. XtVaGetValues(text_field, XmNvalue, &file_name, NULL);
  1878. if(file_name)
  1879. {
  1880. /*
  1881. * set the file name in the print setup box
  1882. */
  1883. XtVaSetValues(psub, DtNfileName, file_name, NULL);
  1884. /*
  1885. * free the file name retrieved from the text field
  1886. */
  1887. XtFree(file_name);
  1888. }
  1889. }
  1890. }
  1891. /*
  1892. * ------------------------------------------------------------------------
  1893. * Name: _DtPrintDefProcInitialize
  1894. *
  1895. * Description:
  1896. *
  1897. *
  1898. *
  1899. * Return value:
  1900. *
  1901. *
  1902. */
  1903. void
  1904. _DtPrintDefProcInitialize(Widget w)
  1905. {
  1906. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  1907. dpd->error_message_box = (Widget)NULL;
  1908. dpd->messages_hint = DtPRINT_HINT_MESSAGES_OK;
  1909. dpd->help_dialog = (Widget)NULL;
  1910. dpd->file_selection_box = (Widget)NULL;
  1911. dpd->printer_selection_box = (Widget)NULL;
  1912. dpd->printer_list_box = (Widget)NULL;
  1913. dpd->xp_server_list = (String*)NULL;
  1914. dpd->xp_server_count = 0;
  1915. dpd->printer_lists = (DtPrintSelectPrinterList*)NULL;
  1916. dpd->selected_printer = 0;
  1917. dpd->select_printer_info_display = (Display*)NULL;
  1918. #if 0 && defined(PRINTING_SUPPORTED)
  1919. dpd->select_printer_info_context = (XPContext)None;
  1920. #endif /* PRINTING_SUPPORTED */
  1921. dpd->printer_info_box = (Widget)NULL;
  1922. XtAddCallback(w, XmNdestroyCallback,
  1923. DtPrintDefProcDestroyCB, (XtPointer)NULL);
  1924. }
  1925. /*
  1926. * ------------------------------------------------------------------------
  1927. * Name: _DtPrintDefProcManageErrorBox
  1928. *
  1929. * Description:
  1930. *
  1931. * Manage the Error Message Box if it exists.
  1932. *
  1933. * Return value:
  1934. *
  1935. *
  1936. */
  1937. void
  1938. _DtPrintDefProcManageErrorBox(
  1939. DtPrintDefaultProcData* dpd)
  1940. {
  1941. if(dpd->error_message_box != (Widget)NULL)
  1942. XtManageChild(dpd->error_message_box);
  1943. }
  1944. /*
  1945. * ------------------------------------------------------------------------
  1946. * Name: _DtPrintSetupBoxXPrinterInfoProc
  1947. *
  1948. * Description:
  1949. *
  1950. * Default Xp mode function for the DtNprinterInfoProc resource.
  1951. *
  1952. * Return value:
  1953. *
  1954. *
  1955. */
  1956. XtEnum
  1957. _DtPrintSetupBoxXPrinterInfoProc(
  1958. Widget w,
  1959. DtPrintSetupData* print_data)
  1960. {
  1961. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  1962. Widget wmshell_ancestor;
  1963. Widget ctl;
  1964. XmString label;
  1965. char* attr_value_ct = NULL;
  1966. String attr_value = NULL;
  1967. XmString empty_label;
  1968. Widget name_label_top;
  1969. Position max_y, y;
  1970. Dimension height;
  1971. Widget manager = NULL;
  1972. Widget dialog_shell;
  1973. wmshell_ancestor = GetWMShellAncestor(w);
  1974. _DtTurnOnHourGlass(wmshell_ancestor);
  1975. empty_label = XmStringCreateLocalized("");
  1976. /*
  1977. * if needed, create the printer information dialog
  1978. */
  1979. if(dpd->printer_info_box == (Widget)NULL)
  1980. {
  1981. XtEnum status = CreatePrinterInfoBox(wmshell_ancestor, w, dpd);
  1982. if(status != DtPRINT_SUCCESS)
  1983. {
  1984. _DtTurnOffHourGlass(wmshell_ancestor);
  1985. return status;
  1986. }
  1987. dialog_shell = XtParent(dpd->printer_info_box);
  1988. }
  1989. else
  1990. {
  1991. /*
  1992. * hide the widget during re-layout
  1993. */
  1994. manager = XtNameToWidget(dpd->printer_info_box, "*PrinterInfoForm");
  1995. XtUnmapWidget(dpd->printer_info_box);
  1996. dialog_shell = XtParent(dpd->printer_info_box);
  1997. XtVaSetValues(dialog_shell, XmNallowShellResize, False, NULL);
  1998. XtUnmanageChild(manager);
  1999. }
  2000. /*
  2001. * description
  2002. */
  2003. ctl = XtNameToWidget(dpd->printer_info_box, "*Description");
  2004. XtVaSetValues(ctl, XmNlabelString, empty_label, NULL);
  2005. #if 0 && defined(PRINTING_SUPPORTED)
  2006. attr_value_ct = XpGetOneAttribute(print_data->print_display,
  2007. print_data->print_context,
  2008. XPPrinterAttr,
  2009. "descriptor");
  2010. #endif /* PRINTING_SUPPORTED */
  2011. if((char*)NULL != attr_value_ct)
  2012. {
  2013. attr_value =
  2014. CompoundTextToString(XtDisplay(w), (unsigned char*)attr_value_ct);
  2015. XFree(attr_value_ct);
  2016. if((String)NULL != attr_value)
  2017. {
  2018. label = XmStringGenerate((XtPointer)attr_value, (XmStringTag)NULL,
  2019. XmMULTIBYTE_TEXT, (XmStringTag)NULL);
  2020. XtFree(attr_value);
  2021. XtVaSetValues(ctl, XmNlabelString, label, NULL);
  2022. XmStringFree(label);
  2023. }
  2024. }
  2025. /*
  2026. * set the top attachment for the name label
  2027. */
  2028. XtVaGetValues(ctl, XmNy, &y, XmNheight, &height, NULL);
  2029. max_y = y + height;
  2030. name_label_top = ctl;
  2031. ctl = XtNameToWidget(dpd->printer_info_box, "*DescriptionLabel");
  2032. XtVaGetValues(ctl, XmNy, &y, XmNheight, &height, NULL);
  2033. if(y+height > max_y)
  2034. name_label_top = ctl;
  2035. ctl = XtNameToWidget(dpd->printer_info_box, "*NameLabel");
  2036. XtVaSetValues(ctl, XmNtopWidget, name_label_top, NULL);
  2037. /*
  2038. * printer name
  2039. */
  2040. ctl = XtNameToWidget(dpd->printer_info_box, "*Name");
  2041. label = XmStringCreateLocalized(print_data->printer_name);
  2042. XtVaSetValues(ctl, XmNlabelString, label, NULL);
  2043. XmStringFree(label);
  2044. /*
  2045. * document format
  2046. */
  2047. ctl = XtNameToWidget(dpd->printer_info_box, "*Format");
  2048. XtVaSetValues(ctl, XmNlabelString, empty_label, NULL);
  2049. #if 0 && defined(PRINTING_SUPPORTED)
  2050. attr_value = XpGetOneAttribute(print_data->print_display,
  2051. print_data->print_context,
  2052. XPDocAttr,
  2053. "document-format");
  2054. #endif /* PRINTING_SUPPORTED */
  2055. if((String)NULL != attr_value)
  2056. {
  2057. char* format_start;
  2058. format_start = strchr(attr_value, '{');
  2059. if((char*)NULL != format_start)
  2060. {
  2061. char* format_end;
  2062. ++format_start;
  2063. format_end = strchr(format_start, '}');
  2064. if((char*)NULL != format_end)
  2065. {
  2066. *format_end = '\0';
  2067. label = XmStringCreateLocalized(format_start);
  2068. XtVaSetValues(ctl, XmNlabelString, label, NULL);
  2069. XmStringFree(label);
  2070. }
  2071. }
  2072. XFree(attr_value);
  2073. }
  2074. /*
  2075. * printer model
  2076. */
  2077. ctl = XtNameToWidget(dpd->printer_info_box, "*Model");
  2078. XtVaSetValues(ctl, XmNlabelString, empty_label, NULL);
  2079. #if 0 && defined(PRINTING_SUPPORTED)
  2080. attr_value_ct = XpGetOneAttribute(print_data->print_display,
  2081. print_data->print_context,
  2082. XPPrinterAttr,
  2083. "printer-model");
  2084. #endif /* PRINTING_SUPPORTED */
  2085. if((char*)NULL != attr_value_ct)
  2086. {
  2087. attr_value =
  2088. CompoundTextToString(XtDisplay(w), (unsigned char*)attr_value_ct);
  2089. XFree(attr_value_ct);
  2090. if((String)NULL != attr_value)
  2091. {
  2092. label = XmStringGenerate((XtPointer)attr_value, (XmStringTag)NULL,
  2093. XmCHARSET_TEXT, (XmStringTag)NULL);
  2094. XtFree(attr_value);
  2095. XtVaSetValues(ctl, XmNlabelString, label, NULL);
  2096. XmStringFree(label);
  2097. }
  2098. }
  2099. /*
  2100. * pop up the printer info dialog and return
  2101. */
  2102. XmStringFree(empty_label);
  2103. if(manager)
  2104. {
  2105. XtVaSetValues(dialog_shell, XmNallowShellResize, True, NULL);
  2106. XtManageChild(manager);
  2107. XtMapWidget(dpd->printer_info_box);
  2108. }
  2109. XtManageChild(dpd->printer_info_box);
  2110. if(None != XtWindow(dialog_shell))
  2111. XRaiseWindow(XtDisplay(dialog_shell), XtWindow(dialog_shell));
  2112. _DtTurnOffHourGlass(wmshell_ancestor);
  2113. return DtPRINT_SUCCESS;
  2114. }
  2115. /*
  2116. * ------------------------------------------------------------------------
  2117. * Name: _DtPrintSetupBoxSelectFileProc
  2118. *
  2119. * Description:
  2120. *
  2121. * Default function for the DtNselectFileProc resource.
  2122. *
  2123. * Return value:
  2124. *
  2125. *
  2126. */
  2127. XtEnum
  2128. _DtPrintSetupBoxSelectFileProc(
  2129. Widget w,
  2130. DtPrintSetupData* print_data)
  2131. {
  2132. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  2133. String name_only;
  2134. String file_name;
  2135. XmString pattern;
  2136. Widget file_list;
  2137. Widget text_field;
  2138. Widget wmshell_ancestor;
  2139. wmshell_ancestor = GetWMShellAncestor(w);
  2140. _DtTurnOnHourGlass(wmshell_ancestor);
  2141. /*
  2142. * if needed, create the file selection dialog
  2143. */
  2144. if(dpd->file_selection_box == (Widget)NULL)
  2145. {
  2146. XtEnum status = CreateFileSelectionBox(wmshell_ancestor, w, dpd);
  2147. if(status != DtPRINT_SUCCESS)
  2148. {
  2149. _DtTurnOffHourGlass(wmshell_ancestor);
  2150. return status;
  2151. }
  2152. }
  2153. /*
  2154. * get the file name passed from the PrintSetupBox
  2155. */
  2156. file_name = print_data->dest_info;
  2157. /*
  2158. * parse the file name to create the filter pattern and the name only
  2159. * portion of the full name spec
  2160. */
  2161. ParseFileNameSpec(file_name, &pattern, &name_only);
  2162. /*
  2163. * set the filter pattern in the file selection box
  2164. */
  2165. XtVaSetValues(dpd->file_selection_box, XmNpattern, pattern, NULL);
  2166. if(pattern != (XmString)NULL)
  2167. XmStringFree(pattern);
  2168. /*
  2169. * select the current file name in the file names list
  2170. */
  2171. file_list = XtNameToWidget(dpd->file_selection_box, "*ItemsList");
  2172. if(file_list != (Widget)NULL)
  2173. {
  2174. XmString file_name_xmstr;
  2175. int position;
  2176. text_field = XtNameToWidget(dpd->file_selection_box, "Text");
  2177. if(text_field != (Widget)NULL)
  2178. {
  2179. String dir_spec;
  2180. /*
  2181. * recreate the file name from the name_only and the current
  2182. * dir spec as determined by the file selection box
  2183. *
  2184. * Note: the char* value retrieved directly from the text
  2185. * field is used, because forming the file name from a
  2186. * concatenation of XmStrings causes XmListItemPos to fail
  2187. * even though the file name is actually in the list.
  2188. */
  2189. XtVaGetValues(text_field, XmNvalue, &dir_spec, NULL);
  2190. file_name = XtMalloc(strlen(dir_spec)+strlen(name_only)+1);
  2191. strcpy(file_name, dir_spec);
  2192. strcat(file_name, name_only);
  2193. file_name_xmstr = XmStringCreateLocalized(file_name);
  2194. XtFree(dir_spec);
  2195. XtFree(file_name);
  2196. }
  2197. else
  2198. file_name_xmstr = XmStringCreateLocalized(file_name);
  2199. /*
  2200. * find the position of the file name in the list
  2201. */
  2202. position = XmListItemPos(file_list, file_name_xmstr);
  2203. SetListBoxSelection(file_list, position);
  2204. if(position == 0)
  2205. {
  2206. /*
  2207. * The file name is not in the list. Manually set in the
  2208. * "Selection" text field.
  2209. */
  2210. XtVaSetValues(dpd->file_selection_box,
  2211. XmNdirSpec, file_name_xmstr,
  2212. NULL);
  2213. }
  2214. XmStringFree(file_name_xmstr);
  2215. }
  2216. XtFree(name_only);
  2217. /*
  2218. * pop up the file selection dialog and return
  2219. */
  2220. XtManageChild(dpd->file_selection_box);
  2221. _DtTurnOffHourGlass(wmshell_ancestor);
  2222. return DtPRINT_SUCCESS;
  2223. }
  2224. /*
  2225. * ------------------------------------------------------------------------
  2226. * Name: _DtPrintSetupBoxSelectXPrinterProc
  2227. *
  2228. * Description:
  2229. *
  2230. * Default Xp mode function for the DtNselectPrinterProc resource.
  2231. *
  2232. * Return value:
  2233. *
  2234. *
  2235. */
  2236. XtEnum
  2237. _DtPrintSetupBoxSelectXPrinterProc(
  2238. Widget w,
  2239. DtPrintSetupData* print_data)
  2240. {
  2241. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  2242. Widget wmshell_ancestor;
  2243. XmStringTable items;
  2244. int item_count;
  2245. int i;
  2246. XmTabList tab_list;
  2247. XmRenderTable render_table, new_render_table;
  2248. int count;
  2249. XmStringTag* tags;
  2250. XmRendition rendition;
  2251. Arg args[2];
  2252. Cardinal n;
  2253. wmshell_ancestor = GetWMShellAncestor(w);
  2254. _DtTurnOnHourGlass(wmshell_ancestor);
  2255. /*
  2256. * build the list of servers and printers
  2257. */
  2258. if(DtPRINT_SUCCESS != BuildPrinterLists(w, dpd, &item_count))
  2259. {
  2260. PresentErrorDialog(w, PRLIST_ERROR_TITLE,
  2261. NO_PRINTERS_MESSAGE,
  2262. (String)NULL);
  2263. _DtTurnOffHourGlass(wmshell_ancestor);
  2264. return DtPRINT_FAILURE;
  2265. }
  2266. /*
  2267. * create the dialog if it doesn't exist
  2268. */
  2269. if(dpd->printer_selection_box == (Widget)NULL)
  2270. {
  2271. XtEnum status = CreatePrinterSelectionBox(wmshell_ancestor, w, dpd);
  2272. if(status != DtPRINT_SUCCESS)
  2273. {
  2274. _DtTurnOffHourGlass(wmshell_ancestor);
  2275. return status;
  2276. }
  2277. }
  2278. /*
  2279. * get a copy of the list widget's render table
  2280. */
  2281. XtVaGetValues(dpd->printer_list_box,
  2282. XmNrenderTable, &render_table,
  2283. NULL);
  2284. render_table = XmRenderTableCopy(render_table, (XmStringTag*)NULL, 0);
  2285. /*
  2286. * build the item list for the list box
  2287. */
  2288. count = XmRenderTableGetTags(render_table, &tags);
  2289. items = BuildPrinterSelectionItems(XtDisplay(w), dpd, item_count,
  2290. print_data->printer_name, tags[0]);
  2291. /*
  2292. * generate a tab list for the items
  2293. */
  2294. tab_list = XmStringTableProposeTablist(items, item_count,
  2295. dpd->printer_list_box,
  2296. 20, XmRELATIVE);
  2297. /*
  2298. * get a copy of the first rendition in the render table
  2299. */
  2300. rendition = XmRenderTableGetRendition(render_table, tags[0]);
  2301. for(i = 0; i < count; i++)
  2302. XtFree(tags[i]);
  2303. XtFree((char*)tags);
  2304. /*
  2305. * update the copy with the new tab list
  2306. */
  2307. n = 0;
  2308. XtSetArg(args[n], XmNtabList, tab_list); n++;
  2309. XmRenditionUpdate(rendition, args, n);
  2310. XmTabListFree(tab_list);
  2311. /*
  2312. * create a new render table replacing the first entry with the
  2313. * updated rendition
  2314. */
  2315. new_render_table = XmRenderTableAddRenditions(render_table, &rendition,
  2316. 1, XmMERGE_REPLACE);
  2317. XmRenditionFree(rendition);
  2318. /*
  2319. * set the new render table and list items in the list box
  2320. */
  2321. XtVaSetValues(dpd->printer_list_box,
  2322. XmNrenderTable, new_render_table,
  2323. XmNitems, items,
  2324. XmNitemCount, item_count,
  2325. NULL);
  2326. XmRenderTableFree(new_render_table);
  2327. for(i = 0; i < item_count; i++)
  2328. XmStringFree(items[i]);
  2329. XtFree((char*)items);
  2330. SetListBoxSelection(dpd->printer_list_box, dpd->selected_printer);
  2331. /*
  2332. * disable the info button if nothing is selected
  2333. */
  2334. if(0 == dpd->selected_printer)
  2335. XtSetSensitive(XtNameToWidget(dpd->printer_selection_box, "*Apply"),
  2336. False);
  2337. /*
  2338. * manage the dialog and return
  2339. */
  2340. XtManageChild(dpd->printer_selection_box);
  2341. _DtTurnOffHourGlass(wmshell_ancestor);
  2342. return DtPRINT_SUCCESS;
  2343. }
  2344. /*
  2345. * ------------------------------------------------------------------------
  2346. * Name: _DtPrintSetupBoxVerifyXPrinterProc
  2347. *
  2348. * Description:
  2349. *
  2350. * Default function for the DtNverifyPrinterProc resource when the
  2351. * setup mode is XP.
  2352. *
  2353. * (this rest of this description outlines the responsibilities of a
  2354. * DtNverifyPrinterProc in general)
  2355. *
  2356. * This function verifies the printer name passed in the
  2357. * PrintSetupData structure.
  2358. *
  2359. * If needed, the DtNprintSetupMode resource may be obtained via a
  2360. * GetValues call in order to determine the current setup mode.
  2361. *
  2362. * It is the responsibility of this proc to return a valid print
  2363. * Display handle and print context by setting the print_display and
  2364. * print_context in the PrintSetupData. Conceptually, this is a
  2365. * side-effect of this proc, but since it will be necessary to open a
  2366. * display connection in order to properly verify the X printer,
  2367. * there's no point in doing it twice.
  2368. *
  2369. * If the passed printer name is incomplete, this proc may attempt to
  2370. * determine a default or fully-qualified name (e.g. fill in a
  2371. * missing display spec for an X Printer Specifier). The new default
  2372. * or fully-qualified printer name should be set in the PrintSetupBox
  2373. * by updating the DtNprinterName resource via a SetValues call. If a
  2374. * fully-qualified name cannot be determined, this proc simply
  2375. * returns DtPRINT_FAILURE.
  2376. *
  2377. * If the printer cannot be verified, it is the responsibiliy of this
  2378. * function to present an appropriate message to the user.
  2379. *
  2380. * Return value:
  2381. *
  2382. * DtPRINT_SUCCESS
  2383. * if the printer name has been successfully verified.
  2384. *
  2385. * DtPRINT_FAILURE
  2386. * if the printer name is invalid.
  2387. *
  2388. *
  2389. */
  2390. XtEnum
  2391. _DtPrintSetupBoxVerifyXPrinterProc(
  2392. Widget w,
  2393. DtPrintSetupData* psd)
  2394. {
  2395. DtPrintDefaultProcData* dpd = &PSUB_DefaultProcData(w);
  2396. XtEnum status;
  2397. String new_printer_spec;
  2398. Display* new_display;
  2399. #if 0 && defined(PRINTING_SUPPORTED)
  2400. XPContext new_context;
  2401. #endif /* PRINTING_SUPPORTED */
  2402. Widget wmshell_ancestor;
  2403. wmshell_ancestor = GetWMShellAncestor(w);
  2404. _DtTurnOnHourGlass(wmshell_ancestor);
  2405. /*
  2406. * verify the printer
  2407. */
  2408. status = _DtPrintVerifyXPrinter(w,
  2409. psd->printer_name,
  2410. &new_printer_spec,
  2411. &new_display
  2412. #if 0 && defined(PRINTING_SUPPORTED)
  2413. ,&new_context
  2414. #endif /* PRINTING_SUPPORTED */
  2415. );
  2416. if(status == DtPRINT_SUCCESS)
  2417. {
  2418. /*
  2419. * update the passed print setup data with the new display and
  2420. * context
  2421. */
  2422. psd->print_display = new_display;
  2423. #if 0 && defined(PRINTING_SUPPORTED)
  2424. psd->print_context = new_context;
  2425. #endif /* PRINTING_SUPPORTED */
  2426. }
  2427. else
  2428. {
  2429. /*
  2430. * unable to open the printer; present a message to the user
  2431. * according to the hint set in the setup data
  2432. */
  2433. dpd->messages_hint = psd->messages_hint;
  2434. PresentVerifyError(w, status,
  2435. new_printer_spec
  2436. ? new_printer_spec : psd->printer_name);
  2437. /*
  2438. * reset the hint since the error dialog is also used
  2439. * by the other default procs
  2440. */
  2441. dpd->messages_hint = DtPRINT_HINT_MESSAGES_OK;
  2442. /*
  2443. * this function only indicates success or failure
  2444. */
  2445. status = DtPRINT_FAILURE;
  2446. }
  2447. if(new_printer_spec)
  2448. {
  2449. /*
  2450. * set the new printer spec, even if the verify failed
  2451. */
  2452. XtVaSetValues(w,
  2453. DtNprinterName, new_printer_spec,
  2454. NULL);
  2455. XtFree(new_printer_spec);
  2456. }
  2457. /*
  2458. * return
  2459. */
  2460. _DtTurnOffHourGlass(wmshell_ancestor);
  2461. return status;
  2462. }