PrintOptions.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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: PrintOptions.c /main/4 1996/04/29 17:12:37 rswiston $ */
  24. /*
  25. *+SNOTICE
  26. *
  27. * $:$
  28. *
  29. * RESTRICTED CONFIDENTIAL INFORMATION:
  30. *
  31. * The information in this document is subject to special
  32. * restrictions in a confidential disclosure agreement between
  33. * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
  34. * document outside HP, IBM, Sun, USL, SCO, or Univel without
  35. * Sun's specific written approval. This document and all copies
  36. * and derivative works thereof must be returned or destroyed at
  37. * Sun's request.
  38. *
  39. * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
  40. *
  41. *+ENOTICE
  42. */
  43. /*
  44. * Common Desktop Environment
  45. *
  46. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  47. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  48. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  49. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  50. * (c) Copyright 1995 Digital Equipment Corp.
  51. * (c) Copyright 1995 Fujitsu Limited
  52. * (c) Copyright 1995 Hitachi, Ltd.
  53. *
  54. *
  55. * RESTRICTED RIGHTS LEGEND
  56. *
  57. * Use, duplication, or disclosure by the U.S. Government is subject to
  58. * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  59. * Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
  60. * for non-DOD U.S. Government Departments and Agencies are as set forth in
  61. * FAR 52.227-19(c)(1,2).
  62. *
  63. * Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
  64. * International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
  65. * Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
  66. * Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
  67. * Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
  68. * Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
  69. * Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
  70. */
  71. #include <Xm/XmAll.h>
  72. #include "Dt/Print.h"
  73. #include "PrintMsgsP.h"
  74. #include "PrintOptionsP.h"
  75. /******************************************************************************
  76. *
  77. * Static functions
  78. *
  79. ******************************************************************************/
  80. static void
  81. _DtPrintDestroyHdrFtrFrameCB(
  82. Widget frame,
  83. XtPointer client_data,
  84. XtPointer call_data
  85. );
  86. static void
  87. _DtPrintDestroyMarginFrameCB(
  88. Widget frame,
  89. XtPointer client_data,
  90. XtPointer call_data
  91. );
  92. /******************************************************************************
  93. *
  94. * _DtPrint Header/Footer API
  95. *
  96. ******************************************************************************/
  97. typedef struct dtpo_header_footer_spec
  98. {
  99. Widget button;
  100. void *data;
  101. char *string;
  102. } DtpoHdrFtrSpec;
  103. typedef struct dtpo_header_footer_frame
  104. {
  105. Widget frame,
  106. label,
  107. form,
  108. menu,
  109. top_left,
  110. top_right,
  111. bottom_left,
  112. bottom_right;
  113. int nspecs;
  114. DtpoHdrFtrSpec *specs;
  115. } DtpoHdrFtrFrame;
  116. static void
  117. _DtPrintDestroyHdrFtrFrameCB(
  118. Widget frame,
  119. XtPointer client_data,
  120. XtPointer call_data
  121. )
  122. {
  123. DtpoHdrFtrFrame *info = (DtpoHdrFtrFrame *) client_data;
  124. if (info == NULL) return;
  125. if (info->specs != NULL)
  126. XtFree((char*) info->specs);
  127. XtFree((char*) info);
  128. }
  129. /*
  130. * Function: _DtPrintCreateHdrFtrFrame
  131. *
  132. * Creates a frame for specifying the contents of page headers and footers.
  133. * The frame contains four option menus, one for each _DtPrintHdrFtrEnum.
  134. * The pulldown menus for the option menu are constructed from the .string
  135. * field in the array of _DtPrintHdrFtrSpec in "specs".
  136. *
  137. * _DtPrintCreateHdrFtrFrame copies the pointer to the array of
  138. * _DtPrintHdrFtrSpec. IT DOES NOT COPY THE ELEMENTS OF THE ARRAY.
  139. *
  140. * parent - specifies the parent of the frame.
  141. * nspecs - specifies the number of entries in the specs array.
  142. * specs - array of header/footer specifiers. The .string
  143. * field is used to construct labels in the GUI.
  144. * The .data field is returned in calls to
  145. * _DtPrintGetHdrFtrSpec.
  146. *
  147. * Returns the widget id for the frame.
  148. */
  149. Widget
  150. _DtPrintCreateHdrFtrFrame(
  151. Widget parent,
  152. int nspecs,
  153. char **spec_strings,
  154. void **spec_data
  155. )
  156. {
  157. DtpoHdrFtrFrame *info;
  158. Arg args[16];
  159. int n;
  160. int i;
  161. XmString xms;
  162. info = (DtpoHdrFtrFrame *) XtMalloc( sizeof(DtpoHdrFtrFrame) );
  163. info->nspecs = nspecs;
  164. info->specs = (DtpoHdrFtrSpec *) XtMalloc(nspecs*sizeof(DtpoHdrFtrSpec));
  165. for (i=0; i<nspecs; i++)
  166. {
  167. info->specs[i].string = spec_strings[i];
  168. if (spec_data != (void*) NULL)
  169. info->specs[i].data = spec_data[i];
  170. else
  171. info->specs[i].data = (void*) NULL;
  172. info->specs[i].button = (Widget) NULL;
  173. }
  174. /*
  175. * Create the frame and attach add a destroyCallback to clean up
  176. * memory allocated for this object.
  177. */
  178. n = 0;
  179. XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
  180. XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
  181. XtSetArg(args[n], XmNuserData, info); n++;
  182. info->frame = XmCreateFrame(parent, "HdrFtrFrame", args, n);
  183. XtAddCallback(
  184. info->frame,
  185. XmNdestroyCallback,
  186. _DtPrintDestroyHdrFtrFrameCB,
  187. (XtPointer) info
  188. );
  189. /*
  190. * Create a label child for the frame
  191. */
  192. xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_LABEL);
  193. n = 0;
  194. XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
  195. XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
  196. XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
  197. XtSetArg(args[n], XmNlabelString, xms); n++;
  198. info->label = XmCreateLabel(info->frame, "HdrFtrLabel", args, n);
  199. XtManageChild(info->label);
  200. XmStringFree(xms);
  201. /*
  202. * Create a form work area child which will be populated by the
  203. * OptionMenu's.
  204. */
  205. n = 0;
  206. XtSetArg(args[n], XmNallowOverlap, False); n++;
  207. XtSetArg(args[n], XmNfractionBase, 2); n++;
  208. info->form = XmCreateForm(info->frame, "HdrFtrForm", args, n);
  209. /*
  210. * Create the pulldown menu for the option menus.
  211. * Store the button index in the userData resource of each button.
  212. */
  213. info->menu = XmCreatePulldownMenu(parent, "HdrFtrMenu", NULL, 0);
  214. for (i=0; i<info->nspecs; i++)
  215. {
  216. static char button_label[32];
  217. sprintf(button_label, "Button%d", i);
  218. xms = XmStringCreateLocalized(info->specs[i].string);
  219. n = 0;
  220. XtSetArg(args[n], XmNlabelString, xms); n++;
  221. XtSetArg(args[n], XmNuserData, i); n++;
  222. info->specs[i].button =
  223. XmCreatePushButtonGadget(info->menu, button_label, args, n);
  224. XmStringFree(xms);
  225. XtManageChild(info->specs[i].button);
  226. }
  227. /*
  228. * Create the option menus using the menu created above.
  229. */
  230. xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_TOP_LEFT_LABEL);
  231. n=0;
  232. XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
  233. XtSetArg(args[n], XmNlabelString, xms); n++;
  234. XtSetArg(args[n], XmNuserData, info); n++;
  235. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  236. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  237. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  238. XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  239. XtSetArg(args[n], XmNrightPosition, 1); n++;
  240. XtSetArg(args[n], XmNrightOffset, 5); n++;
  241. info->top_left = XmCreateOptionMenu(
  242. info->form,
  243. "PageHeaderLeftOM",
  244. args, n
  245. );
  246. XmStringFree(xms);
  247. XtManageChild(info->top_left);
  248. xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_TOP_RIGHT_LABEL);
  249. n=0;
  250. XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
  251. XtSetArg(args[n], XmNlabelString, xms); n++;
  252. XtSetArg(args[n], XmNuserData, info); n++;
  253. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  254. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  255. XtSetArg(args[n], XmNtopWidget, info->top_left); n++;
  256. XtSetArg(args[n], XmNtopOffset, 0); n++;
  257. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  258. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  259. info->top_right = XmCreateOptionMenu(
  260. info->form,
  261. "PageHeaderRightOM",
  262. args, n
  263. );
  264. XmStringFree(xms);
  265. XtManageChild(info->top_right);
  266. xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_BOTTOM_LEFT_LABEL);
  267. n=0;
  268. XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
  269. XtSetArg(args[n], XmNlabelString, xms); n++;
  270. XtSetArg(args[n], XmNuserData, info); n++;
  271. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  272. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  273. XtSetArg(args[n], XmNtopWidget, info->top_left); n++;
  274. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  275. XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  276. XtSetArg(args[n], XmNrightWidget, info->top_left); n++;
  277. XtSetArg(args[n], XmNrightOffset, 0); n++;
  278. info->bottom_left = XmCreateOptionMenu(
  279. info->form,
  280. "PageFooterLeftOM",
  281. args, n
  282. );
  283. XmStringFree(xms);
  284. XtManageChild(info->bottom_left);
  285. xms = XmStringCreateLocalized(DTPO_HEADERFOOTER_FRAME_BOTTOM_RIGHT_LABEL);
  286. n=0;
  287. XtSetArg(args[n], XmNsubMenuId, info->menu); n++;
  288. XtSetArg(args[n], XmNlabelString, xms); n++;
  289. XtSetArg(args[n], XmNuserData, info); n++;
  290. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  291. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  292. XtSetArg(args[n], XmNtopWidget, info->bottom_left); n++;
  293. XtSetArg(args[n], XmNtopOffset, 0); n++;
  294. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  295. XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  296. XtSetArg(args[n], XmNrightWidget, info->top_right); n++;
  297. XtSetArg(args[n], XmNrightOffset, 0); n++;
  298. info->bottom_right = XmCreateOptionMenu(
  299. info->form,
  300. "PageFooterRightOM",
  301. args, n
  302. );
  303. XmStringFree(xms);
  304. XtManageChild(info->bottom_right);
  305. XtManageChild(info->form);
  306. return info->frame;
  307. }
  308. /*
  309. * Function: _DtPrintHdrFtrFrameEnumToWidget
  310. *
  311. * Returns the widget id of the option menu corresponding the specified
  312. * header or footer.
  313. *
  314. * frame - specifies the HdrFtr frame
  315. * which - specifies the particular header or footer in "frame".
  316. *
  317. * Returns the widget id of the option menu for "which"
  318. */
  319. Widget
  320. _DtPrintHdrFtrFrameEnumToWidget(
  321. Widget frame,
  322. _DtPrintHdrFtrEnum which
  323. )
  324. {
  325. DtpoHdrFtrFrame *info;
  326. Widget widget = NULL;
  327. XtVaGetValues(frame, XmNuserData, &info, NULL);
  328. if (info == NULL)
  329. return widget;
  330. switch (which)
  331. {
  332. case DTPRINT_OPTION_HEADER_LEFT:
  333. widget = info->top_left; break;
  334. case DTPRINT_OPTION_HEADER_RIGHT:
  335. widget = info->top_right; break;
  336. case DTPRINT_OPTION_FOOTER_LEFT:
  337. widget = info->bottom_left; break;
  338. case DTPRINT_OPTION_FOOTER_RIGHT:
  339. widget = info->bottom_right; break;
  340. default:
  341. widget = NULL;
  342. }
  343. return widget;
  344. }
  345. /*
  346. * Function: _DtPrintHdrFtrFrameMenuWidgets
  347. *
  348. * widget -specifies the option menu
  349. *
  350. * Returns the widgets which make up the pulldown menu.
  351. */
  352. void
  353. _DtPrintHdrFtrFrameMenuWidgets(
  354. Widget frame,
  355. Widget *menu,
  356. int *nmenu_buttons,
  357. Widget **menu_buttons
  358. )
  359. {
  360. int i;
  361. DtpoHdrFtrFrame *info;
  362. if (frame == NULL) return;
  363. XtVaGetValues(frame, XmNuserData, &info, NULL);
  364. if (info == NULL) return;
  365. if (menu != NULL)
  366. *menu = info->menu;
  367. if (nmenu_buttons != NULL)
  368. *nmenu_buttons = info->nspecs;
  369. if (menu_buttons != NULL)
  370. {
  371. if (*menu_buttons == NULL)
  372. *menu_buttons = (Widget *) XtMalloc( info->nspecs * sizeof(Widget) );
  373. for (i=0; i<info->nspecs; i++)
  374. (*menu_buttons)[i] = info->specs[i].button;
  375. }
  376. }
  377. /*
  378. * Function: _DtPrintGetHdrFtrIndex
  379. *
  380. * option - specifies the HdrFtr option menu
  381. *
  382. * Returns the index of the active menu option of the specified
  383. * option menu.
  384. */
  385. int
  386. _DtPrintGetHdrFtrIndex(
  387. Widget option
  388. )
  389. {
  390. int index = -1;
  391. Widget selected;
  392. if (! option) return index;
  393. XtVaGetValues(option, XmNmenuHistory, &selected, NULL);
  394. XtVaGetValues(selected, XmNuserData, &index, NULL);
  395. return index;
  396. }
  397. /*
  398. * Function: _DtPrintGetHdrFtrData
  399. *
  400. * option - specifies the HdrFtr option menu
  401. *
  402. * Returns the data associated with the active menu option of the specified
  403. * option menu.
  404. */
  405. void *
  406. _DtPrintGetHdrFtrData(
  407. Widget option
  408. )
  409. {
  410. int index = 0;
  411. DtpoHdrFtrFrame *info = NULL;
  412. if (! option) return (void*) NULL;
  413. XtVaGetValues(option, XmNuserData, &info, NULL);
  414. if (info == NULL) return 0;
  415. index = _DtPrintGetHdrFtrIndex(option);
  416. return info->specs[index].data;
  417. }
  418. /*
  419. * Function: _DtPrintGetHdrFtrString
  420. *
  421. * option - specifies the HdrFtr option menu
  422. *
  423. * Returns the string associated with the active menu option of the specified
  424. * option menu.
  425. */
  426. char *
  427. _DtPrintGetHdrFtrString(
  428. Widget option
  429. )
  430. {
  431. int index = 0;
  432. DtpoHdrFtrFrame *info = NULL;
  433. if (! option) return (void*) NULL;
  434. XtVaGetValues(option, XmNuserData, &info, NULL);
  435. if (info == NULL) return 0;
  436. index = _DtPrintGetHdrFtrIndex(option);
  437. return info->specs[index].string;
  438. }
  439. /*
  440. * Function: _DtPrintSetHdrFtrByData
  441. *
  442. * Displays the specified menu item as the currently active option.
  443. *
  444. * option - specifies the HdrFtr option menu
  445. * data - data associated with the option to be displayed.
  446. */
  447. void
  448. _DtPrintSetHdrFtrByData(
  449. Widget option,
  450. void *data
  451. )
  452. {
  453. int i;
  454. DtpoHdrFtrFrame *info;
  455. if (option == NULL) return;
  456. XtVaGetValues(option, XmNuserData, &info, NULL);
  457. if (info == NULL) return;
  458. for (i=0; i<info->nspecs; i++)
  459. if (info->specs[i].data == data)
  460. {
  461. XtVaSetValues(option, XmNmenuHistory, info->specs[i].button, NULL);
  462. return;
  463. }
  464. }
  465. /*
  466. * Function: _DtPrintSetHdrFtrByIndex
  467. *
  468. * Displays the specified menu item as the currently active option.
  469. *
  470. * option - specifies the HdrFtr option menu
  471. * index - specifies the option to be displayed.
  472. */
  473. void
  474. _DtPrintSetHdrFtrByIndex(
  475. Widget option,
  476. int index
  477. )
  478. {
  479. DtpoHdrFtrFrame *info;
  480. if (option == NULL) return;
  481. XtVaGetValues(option, XmNuserData, &info, NULL);
  482. if (info == NULL) return;
  483. XtVaSetValues(option, XmNmenuHistory, info->specs[index].button, NULL);
  484. }
  485. /*
  486. * Function: _DtPrintSetHdrFtrByString
  487. *
  488. * Displays the specified menu item as the currently active option.
  489. *
  490. * option - specifies the HdrFtr option menu
  491. * string - string associated with the option to be displayed.
  492. */
  493. void
  494. _DtPrintSetHdrFtrByString(
  495. Widget option,
  496. char *string
  497. )
  498. {
  499. int i;
  500. DtpoHdrFtrFrame *info;
  501. if (option == NULL) return;
  502. XtVaGetValues(option, XmNuserData, &info, NULL);
  503. if (info == NULL) return;
  504. for (i=0; i<info->nspecs; i++)
  505. if (strcmp(info->specs[i].string,string) == 0)
  506. {
  507. XtVaSetValues(option, XmNmenuHistory, info->specs[i].button, NULL);
  508. return;
  509. }
  510. }
  511. /******************************************************************************
  512. *
  513. * _DtPrint Margin API
  514. *
  515. ******************************************************************************/
  516. typedef struct dtpo_margin_frame
  517. {
  518. Widget frame,
  519. label,
  520. form,
  521. top,
  522. right,
  523. bottom,
  524. left,
  525. top_label,
  526. right_label,
  527. bottom_label,
  528. left_label;
  529. } DtpoMarginFrame;
  530. static void
  531. _DtPrintDestroyMarginFrameCB(
  532. Widget frame,
  533. XtPointer client_data,
  534. XtPointer call_data
  535. )
  536. {
  537. DtpoHdrFtrFrame *info = (DtpoHdrFtrFrame *) client_data;
  538. if (info == NULL) return;
  539. XtFree((char*) info);
  540. }
  541. /*
  542. * Function: _DtPrintCreateMarginFrame
  543. *
  544. * Creates a frame for specifying margins. The frame contains four text
  545. * fields, one for each _DtPrintMarginEnum.
  546. *
  547. * parent - specifies the parent of the frame.
  548. *
  549. * Returns the widget id of the frame.
  550. */
  551. Widget
  552. _DtPrintCreateMarginFrame(
  553. Widget parent
  554. )
  555. {
  556. DtpoMarginFrame
  557. *info;
  558. Arg args[16];
  559. int n;
  560. XmString xms;
  561. info = (DtpoMarginFrame *) XtMalloc( sizeof(DtpoMarginFrame) );
  562. n = 0;
  563. XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
  564. XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
  565. XtSetArg(args[n], XmNuserData, info); n++;
  566. info->frame = XmCreateFrame(parent, "MarginFrame", args, n);
  567. XtAddCallback(
  568. info->frame,
  569. XmNdestroyCallback,
  570. _DtPrintDestroyMarginFrameCB,
  571. (XtPointer) info
  572. );
  573. xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_LABEL);
  574. n = 0;
  575. XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
  576. XtSetArg(args[n], XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING); n++;
  577. XtSetArg(args[n], XmNchildVerticalAlignment, XmALIGNMENT_CENTER); n++;
  578. XtSetArg(args[n], XmNlabelString, xms); n++;
  579. info->label = XmCreateLabel(info->frame, "MarginLabel", args, n);
  580. XtManageChild(info->label);
  581. XmStringFree(xms);
  582. n = 0;
  583. XtSetArg(args[n], XmNallowOverlap, False); n++;
  584. XtSetArg(args[n], XmNfractionBase, 2); n++;
  585. info->form = XmCreateForm(info->frame, "MarginForm", args, n);
  586. n = 0;
  587. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  588. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  589. XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  590. XtSetArg(args[n], XmNrightPosition, 1); n++;
  591. XtSetArg(args[n], XmNrightOffset, 5); n++;
  592. info->top = XmCreateTextField(info->form, "MarginTopText", args, n);
  593. XtManageChild(info->top);
  594. xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_TOP_MARGIN_LABEL);
  595. n = 0;
  596. XtSetArg(args[n], XmNlabelString, xms); n++;
  597. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  598. XtSetArg(args[n], XmNtopWidget, info->top); n++;
  599. XtSetArg(args[n], XmNtopOffset, 0); n++;
  600. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  601. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  602. XtSetArg(args[n], XmNrightWidget, info->top); n++;
  603. XtSetArg(args[n], XmNrightOffset, 3); n++;
  604. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  605. XtSetArg(args[n], XmNbottomWidget, info->top); n++;
  606. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  607. info->top_label =
  608. XmCreateLabelGadget(info->form, "MarginTopLabel", args, n);
  609. XmStringFree(xms);
  610. XtManageChild(info->top_label);
  611. n = 0;
  612. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  613. XtSetArg(args[n], XmNtopWidget, info->top); n++;
  614. XtSetArg(args[n], XmNtopOffset, 0); n++;
  615. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  616. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  617. info->right = XmCreateTextField(info->form, "MarginRightText", args, n);
  618. XtManageChild(info->right);
  619. xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_RIGHT_MARGIN_LABEL);
  620. n = 0;
  621. XtSetArg(args[n], XmNlabelString, xms); n++;
  622. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  623. XtSetArg(args[n], XmNtopWidget, info->right); n++;
  624. XtSetArg(args[n], XmNtopOffset, 0); n++;
  625. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  626. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  627. XtSetArg(args[n], XmNrightWidget, info->right); n++;
  628. XtSetArg(args[n], XmNrightOffset, 3); n++;
  629. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  630. XtSetArg(args[n], XmNbottomWidget, info->right); n++;
  631. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  632. info->right_label =
  633. XmCreateLabelGadget(info->form, "MarginRightLabel", args, n);
  634. XmStringFree(xms);
  635. XtManageChild(info->right_label);
  636. n = 0;
  637. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  638. XtSetArg(args[n], XmNtopWidget, info->top); n++;
  639. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  640. XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  641. XtSetArg(args[n], XmNrightWidget, info->top); n++;
  642. XtSetArg(args[n], XmNrightOffset, 0); n++;
  643. info->bottom = XmCreateTextField(info->form, "MarginBottomText", args, n);
  644. XtManageChild(info->bottom);
  645. xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_BOTTOM_MARGIN_LABEL);
  646. n = 0;
  647. XtSetArg(args[n], XmNlabelString, xms); n++;
  648. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  649. XtSetArg(args[n], XmNtopWidget, info->bottom); n++;
  650. XtSetArg(args[n], XmNtopOffset, 0); n++;
  651. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  652. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  653. XtSetArg(args[n], XmNrightWidget, info->bottom); n++;
  654. XtSetArg(args[n], XmNrightOffset, 3); n++;
  655. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  656. XtSetArg(args[n], XmNbottomWidget, info->bottom); n++;
  657. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  658. info->bottom_label =
  659. XmCreateLabelGadget(info->form, "MarginBottomLabel", args, n);
  660. XmStringFree(xms);
  661. XtManageChild(info->bottom_label);
  662. n = 0;
  663. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  664. XtSetArg(args[n], XmNtopWidget, info->bottom); n++;
  665. XtSetArg(args[n], XmNtopOffset, 0); n++;
  666. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  667. XtSetArg(args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  668. XtSetArg(args[n], XmNrightWidget, info->right); n++;
  669. XtSetArg(args[n], XmNrightOffset, 0); n++;
  670. info->left = XmCreateTextField(info->form, "MarginLeftText", args, n);
  671. XtManageChild(info->left);
  672. xms = XmStringCreateLocalized(DTPO_MARGIN_FRAME_LEFT_MARGIN_LABEL);
  673. n = 0;
  674. XtSetArg(args[n], XmNlabelString, xms); n++;
  675. XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  676. XtSetArg(args[n], XmNtopWidget, info->left); n++;
  677. XtSetArg(args[n], XmNtopOffset, 0); n++;
  678. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  679. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  680. XtSetArg(args[n], XmNrightWidget, info->left); n++;
  681. XtSetArg(args[n], XmNrightOffset, 3); n++;
  682. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  683. XtSetArg(args[n], XmNbottomWidget, info->left); n++;
  684. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  685. info->left_label =
  686. XmCreateLabelGadget(info->form, "MarginLeftLabel", args, n);
  687. XmStringFree(xms);
  688. XtManageChild(info->left_label);
  689. XtManageChild(info->form);
  690. return info->frame;
  691. }
  692. /*
  693. * Function: _DtPrintMarginFrameEnumToWidget
  694. *
  695. * frame - specifies the HdrFtr frame
  696. * which - specifies the particular margin in "frame".
  697. *
  698. * Returns the widget id of the textfield for "which"
  699. */
  700. Widget
  701. _DtPrintMarginFrameEnumToWidget(
  702. Widget frame,
  703. _DtPrintMarginEnum which
  704. )
  705. {
  706. DtpoMarginFrame *info;
  707. Widget widget = NULL;
  708. XtVaGetValues(frame, XmNuserData, &info, NULL);
  709. if (info == NULL)
  710. return widget;
  711. switch (which)
  712. {
  713. case DTPRINT_OPTION_MARGIN_TOP:
  714. widget = info->top; break;
  715. case DTPRINT_OPTION_MARGIN_RIGHT:
  716. widget = info->right; break;
  717. case DTPRINT_OPTION_MARGIN_BOTTOM:
  718. widget = info->bottom; break;
  719. case DTPRINT_OPTION_MARGIN_LEFT:
  720. widget = info->left; break;
  721. default:
  722. break;
  723. }
  724. return widget;
  725. }
  726. /*
  727. * Function: _DtPrintGetMarginSpec
  728. *
  729. * margin - specifies the margin widget.
  730. *
  731. * Returns a copy of the contents of the specified margin.
  732. * The calling function should free this string when done with it.
  733. */
  734. char*
  735. _DtPrintGetMarginSpec(
  736. Widget margin
  737. )
  738. {
  739. char *spec = NULL;
  740. if (margin)
  741. spec = XmTextFieldGetString(margin);
  742. return spec;
  743. }
  744. /*
  745. * Function: _DtPrintSetMarginSpec
  746. *
  747. * margin -specifies the margin widget.
  748. * spec - specifies the string to be displayed in the GUI.
  749. *
  750. */
  751. void
  752. _DtPrintSetMarginSpec(
  753. Widget margin,
  754. char *spec
  755. )
  756. {
  757. if (margin)
  758. XmTextFieldSetString(margin, spec);
  759. }