2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: PrinterBox.c /main/10 1996/11/20 12:59:48 cde-hp $ */
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.
37 #include <Dt/DtNlUtils.h>
39 #include "PrinterBox.h"
43 #ifndef CDE_INSTALLATION_TOP
44 #define CDE_INSTALLATION_TOP "/usr/dt"
47 #define ICON_INSTALL_DIR CDE_INSTALLATION_TOP "/appconfig/icons/C/"
50 # define MAX(a, b) ((a) > (b) ? (a) : (b))
54 * PrinterBox-specific data - PdmSetupBox.subclass_data
61 struct _OrientCtl* orient_ctl;
62 struct _PlexCtl* plex_ctl;
63 struct _TrayCtl* tray_ctl;
64 struct _SizeCtl* size_ctl;
68 const char* printer_model;
69 char* document_format;
71 PdmOidList* document_attrs_supported;
73 PdmOidList* orientations_supported;
76 PdmOidList* plexes_supported;
79 PdmOid default_input_tray;
80 PdmOid default_medium;
82 PdmOidList* input_trays;
83 PdmOidList* tray_sizes;
84 PdmOidLinkedList* sizes_supported;
89 * orientations control
91 typedef struct _OrientCtl
100 const PdmOidList* orientations_supported;
101 PdmOidList* dummy_orientations_supported;
103 struct _PdmPixmapList* pixmap_list;
104 struct _PdmPixmapList* i_pixmap_list;
106 struct _PlexCtl* plex_ctl;
113 typedef struct _PlexCtl
122 const PdmOidList* plexes_supported;
123 PdmOidList* dummy_plexes_supported;
125 struct _PdmPixmapList** pixmap_list_ptr;
126 struct _PdmPixmapList* portrait_pixmap_list;
127 struct _PdmPixmapList* landscape_pixmap_list;
129 struct _PdmPixmapList** i_pixmap_list_ptr;
130 struct _PdmPixmapList* i_portrait_pixmap_list;
131 struct _PdmPixmapList* i_landscape_pixmap_list;
136 * input trays control
138 typedef struct _TrayCtl
146 const PdmOidList* input_trays;
147 const PdmOidList* tray_sizes;
149 struct _SizeCtl* size_ctl;
156 typedef struct _SizeCtlSortRec
160 } SizeCtlSortRec, *SizeCtlSortList;
162 typedef struct _SizeCtl
169 Widget supported_radio;
171 PdmOidList* sizes_ready;
172 PdmOidList* sizes_supported;
174 PdmOid selected_size;
178 SIZECTL_SIZES_SUPPORTED } selected_list;
180 Boolean single_size_mode;
182 XmStringTable sizes_ready_xmstr;
183 XmStringTable sizes_supported_xmstr;
190 typedef struct _PdmPixmapList
196 Pixel foreground, background;
201 * PrinterBox-specific fallback resources
203 static String PdmPrinterBoxFallbackResources[] =
205 "*PrinterSetup*LoadedAllowed.button_0.labelString: Loaded in Printer",
206 "*PrinterSetup*LoadedAllowed.button_1.labelString: All Sizes",
207 "*PrinterSetup*OrientationLabel.labelString: Page Orientation",
208 "*PrinterSetup*PageSizeLabel.labelString: Page Size",
209 "*PrinterSetup*PlexLabel.labelString: Printed Sides",
210 "*PrinterSetup*DocumentFormatLabel.labelString: Format:",
211 "*PrinterSetup*PrinterModelLabel.labelString: Printer Model:",
212 "*PrinterSetup*TrayLabel.labelString: Tray",
213 "*PrinterSetup.locationId: PrinterSetup",
214 "*PrinterSetup*OrientCtlTop.PortraitIconFileName: "
215 ICON_INSTALL_DIR "portrait.pm",
216 "*PrinterSetup*OrientCtlTop.LandscapeIconFileName: "
217 ICON_INSTALL_DIR "landscap.pm",
218 "*PrinterSetup*OrientCtlTop.ReversePortraitIconFileName: "
219 ICON_INSTALL_DIR "rportrai.pm",
220 "*PrinterSetup*OrientCtlTop.ReverseLandscapeIconFileName: "
221 ICON_INSTALL_DIR "rlandsca.pm",
222 "*PrinterSetup*PlexCtlTop.SimplexPortraitIconFileName: "
223 ICON_INSTALL_DIR "psimplex.pm",
224 "*PrinterSetup*PlexCtlTop.SimplexLandscapeIconFileName: "
225 ICON_INSTALL_DIR "lsimplex.pm",
226 "*PrinterSetup*PlexCtlTop.DuplexPortraitIconFileName: "
227 ICON_INSTALL_DIR "pduplex.pm",
228 "*PrinterSetup*PlexCtlTop.DuplexLandscapeIconFileName: "
229 ICON_INSTALL_DIR "lduplex.pm",
230 "*PrinterSetup*PlexCtlTop.TumblePortraitIconFileName: "
231 ICON_INSTALL_DIR "ptumble.pm",
232 "*PrinterSetup*PlexCtlTop.TumbleLandscapeIconFileName: "
233 ICON_INSTALL_DIR "ltumble.pm",
234 "*PrinterTab.compoundString: Printer",
235 "*PrinterTab.labelString: Printer"
239 * Printer Setup Box static function declarations
241 static void PdmPrinterBoxDelete(PdmSetupBox* me);
242 static void PdmPrinterBoxCreate(PdmSetupBox* me, Widget parent);
243 static PdmStatus PdmPrinterBoxVerifyAttr(PdmSetupBox* me, PdmXp* pdm_xp);
244 static void PdmPrinterBoxGetAttr(PdmSetupBox* me, PdmXp* pdm_xp);
245 static void PdmPrinterBoxSetAttr(PdmSetupBox* me, PdmXp* pdm_xp);
246 static Widget PdmPrinterBoxCreateWindow(PdmSetupBox* me, Widget parent);
247 static void PdmPrinterBoxResizeCB(Widget w,
248 XtPointer client_data,
249 XtPointer call_data);
251 * Orientation Control methods
253 static OrientCtl* OrientCtlNew(PlexCtl* plex_ctl);
254 static void OrientCtlDelete(OrientCtl* me);
255 static void OrientCtlCreate(OrientCtl* me,
258 const PdmOidList* document_attrs_supported,
259 const PdmOidList* orientations_supported);
260 static void OrientCtlCreateWindow(OrientCtl* me, Widget parent);
261 #define OrientCtlGetWidget(me) ((me)->widget)
262 static void OrientCtlCreatePulldown(OrientCtl* me);
263 static void OrientCtlDisable(OrientCtl* me);
264 static void OrientCtlUpdateIcon(OrientCtl* me);
265 static PdmOid OrientCtlGetOrientation(OrientCtl* me);
266 static void OrientCtlResizeCB(Widget w,
267 XtPointer client_data, XtPointer call_data);
268 static void OrientCtlSetSelectedItem(OrientCtl* me, int selected_item);
269 static void OrientCtlSelectCB(Widget w, XtPointer client_d, XtPointer call_d);
270 static void OrientCtlInitPixmapList(OrientCtl* me);
273 * Plex Control methods
275 static PlexCtl* PlexCtlNew();
276 static void PlexCtlDelete(PlexCtl* me);
277 static void PlexCtlCreate(PlexCtl* me,
280 const PdmOidList* document_attrs_supported,
281 const PdmOidList* plexes_supported);
282 static void PlexCtlCreateWindow(PlexCtl* me, Widget parent);
283 static void PlexCtlDisable(PlexCtl* me);
284 #define PlexCtlGetWidget(me) ((me)->widget)
285 static void PlexCtlCreatePulldown(PlexCtl* me);
286 static void PlexCtlUpdateIcon(PlexCtl* me);
287 static PdmOid PlexCtlGetPlex(PlexCtl* me);
288 static void PlexCtlResizeCB(Widget w,
289 XtPointer client_data, XtPointer call_data);
290 static void PlexCtlSetSelectedItem(PlexCtl* me, int selected_item);
291 static void PlexCtlSelectCB(Widget w, XtPointer client_d, XtPointer call_d);
292 static void PlexCtlSetOrientation(PlexCtl* me, PdmOid orientation);
293 static void PlexCtlInitPixmapLists(PlexCtl* me);
296 * Tray Control methods
298 static TrayCtl* TrayCtlNew(SizeCtl* size_ctl);
299 static void TrayCtlDelete(TrayCtl* me);
300 static void TrayCtlCreate(TrayCtl* me,
302 PdmOid default_input_tray,
303 PdmOid default_medium,
304 const PdmOidList* document_attrs_supported,
305 const PdmOidList* input_trays,
306 const PdmOidList* tray_sizes);
307 static void TrayCtlCreateWindow(TrayCtl* me, Widget parent);
308 #define TrayCtlGetWidget(me) ((me)->widget)
309 static PdmOid TrayCtlGetTray(TrayCtl* me);
310 static void TrayCtlDisable(TrayCtl* me);
311 static void TrayCtlResizeCB(Widget w,
312 XtPointer client_data, XtPointer call_data);
313 static void TrayCtlCreatePulldown(TrayCtl* me);
314 static void TrayCtlSetSelectedItem(TrayCtl* me, int selected_item);
315 static void TrayCtlSelectCB(Widget w, XtPointer client_d, XtPointer call_d);
318 * Size Control methods
320 static SizeCtl* SizeCtlNew();
321 static void SizeCtlDelete(SizeCtl* me);
322 static int SizeCtlStrColl(const void* e1, const void* e2);
323 static void SizeCtlSetSizeLists(PdmOidList** oids,
324 XmStringTable* xmstrs,
325 PdmOidLinkedList* oids_ll);
326 static void SizeCtlCreate(SizeCtl* me,
328 PdmOid default_medium,
329 const PdmOidList* document_attrs_supported,
330 const PdmOidList* tray_sizes,
331 PdmOidLinkedList* sizes_supported);
332 static void SizeCtlCreateWindow(SizeCtl* me, Widget parent);
333 #define SizeCtlGetWidget(me) ((me)->widget)
334 static void SizeCtlUpdate(SizeCtl* me);
335 static PdmOid SizeCtlGetSize(SizeCtl* me);
336 static void SizeCtlResizeCB(Widget w,
337 XtPointer client_data, XtPointer call_data);
338 static void SizeCtlSetSingleSizeMode(SizeCtl* me, PdmOid size);
339 static void SizeCtlSetMultiSizeMode(SizeCtl* me);
340 static void SizeCtlReadyChangedCB(Widget w,
341 XtPointer client_data, XtPointer call_data);
342 static void SizeCtlSupportedChangedCB(Widget w,
343 XtPointer client_data,
344 XtPointer call_data);
345 static void SizeCtlSelectCB(Widget w,
346 XtPointer client_data,
347 XtPointer call_data);
349 * pixmap list functions
351 static PdmPixmapList* PdmPixmapListNew(int count, Widget w, Boolean stipple);
352 static void PdmPixmapListDelete(PdmPixmapList* me);
353 static Pixmap PdmPixmapListGetPixmap(PdmPixmapList* me, int i);
354 #define PdmPixmapListCount(me) ((me)->count)
355 static void PdmPixmapListSetImageName(PdmPixmapList* me,
360 * option menu list creation function
363 CreateOptionMenuPulldown(String pulldown_name,
365 XtCallbackProc activate_proc,
371 * XmString / oid utilities
373 static XmString* CreateXmStringsFromOidList(const PdmOidList* list);
374 static void FreeXmStringList(XmString* list, int count);
377 * utility to help determine maximum icon size
380 IconMaxDimension(Widget icon_label,
381 PdmPixmapList* pixmap_list, int i,
382 Dimension* max_width, Dimension* max_height);
385 * utility to position list box initial selection
387 static void SetListBoxSelection(Widget list_box, int position);
390 * utility to grab icon file names out of the Xrm resource database
392 static String GetIconFileName(Widget w, String resource_name);
395 * ------------------------------------------------------------------------
396 * Name: PdmPrinterBoxNew
400 * Creates a new PdmPrinterBox (PdmSetupBox) instance structure.
404 * The new PdmPrinterBox instance structure.
408 PdmPrinterBoxNew(void)
410 PdmSetupBox* me = (PdmSetupBox*)XtCalloc(1, sizeof(PdmSetupBox));
411 PdmPrinterBoxData* data;
413 me->delete_proc = PdmPrinterBoxDelete;
414 me->create_proc = PdmPrinterBoxCreate;
415 me->verify_attr_proc = PdmPrinterBoxVerifyAttr;
416 me->get_attr_proc = PdmPrinterBoxGetAttr;
417 me->set_attr_proc = PdmPrinterBoxSetAttr;
418 me->fallback_resources = PdmPrinterBoxFallbackResources;
419 me->fallback_resources_count = XtNumber(PdmPrinterBoxFallbackResources);
420 me->tab_name = "PrinterTab";
422 me->subclass_data = (XtPointer)XtCalloc(1, sizeof(PdmPrinterBoxData));
423 data = (PdmPrinterBoxData*)me->subclass_data;
425 data->plex_ctl = PlexCtlNew();
426 data->orient_ctl = OrientCtlNew(data->plex_ctl);
428 data->size_ctl = SizeCtlNew();
429 data->tray_ctl = TrayCtlNew(data->size_ctl);
435 * ------------------------------------------------------------------------
436 * Name: PdmPrinterBoxDelete
440 * Frees the passed PdmPrinterBox (PdmSetupBox) instance structure.
448 PdmPrinterBoxDelete(PdmSetupBox* me)
450 if(me != (PdmSetupBox*)NULL)
452 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
454 XtFree(data->document_format);
456 PdmOidListDelete(data->document_attrs_supported);
457 PdmOidListDelete(data->orientations_supported);
458 PdmOidListDelete(data->plexes_supported);
459 PdmOidListDelete(data->input_trays);
460 PdmOidListDelete(data->tray_sizes);
461 PdmOidLinkedListDelete(data->sizes_supported);
463 OrientCtlDelete(data->orient_ctl);
464 PlexCtlDelete(data->plex_ctl);
465 SizeCtlDelete(data->size_ctl);
466 TrayCtlDelete(data->tray_ctl);
474 * ------------------------------------------------------------------------
475 * Name: PdmPrinterBoxCreate
479 * Creates the PDM Printer options setup box.
483 * The passed PdmPrinterBox (PdmSetupBox) instance structure.
487 PdmPrinterBoxCreate(PdmSetupBox* me, Widget parent)
489 me->widget = PdmPrinterBoxCreateWindow(me, parent);
490 XtManageChild(me->widget);
494 * ------------------------------------------------------------------------
495 * Name: PdmPrinterBoxVerifyAttr
503 * PDM_SUCCESS if all of the Printer options selected are OK.
505 * PDM_FAILURE if any of the Printer options are invalid.
509 PdmPrinterBoxVerifyAttr(PdmSetupBox* me, PdmXp* pdm_xp)
515 * ------------------------------------------------------------------------
516 * Name: PdmPrinterBoxGetAttr
528 PdmPrinterBoxGetAttr(PdmSetupBox* me, PdmXp* pdm_xp)
530 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
532 PdmOidMediumSS* medium_ss_supported;
533 PdmOidTrayMediumList* input_trays_medium = NULL;
534 #if 0 && defined(PRINTING_SUPPORTED)
536 * printer model description
538 data->printer_model =
539 PdmXpGetStringValue(pdm_xp, XPPrinterAttr, pdmoid_att_printer_model);
543 strval = PdmXpGetStringValue(pdm_xp, XPDocAttr,
544 pdmoid_att_document_format);
545 data->document_format = PdmOidDocumentFormatParse(strval);
546 #endif /* PRINTING_SUPPORTED */
547 if((char*)NULL == data->document_format)
550 * document format not specified, try to obtain
551 * document-formats-supported, and obtain up the default from it
553 #if 0 && defined(PRINTING_SUPPORTED)
554 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
555 pdmoid_att_document_formats_supported);
556 data->document_format = PdmOidDocumentFormatDefault(strval);
557 #endif /* PRINTING_SUPPORTED */
560 * document attributes supported
562 #if 0 && defined(PRINTING_SUPPORTED)
563 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
564 pdmoid_att_document_attributes_supported);
565 data->document_attrs_supported = PdmOidListNew(strval);
567 * content orientation supported
569 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
570 pdmoid_att_content_orientations_supported);
571 data->orientations_supported = PdmOidListNew(strval);
576 PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_content_orientation);
580 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
581 pdmoid_att_plexes_supported);
582 data->plexes_supported = PdmOidListNew(strval);
586 data->plex = PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_plex);
588 * default input tray, default medium
590 data->default_input_tray =
591 PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_default_input_tray);
592 data->default_medium =
593 PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_default_medium);
595 * medium source sizes supported
597 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
598 pdmoid_att_medium_source_sizes_supported);
599 medium_ss_supported = PdmOidMediumSSNew(strval);
603 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
604 pdmoid_att_input_trays_medium);
605 input_trays_medium = PdmOidTrayMediumListNew(strval);
607 * build input trays and page sizes ready lists
609 PdmOidMediumSSGetTraysSizes(medium_ss_supported, input_trays_medium,
610 &data->input_trays, &data->tray_sizes);
612 * build list of supported page sizes
614 data->sizes_supported = PdmOidMediumSSGetAllSizes(medium_ss_supported);
618 PdmOidMediumSSDelete(medium_ss_supported);
619 PdmOidTrayMediumListDelete(input_trays_medium);
620 #endif /* PRINTING_SUPPORTED */
624 * ------------------------------------------------------------------------
625 * Name: PdmPrinterBoxSetAttr
637 PdmPrinterBoxSetAttr(PdmSetupBox* me, PdmXp* pdm_xp)
639 #if 0 && defined(PRINTING_SUPPORTED)
640 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
644 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_content_orientation,
645 OrientCtlGetOrientation(data->orient_ctl));
649 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_plex,
650 PlexCtlGetPlex(data->plex_ctl));
654 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_default_medium,
655 SizeCtlGetSize(data->size_ctl));
659 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_default_input_tray,
660 TrayCtlGetTray(data->tray_ctl));
661 #endif /* PRINTING_SUPPORTED */
665 * ------------------------------------------------------------------------
666 * Name: PdmPrinterBoxCreateWindow
670 * Creates the PDM Printer options setup box window.
674 * Widget ID of the new Printer setup box.
678 PdmPrinterBoxCreateWindow(PdmSetupBox* me, Widget parent)
680 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
687 * create the manager for the Printer Setup Box
689 manager = XtVaCreateManagedWidget(
691 xmRowColumnWidgetClass,
695 * create the printer model row
697 if(data->printer_model != (const char*)NULL)
702 row = XtVaCreateManagedWidget(
704 xmRowColumnWidgetClass,
706 XmNorientation, XmHORIZONTAL,
709 * create the printer model label
711 w = XtVaCreateManagedWidget("PrinterModelLabel",
716 * create the printer model using just the 1st line
718 desc = XtNewString(data->printer_model);
719 ptr = Dt_strchr(desc, '\n');
722 label = XmStringCreateLocalized(desc);
724 w = XtVaCreateManagedWidget("PrinterModel",
727 XmNlabelString, label,
732 * create the document format row
734 if((char*)NULL != data->document_format)
737 * create the document format row
739 row = XtVaCreateManagedWidget(
741 xmRowColumnWidgetClass,
743 XmNorientation, XmHORIZONTAL,
746 * create the document format label
748 w = XtVaCreateManagedWidget("DocumentFormatLabel",
753 * create the document format
755 label = XmStringCreateLocalized(data->document_format);
756 w = XtVaCreateManagedWidget("DocumentFormat",
759 XmNlabelString, label,
764 * orientation / plex / tray / sides
766 draw_area = XtVaCreateWidget("PrinterSetupControls",
767 xmDrawingAreaWidgetClass,
770 XtAddCallback(draw_area, XmNresizeCallback,
771 PdmPrinterBoxResizeCB, (XtPointer)me);
773 * orientation control
775 OrientCtlCreate(data->orient_ctl,
778 data->document_attrs_supported,
779 data->orientations_supported);
783 SizeCtlCreate(data->size_ctl,
785 data->default_medium,
786 data->document_attrs_supported,
788 data->sizes_supported);
792 PlexCtlCreate(data->plex_ctl,
795 data->document_attrs_supported,
796 data->plexes_supported);
800 TrayCtlCreate(data->tray_ctl,
802 data->default_input_tray,
803 data->default_medium,
804 data->document_attrs_supported,
808 XtManageChild(draw_area);
810 * return the new Printer Setup Box
816 * ------------------------------------------------------------------------
817 * Name: PdmPrinterBoxResizeCB
829 PdmPrinterBoxResizeCB(Widget w,
830 XtPointer client_data,
833 PdmSetupBox* me = (PdmSetupBox*)client_data;
834 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
836 XtArgVal /* Position */ x, y;
837 XtArgVal /* Dimension */ width, height;
839 PdmRect rt, rs, ro, rp, c1, c2, r1, r2;
841 * retrieve child dimensions
843 XtVaGetValues(TrayCtlGetWidget(data->tray_ctl),
847 XmNheight, &rt.height,
849 XtVaGetValues(SizeCtlGetWidget(data->size_ctl),
853 XmNheight, &rs.height,
855 XtVaGetValues(OrientCtlGetWidget(data->orient_ctl),
859 XmNheight, &ro.height,
861 XtVaGetValues(PlexCtlGetWidget(data->plex_ctl),
865 XmNheight, &rp.height,
868 * calculate rows and columns dimensions
870 r1.x = r2.x = c1.x = 0;
871 r1.y = c1.y = c2.y = 0;
872 r1.height = MAX(ro.height, rp.height);
873 r2.height = MAX(rs.height, rt.height);
874 c1.width = MAX(ro.width, rs.width);
875 c2.width = MAX(rp.width, rt.width);
876 r2.y = r1.height + 5;
878 r1.width = r2.width = c2.x + c2.width;
879 c1.height = c2.height = r2.y + r2.height;
881 * position the children
883 XtVaSetValues(OrientCtlGetWidget(data->orient_ctl),
887 XmNheight, r1.height,
889 XtVaSetValues(PlexCtlGetWidget(data->plex_ctl),
893 XmNheight, r1.height,
895 XtVaSetValues(SizeCtlGetWidget(data->size_ctl),
899 XmNheight, r2.height,
901 XtVaSetValues(TrayCtlGetWidget(data->tray_ctl),
905 XmNheight, r2.height,
908 * resize the drawing area to accommodate the new layout
912 XmNheight, c1.height,
917 * ------------------------------------------------------------------------
930 OrientCtlNew(PlexCtl* plex_ctl)
932 OrientCtl* me = (OrientCtl*)XtCalloc(1, sizeof(OrientCtl));
933 me->plex_ctl = plex_ctl;
938 * ------------------------------------------------------------------------
939 * Name: OrientCtlDelete
951 OrientCtlDelete(OrientCtl* me)
953 PdmOidListDelete(me->dummy_orientations_supported);
954 PdmPixmapListDelete(me->pixmap_list);
955 PdmPixmapListDelete(me->i_pixmap_list);
961 * ------------------------------------------------------------------------
962 * Name: OrientCtlCreate
974 OrientCtlCreate(OrientCtl* me,
977 const PdmOidList* document_attrs_supported,
978 const PdmOidList* orientations_supported)
982 * determine if setting the content orientation is supported
984 if(PdmOidListHasOid(document_attrs_supported,
985 pdmoid_att_content_orientation)
987 PdmOidListCount(orientations_supported) > 0)
990 me->orientations_supported = orientations_supported;
996 * dummy up a list to be presented (insensitive)
998 me->dummy_orientations_supported =
999 PdmOidListNew(PdmOidString(pdmoid_val_content_orientation_portrait));
1000 me->orientations_supported = me->dummy_orientations_supported;
1001 orientation = pdmoid_none;
1004 * set the initially selected list item
1006 OrientCtlSetSelectedItem(me,
1007 PdmOidListGetIndex(me->orientations_supported,
1010 * create the orientations control window
1012 OrientCtlCreateWindow(me, parent);
1014 * initialize the window components
1016 OrientCtlCreatePulldown(me);
1017 OrientCtlInitPixmapList(me);
1018 OrientCtlUpdateIcon(me);
1020 * if content-orientation is not supported, disable the control
1023 OrientCtlDisable(me);
1027 * ------------------------------------------------------------------------
1028 * Name: OrientCtlCreateWindow
1040 OrientCtlCreateWindow(OrientCtl* me,
1043 Widget control_manager;
1048 me->widget = XtVaCreateManagedWidget("OrientCtlTop",
1051 XmNshadowType, XmSHADOW_ETCHED_IN,
1057 XtVaCreateManagedWidget("OrientationLabel",
1060 XmNframeChildType, XmFRAME_TITLE_CHILD,
1063 * orientation controls manager
1066 XtVaCreateManagedWidget("OrientationControls",
1067 xmDrawingAreaWidgetClass,
1069 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
1071 XtAddCallback(control_manager, XmNresizeCallback, OrientCtlResizeCB, me);
1073 * orientations option menu
1076 XtVaCreateManagedWidget("OrientationOptionMenu",
1077 xmRowColumnWidgetClass,
1080 XmNrowColumnType, XmMENU_OPTION,
1086 XtVaCreateManagedWidget("OrientationIcon",
1089 XmNlabelType, XmPIXMAP,
1090 XmNalignment, XmALIGNMENT_CENTER,
1095 * ------------------------------------------------------------------------
1096 * Name: OrientCtlDisable
1100 * Disable the orientation controls.
1108 OrientCtlDisable(OrientCtl* me)
1110 XtSetSensitive(me->frame_label, False);
1111 XtSetSensitive(me->option_menu, False);
1112 XtSetSensitive(me->icon_label, False);
1116 * ------------------------------------------------------------------------
1117 * Name: OrientCtlResizeCB
1129 OrientCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
1131 OrientCtl* me = (OrientCtl*)client_data;
1132 XtArgVal /* Dimension */ height, width, margin_width, new_width;
1133 XtArgVal /* Position */ menu_x, menu_y, icon_x, icon_y;
1134 XtArgVal /* Dimension */ menu_h, menu_w, icon_h, icon_w;
1136 * get current layout info
1138 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
1139 XmNmarginWidth, &margin_width,
1141 XtVaGetValues(me->option_menu, XmNheight, &menu_h, XmNwidth, &menu_w,
1143 XtVaGetValues(me->icon_label, XmNheight, &icon_h, XmNwidth, &icon_w,
1146 * position controls side by side
1149 icon_x = menu_x + menu_w;
1153 menu_y = (height - menu_h) / 2;
1154 icon_y = (height - icon_h) / 2;
1158 XtVaSetValues(me->option_menu, XmNx, menu_x, XmNy, menu_y, NULL);
1159 XtVaSetValues(me->icon_label, XmNx, icon_x, XmNy, icon_y, NULL);
1161 * update drawing area width
1163 new_width = menu_x + menu_w + icon_w + margin_width;
1164 if(new_width > width)
1165 XtVaSetValues(w, XmNwidth, new_width, NULL);
1169 * ------------------------------------------------------------------------
1170 * Name: OrientCtlCreatePulldown
1182 OrientCtlCreatePulldown(OrientCtl* me)
1187 * create a list of XmStrings for the content orientations
1189 list = CreateXmStringsFromOidList(me->orientations_supported);
1191 * create the option menu pulldown
1193 count = PdmOidListCount(me->orientations_supported);
1194 CreateOptionMenuPulldown("OrientationOptions",
1203 FreeXmStringList(list, count);
1207 * ------------------------------------------------------------------------
1208 * Name: OrientCtlSelectCB
1220 OrientCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
1223 XtArgVal /* int */ selected_item = (XtArgVal)client_data;
1225 XtVaGetValues(w, XmNuserData, &me, NULL);
1226 OrientCtlSetSelectedItem(me, selected_item);
1227 OrientCtlUpdateIcon(me);
1231 * ------------------------------------------------------------------------
1232 * Name: OrientCtlInitPixmapList
1244 OrientCtlInitPixmapList(OrientCtl* me)
1247 const char* image_name;
1249 Dimension max_width = 0;
1250 Dimension max_height = 0;
1253 * initialize the list of pixmaps based on the supported orientations
1255 count = PdmOidListCount(me->orientations_supported);
1256 me->pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
1257 me->i_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
1258 for(i = 0; i < count; i++)
1260 switch(PdmOidListGetOid(me->orientations_supported, i))
1262 case pdmoid_val_content_orientation_portrait:
1263 image_name = GetIconFileName(me->widget, "PortraitIconFileName");
1265 case pdmoid_val_content_orientation_landscape:
1266 image_name = GetIconFileName(me->widget, "LandscapeIconFileName");
1268 case pdmoid_val_content_orientation_reverse_portrait:
1270 GetIconFileName(me->widget, "ReversePortraitIconFileName");
1272 case pdmoid_val_content_orientation_reverse_landscape:
1274 GetIconFileName(me->widget, "ReverseLandscapeIconFileName");
1279 PdmPixmapListSetImageName(me->pixmap_list, image_name, i);
1280 PdmPixmapListSetImageName(me->i_pixmap_list, image_name, i);
1281 IconMaxDimension(me->icon_label,
1283 &max_width, &max_height);
1285 XtVaSetValues(me->icon_label,
1286 XmNwidth, max_width,
1287 XmNheight, max_height,
1288 XmNrecomputeSize, False,
1293 * ------------------------------------------------------------------------
1294 * Name: OrientCtlSetSelectedItem
1306 OrientCtlSetSelectedItem(OrientCtl* me, int selected_item)
1308 if(selected_item == -1)
1309 me->selected_item = 0;
1311 me->selected_item = selected_item;
1313 if(me->plex_ctl != (PlexCtl*)NULL)
1314 PlexCtlSetOrientation(me->plex_ctl, OrientCtlGetOrientation(me));
1319 * ------------------------------------------------------------------------
1320 * Name: OrientCtlUpdateIcon
1332 OrientCtlUpdateIcon(OrientCtl* me)
1334 if(me->icon_label != (Widget)NULL)
1335 XtVaSetValues(me->icon_label,
1337 PdmPixmapListGetPixmap(me->pixmap_list,
1339 XmNlabelInsensitivePixmap,
1340 PdmPixmapListGetPixmap(me->i_pixmap_list,
1346 * ------------------------------------------------------------------------
1347 * Name: OrientCtlGetOrientation
1359 OrientCtlGetOrientation(OrientCtl* me)
1361 if(me->orientations_supported == me->dummy_orientations_supported)
1364 return PdmOidListGetOid(me->orientations_supported, me->selected_item);
1369 * ------------------------------------------------------------------------
1384 PlexCtl* me = (PlexCtl*)XtCalloc(1, sizeof(PlexCtl));
1385 me->pixmap_list_ptr = &me->portrait_pixmap_list;
1386 me->i_pixmap_list_ptr = &me->i_portrait_pixmap_list;
1391 * ------------------------------------------------------------------------
1392 * Name: PlexCtlDelete
1404 PlexCtlDelete(PlexCtl* me)
1406 PdmOidListDelete(me->dummy_plexes_supported);
1407 PdmPixmapListDelete(me->portrait_pixmap_list);
1408 PdmPixmapListDelete(me->i_portrait_pixmap_list);
1409 PdmPixmapListDelete(me->landscape_pixmap_list);
1410 PdmPixmapListDelete(me->i_landscape_pixmap_list);
1416 * ------------------------------------------------------------------------
1417 * Name: PlexCtlCreate
1429 PlexCtlCreate(PlexCtl* me,
1432 const PdmOidList* document_attrs_supported,
1433 const PdmOidList* plexes_supported)
1437 * determine if setting the content orientation is supported
1439 if(PdmOidListHasOid(document_attrs_supported, pdmoid_att_plex)
1441 PdmOidListCount(plexes_supported) > 0)
1444 me->plexes_supported = plexes_supported;
1450 * dummy up a list to be presented (insensitive)
1452 me->dummy_plexes_supported =
1453 PdmOidListNew(PdmOidString(pdmoid_val_plex_simplex));
1454 me->plexes_supported = me->dummy_plexes_supported;
1459 * set the initially selected list item
1461 PlexCtlSetSelectedItem(me, PdmOidListGetIndex(me->plexes_supported, plex));
1463 * create the plexes control window
1465 PlexCtlCreateWindow(me, parent);
1467 * initialize the window components
1469 PlexCtlCreatePulldown(me);
1470 PlexCtlInitPixmapLists(me);
1471 PlexCtlUpdateIcon(me);
1473 * if plex is not supported, disable the control
1480 * ------------------------------------------------------------------------
1481 * Name: PlexCtlCreateWindow
1493 PlexCtlCreateWindow(PlexCtl* me,
1496 Widget control_manager;
1500 me->widget = XtVaCreateManagedWidget("PlexCtlTop",
1503 XmNshadowType, XmSHADOW_ETCHED_IN,
1509 XtVaCreateManagedWidget("PlexLabel",
1512 XmNframeChildType, XmFRAME_TITLE_CHILD,
1515 * plex controls manager
1518 XtVaCreateManagedWidget(
1520 xmDrawingAreaWidgetClass,
1522 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
1524 XtAddCallback(control_manager, XmNresizeCallback, PlexCtlResizeCB, me);
1526 * plexes option menu
1529 XtVaCreateManagedWidget("PlexOptionMenu",
1530 xmRowColumnWidgetClass,
1532 XmNrowColumnType, XmMENU_OPTION,
1539 XtVaCreateManagedWidget("PlexIcon",
1542 XmNlabelType, XmPIXMAP,
1543 XmNalignment, XmALIGNMENT_CENTER,
1548 * ------------------------------------------------------------------------
1549 * Name: PlexCtlDisable
1553 * Disable the plex controls.
1561 PlexCtlDisable(PlexCtl* me)
1563 XtSetSensitive(me->frame_label, False);
1564 XtSetSensitive(me->option_menu, False);
1565 XtSetSensitive(me->icon_label, False);
1569 * ------------------------------------------------------------------------
1570 * Name: PlexCtlResizeCB
1582 PlexCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
1584 PlexCtl* me = (PlexCtl*)client_data;
1585 XtArgVal /* Dimension */ height, width, margin_width, new_width;
1586 XtArgVal /* Position */ menu_x, menu_y, icon_x, icon_y;
1587 XtArgVal /* Dimension */ menu_h, menu_w, icon_h, icon_w;
1589 * get current layout info
1591 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
1592 XmNmarginWidth, &margin_width,
1594 XtVaGetValues(me->option_menu, XmNheight, &menu_h, XmNwidth, &menu_w,
1596 XtVaGetValues(me->icon_label, XmNheight, &icon_h, XmNwidth, &icon_w,
1599 * position controls side by side
1602 icon_x = menu_x + menu_w;
1606 menu_y = (height - menu_h) / 2;
1607 icon_y = (height - icon_h) / 2;
1611 XtVaSetValues(me->option_menu, XmNx, menu_x, XmNy, menu_y, NULL);
1612 XtVaSetValues(me->icon_label, XmNx, icon_x, XmNy, icon_y, NULL);
1614 * update drawing area width
1616 new_width = menu_x + menu_w + icon_w + margin_width;
1617 if(new_width > width)
1618 XtVaSetValues(w, XmNwidth, new_width, NULL);
1622 * ------------------------------------------------------------------------
1623 * Name: PlexCtlCreatePulldown
1635 PlexCtlCreatePulldown(PlexCtl* me)
1640 * build a list of Xm strings for the supported plexes
1642 list = CreateXmStringsFromOidList(me->plexes_supported);
1644 * create the option menu pulldown
1646 count = PdmOidListCount(me->plexes_supported);
1647 CreateOptionMenuPulldown("PlexOptions",
1656 FreeXmStringList(list, count);
1660 * ------------------------------------------------------------------------
1661 * Name: PlexCtlSelectCB
1673 PlexCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
1676 XtArgVal /* int */ selected_item = (XtArgVal)client_data;
1678 XtVaGetValues(w, XmNuserData, &me, NULL);
1679 PlexCtlSetSelectedItem(me, selected_item);
1680 PlexCtlUpdateIcon(me);
1684 * ------------------------------------------------------------------------
1685 * Name: PlexCtlSetOrientation
1697 PlexCtlSetOrientation(PlexCtl* me,
1702 case pdmoid_val_content_orientation_landscape:
1703 case pdmoid_val_content_orientation_reverse_landscape:
1704 me->pixmap_list_ptr = &me->landscape_pixmap_list;
1705 me->i_pixmap_list_ptr = &me->i_landscape_pixmap_list;
1708 me->pixmap_list_ptr = &me->portrait_pixmap_list;
1709 me->i_pixmap_list_ptr = &me->i_portrait_pixmap_list;
1712 PlexCtlUpdateIcon(me);
1716 * ------------------------------------------------------------------------
1717 * Name: PlexCtlInitPixmapLists
1729 PlexCtlInitPixmapLists(PlexCtl* me)
1732 const char* portrait_image_name;
1733 const char* landscape_image_name;
1735 Dimension max_width = 0;
1736 Dimension max_height = 0;
1739 * initialize the list of pixmaps based on the list of plexes
1741 count = PdmOidListCount(me->plexes_supported);
1742 me->portrait_pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
1743 me->i_portrait_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
1744 me->landscape_pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
1745 me->i_landscape_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
1746 for(i = 0; i < count; i++)
1748 switch(PdmOidListGetOid(me->plexes_supported, i))
1750 case pdmoid_val_plex_simplex:
1751 portrait_image_name =
1752 GetIconFileName(me->widget, "SimplexPortraitIconFileName");
1753 landscape_image_name =
1754 GetIconFileName(me->widget, "SimplexLandscapeIconFileName");
1756 case pdmoid_val_plex_duplex:
1757 portrait_image_name =
1758 GetIconFileName(me->widget, "DuplexPortraitIconFileName");
1759 landscape_image_name =
1760 GetIconFileName(me->widget, "DuplexLandscapeIconFileName");
1762 case pdmoid_val_plex_tumble:
1763 portrait_image_name =
1764 GetIconFileName(me->widget, "TumblePortraitIconFileName");
1765 landscape_image_name =
1766 GetIconFileName(me->widget, "TumbleLandscapeIconFileName");
1771 PdmPixmapListSetImageName(me->portrait_pixmap_list,
1772 portrait_image_name, i);
1773 PdmPixmapListSetImageName(me->i_portrait_pixmap_list,
1774 portrait_image_name, i);
1775 PdmPixmapListSetImageName(me->landscape_pixmap_list,
1776 landscape_image_name, i);
1777 PdmPixmapListSetImageName(me->i_landscape_pixmap_list,
1778 landscape_image_name, i);
1779 IconMaxDimension(me->icon_label,
1780 me->portrait_pixmap_list, i,
1781 &max_width, &max_height);
1782 IconMaxDimension(me->icon_label,
1783 me->landscape_pixmap_list, i,
1784 &max_width, &max_height);
1786 XtVaSetValues(me->icon_label,
1787 XmNwidth, max_width,
1788 XmNheight, max_height,
1789 XmNrecomputeSize, False,
1794 * ------------------------------------------------------------------------
1795 * Name: PlexCtlSetSelectedItem
1807 PlexCtlSetSelectedItem(PlexCtl* me, int selected_item)
1809 if(selected_item == -1)
1810 me->selected_item = 0;
1812 me->selected_item = selected_item;
1816 * ------------------------------------------------------------------------
1817 * Name: PlexCtlUpdateIcon
1829 PlexCtlUpdateIcon(PlexCtl* me)
1831 if(me->icon_label != (Widget)NULL)
1832 XtVaSetValues(me->icon_label,
1834 PdmPixmapListGetPixmap(*me->pixmap_list_ptr,
1836 XmNlabelInsensitivePixmap,
1837 PdmPixmapListGetPixmap(*me->i_pixmap_list_ptr,
1843 * ------------------------------------------------------------------------
1844 * Name: PlexCtlGetPlex
1856 PlexCtlGetPlex(PlexCtl* me)
1858 if(me->plexes_supported == me->dummy_plexes_supported)
1861 return PdmOidListGetOid(me->plexes_supported, me->selected_item);
1865 * ------------------------------------------------------------------------
1878 TrayCtlNew(SizeCtl* size_ctl)
1880 TrayCtl* me = (TrayCtl*)XtCalloc(1, sizeof(TrayCtl));
1882 me->size_ctl = size_ctl;
1888 * ------------------------------------------------------------------------
1889 * Name: TrayCtlDelete
1901 TrayCtlDelete(TrayCtl* me)
1907 * ------------------------------------------------------------------------
1908 * Name: TrayCtlCreate
1920 TrayCtlCreate(TrayCtl* me,
1922 PdmOid default_input_tray,
1923 PdmOid default_medium,
1924 const PdmOidList* document_attrs_supported,
1925 const PdmOidList* input_trays,
1926 const PdmOidList* tray_sizes)
1930 * save the trays and sizes list pointers
1932 me->input_trays = input_trays;
1933 me->tray_sizes = tray_sizes;
1935 * determine if setting the input tray is supported
1937 if(PdmOidListHasOid(document_attrs_supported,
1938 pdmoid_att_default_input_tray)
1940 PdmOidListCount(me->input_trays) > 0)
1947 * set the initially selected list item
1949 if(default_medium != pdmoid_none)
1952 * default-medium has precedence; set "Auto-select" (index 0)
1954 TrayCtlSetSelectedItem(me, 0);
1958 int i = PdmOidListGetIndex(me->input_trays, default_input_tray);
1959 if(!supported || i == -1)
1961 * default-input-tray unsupported or not found in list; set
1962 * "Auto-select" (index 0)
1964 TrayCtlSetSelectedItem(me, 0);
1967 * Select the list item corresponding to default-input-tray -
1968 * ie. add 1 to the input trays list index since the option
1969 * menu is always built with "Auto-select" as the first
1970 * entry, followed by the input trays list entries.
1972 TrayCtlSetSelectedItem(me, i+1);
1975 * create the tray control window
1977 TrayCtlCreateWindow(me, parent);
1979 * initialize the window components
1981 TrayCtlCreatePulldown(me);
1983 * if tray selection is not supported, disable the control
1990 * ------------------------------------------------------------------------
1991 * Name: TrayCtlCreateWindow
2003 TrayCtlCreateWindow(TrayCtl* me, Widget parent)
2005 Widget control_manager;
2010 me->widget = XtVaCreateManagedWidget("TrayCtlTop",
2013 XmNshadowType, XmSHADOW_ETCHED_IN,
2019 = XtVaCreateManagedWidget("TrayLabel",
2022 XmNframeChildType, XmFRAME_TITLE_CHILD,
2025 * tray controls manager
2028 XtVaCreateManagedWidget("TrayControls",
2029 xmDrawingAreaWidgetClass,
2031 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
2033 XtAddCallback(control_manager, XmNresizeCallback, TrayCtlResizeCB, me);
2038 XtVaCreateManagedWidget("TrayOptionMenu",
2039 xmRowColumnWidgetClass,
2042 XmNrowColumnType, XmMENU_OPTION,
2047 * ------------------------------------------------------------------------
2048 * Name: TrayCtlDisable
2052 * Disable the input tray controls.
2060 TrayCtlDisable(TrayCtl* me)
2062 XtSetSensitive(me->frame_label, False);
2063 XtSetSensitive(me->option_menu, False);
2067 * ------------------------------------------------------------------------
2068 * Name: TrayCtlResizeCB
2080 TrayCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
2082 TrayCtl* me = (TrayCtl*)client_data;
2083 XtArgVal /* Dimension */ height, menu_h;
2084 XtArgVal /* Position */ menu_y;
2086 * get current layout info
2088 XtVaGetValues(w, XmNheight, &height, NULL);
2089 XtVaGetValues(me->option_menu, XmNheight, &menu_h, NULL);
2093 menu_y = (height - menu_h) / 2;
2097 XtVaSetValues(me->option_menu, XmNx, 0, XmNy, menu_y, NULL);
2101 * ------------------------------------------------------------------------
2102 * Name: TrayCtlGetTray
2114 TrayCtlGetTray(TrayCtl* me)
2116 if(me->selected_item == 0)
2119 return PdmOidListGetOid(me->input_trays, me->selected_item - 1);
2123 * ------------------------------------------------------------------------
2124 * Name: TrayCtlCreatePulldown
2136 TrayCtlCreatePulldown(TrayCtl* me)
2138 XmString* xmstr_list;
2144 * create a list of XmStrings for the Auto-select item plus the list
2147 count = 1 + PdmOidListCount(me->input_trays);
2148 xmstr_list = (XmString*)XtCalloc(count, sizeof(XmString));
2150 * set the "Auto-select" item as the first item
2153 xmstr_list[i++] = XmStringCreateLocalized((char*)PDM_MSG_TRAY_AUTO_SELECT);
2155 * add the input trays
2157 for(; i < count; i++)
2159 oid = PdmOidListGetOid(me->input_trays, i-1);
2160 str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
2162 PdmOidDefaultMsg(oid));
2163 xmstr_list[i] = XmStringCreateLocalized((char*)str);
2166 * create the option menu pulldown
2168 CreateOptionMenuPulldown("TrayOptions",
2177 FreeXmStringList(xmstr_list, count);
2181 * ------------------------------------------------------------------------
2182 * Name: TrayCtlSetSelectedItem
2194 TrayCtlSetSelectedItem(TrayCtl* me, int selected_item)
2196 if(selected_item == -1)
2197 me->selected_item = 0;
2199 me->selected_item = selected_item;
2201 * update the page size control accordingly
2203 if(me->selected_item == 0)
2204 SizeCtlSetMultiSizeMode(me->size_ctl);
2206 SizeCtlSetSingleSizeMode(me->size_ctl,
2207 PdmOidListGetOid(me->tray_sizes,
2208 me->selected_item - 1));
2212 * ------------------------------------------------------------------------
2213 * Name: TrayCtlSelectCB
2225 TrayCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
2228 XtArgVal /* int */ selected_item = (XtArgVal)client_data;
2230 XtVaGetValues(w, XmNuserData, &me, NULL);
2231 TrayCtlSetSelectedItem(me, selected_item);
2236 * ------------------------------------------------------------------------
2251 SizeCtl* me = (SizeCtl*)XtCalloc(1, sizeof(SizeCtl));
2256 * ------------------------------------------------------------------------
2257 * Name: SizeCtlDelete
2269 SizeCtlDelete(SizeCtl* me)
2271 if(me != (SizeCtl*)NULL)
2273 if(me->sizes_ready_xmstr != (XmString*)NULL)
2274 FreeXmStringList(me->sizes_ready_xmstr,
2275 PdmOidListCount(me->sizes_ready));
2276 if(me->sizes_supported_xmstr != (XmString*)NULL)
2277 FreeXmStringList(me->sizes_supported_xmstr,
2278 PdmOidListCount(me->sizes_supported));
2279 PdmOidListDelete(me->sizes_ready);
2280 PdmOidListDelete(me->sizes_supported);
2286 * ------------------------------------------------------------------------
2287 * Name: SizeCtlStrColl
2291 * An adaptor for using strcoll on SizeCtlSortRec's with qsort.
2295 * The return value for strcoll given the strings in the passed
2300 SizeCtlStrColl(const void* e1, const void* e2)
2302 const SizeCtlSortRec *r1 = e1, *r2 = e2;
2304 return strcoll(r1->str, r2->str);
2308 * ------------------------------------------------------------------------
2309 * Name: SizeCtlSetSizeLists
2313 * Creates a sorted XmStringTable and PdmOidList using
2314 * the oids from the passed PdmOidLinkedList. The newly created lists
2315 * are returned via the 'oids' and 'xmstrs' parms.
2323 SizeCtlSetSizeLists(PdmOidList** oid_list,
2324 XmStringTable* xmstrs,
2325 PdmOidLinkedList* oid_ll)
2329 count = PdmOidLinkedListCount(oid_ll);
2332 *oid_list = (PdmOidList*)NULL;
2333 *xmstrs = (XmStringTable)NULL;
2337 SizeCtlSortList sort_list;
2341 * sort the passed sizes
2343 sort_list = (SizeCtlSortList)XtCalloc(count, sizeof(SizeCtlSortRec));
2344 for(i = 0, oid = PdmOidLinkedListFirstOid(oid_ll);
2346 i++, oid = PdmOidLinkedListNextOid(oid_ll))
2348 sort_list[i].oid = oid;
2349 sort_list[i].str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
2351 PdmOidDefaultMsg(oid));
2353 qsort(sort_list, count, sizeof(SizeCtlSortRec), SizeCtlStrColl);
2355 * create the return lists of oids and XmStrings
2357 *oid_list = (PdmOidList*)XtCalloc(1, sizeof(PdmOidList));
2358 (*oid_list)->list = (PdmOid*)XtCalloc(count, sizeof(PdmOid));
2359 (*oid_list)->count = count;
2360 *xmstrs = (XmStringTable)XtCalloc(count, sizeof(XmString));
2361 for(i = 0; i < count; i++)
2363 ((*oid_list)->list)[i] = sort_list[i].oid;
2364 (*xmstrs)[i] = XmStringCreateLocalized((char*)sort_list[i].str);
2366 XtFree((char*)sort_list);
2371 * ------------------------------------------------------------------------
2372 * Name: SizeCtlCreate
2384 SizeCtlCreate(SizeCtl* me,
2386 PdmOid default_medium,
2387 const PdmOidList* document_attrs_supported,
2388 const PdmOidList* tray_sizes,
2389 PdmOidLinkedList* sizes_supported)
2394 PdmOidLinkedList* sizes_ready_ll;
2396 * initialize the selected size
2398 me->selected_size = default_medium;
2400 * build the sizes ready list using unique elements of the tray sizes
2403 sizes_ready_ll = PdmOidLinkedListNew();
2404 for(i = 0; i < PdmOidListCount(tray_sizes); i++)
2406 oid = PdmOidListGetOid(tray_sizes, i);
2407 if(!PdmOidLinkedListHasOid(sizes_ready_ll, oid))
2409 PdmOidLinkedListAddOid(sizes_ready_ll, oid);
2413 * determine if setting the medium is supported
2415 if(!PdmOidListHasOid(document_attrs_supported,
2416 pdmoid_att_default_medium)
2418 PdmOidLinkedListCount(sizes_supported) == 0)
2420 me->selected_list = SIZECTL_UNSUPPORTED;
2425 * default to the ready list
2427 me->selected_list = SIZECTL_SIZES_READY;
2430 * create the XmString versions of the sizes lists
2432 SizeCtlSetSizeLists(&me->sizes_ready, &me->sizes_ready_xmstr,
2434 PdmOidLinkedListDelete(sizes_ready_ll);
2435 SizeCtlSetSizeLists(&me->sizes_supported, &me->sizes_supported_xmstr,
2438 * create the size control window
2440 SizeCtlCreateWindow(me, parent);
2442 * update the control state
2448 * ------------------------------------------------------------------------
2449 * Name: SizeCtlCreateWindow
2461 SizeCtlCreateWindow(SizeCtl* me, Widget parent)
2465 Widget control_manager;
2467 XmString default_xmstr = (XmString)NULL;
2471 me->widget = XtVaCreateManagedWidget("PageSizeCtlTop",
2474 XmNshadowType, XmSHADOW_ETCHED_IN,
2480 = XtVaCreateManagedWidget("PageSizeLabel",
2483 XmNframeChildType, XmFRAME_TITLE_CHILD,
2487 * page size controls manager
2490 XtVaCreateManagedWidget("PageSizeControls",
2491 xmDrawingAreaWidgetClass,
2493 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
2495 XtAddCallback(control_manager, XmNresizeCallback, SizeCtlResizeCB, me);
2497 * page sizes list box
2500 XtSetArg(args[n], XmNvisibleItemCount, 3); n++;
2501 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); n++;
2502 XtSetArg(args[n], XmNhorizontalScrollBar, NULL); n++;
2504 * set the supported sizes list in the list box, in order to lock
2505 * down the maximum dimensions - the list box does not support
2506 * changes to the list size policy after creation
2508 if(me->selected_list == SIZECTL_UNSUPPORTED)
2511 * unsupported, use "Default"
2514 XmStringCreateLocalized((char*)PDM_MSG_SIZE_DEFAULT);
2515 XtSetArg(args[n], XmNitemCount, 1); n++;
2516 XtSetArg(args[n], XmNitems, &default_xmstr); n++;
2520 XtSetArg(args[n], XmNitems, me->sizes_supported_xmstr); n++;
2521 XtSetArg(args[n], XmNitemCount,
2522 PdmOidListCount(me->sizes_supported)); n++;
2524 XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++;
2526 me->list_box = XmCreateScrolledList(control_manager, "PageSizes", args, n);
2527 if((XmString)NULL != default_xmstr) XmStringFree(default_xmstr);
2528 XtAddCallback(me->list_box, XmNbrowseSelectionCallback,
2529 SizeCtlSelectCB, (XtPointer)me);
2531 * hide the horizontal scroll bar, since the width of the list has
2532 * been set to accommodate the widest item.
2534 hscroll = XtNameToWidget(XtParent(me->list_box), "*HorScrollBar");
2535 XtVaSetValues(hscroll,
2536 XmNmappedWhenManaged, False,
2537 XmNx, 0, XmNy, 0, XmNwidth, 1, XmNheight, 1,
2540 * manage the scrolled list
2542 XtManageChild(me->list_box);
2543 XtManageChild(XtParent(me->list_box));
2545 * loaded / allowed sizes radio buttons
2547 me->radio_box = XtVaCreateWidget(
2549 xmRowColumnWidgetClass,
2551 XmNradioBehavior, True,
2553 me->ready_radio = XtVaCreateManagedWidget("button_0",
2554 xmToggleButtonWidgetClass,
2557 XtAddCallback(me->ready_radio, XmNvalueChangedCallback,
2558 SizeCtlReadyChangedCB, (XtPointer)me);
2559 me->supported_radio = XtVaCreateManagedWidget("button_1",
2560 xmToggleButtonWidgetClass,
2563 XtAddCallback(me->supported_radio, XmNvalueChangedCallback,
2564 SizeCtlSupportedChangedCB, (XtPointer)me);
2566 XtManageChild(me->radio_box);
2570 * ------------------------------------------------------------------------
2571 * Name: SizeCtlUpdate
2575 * Update the state of the size control
2583 SizeCtlUpdate(SizeCtl* me)
2585 Boolean frame_label_sensitive = False;
2586 Boolean list_box_sensitive = False;
2587 Boolean list_box_traverse = False;
2588 Boolean ready_radio_sensitive = False;
2589 Boolean supported_radio_sensitive = False;
2591 * clear the current list
2593 XmListDeleteAllItems(me->list_box);
2595 if(me->single_size_mode)
2598 PdmOid oid = me->selected_size;
2601 XmStringCreateLocalized((char*)
2602 DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
2604 PdmOidDefaultMsg(oid)));
2605 XmListAddItem(me->list_box, item, 0);
2606 XmListSelectPos(me->list_box, 0, False);
2609 if(me->selected_list != SIZECTL_UNSUPPORTED)
2611 frame_label_sensitive = True;
2612 list_box_sensitive = True;
2613 me->selected_list = SIZECTL_SIZES_READY;
2614 XmToggleButtonSetState(me->ready_radio, True, False);
2615 XmToggleButtonSetState(me->supported_radio, False, False);
2620 if(me->selected_list == SIZECTL_UNSUPPORTED)
2622 XmString default_item;
2625 XmStringCreateLocalized((char*)PDM_MSG_SIZE_DEFAULT);
2626 XmListAddItem(me->list_box, default_item, 0);
2627 XmListSelectPos(me->list_box, 0, False);
2628 XmStringFree(default_item);
2636 * set control sensitivities
2638 frame_label_sensitive = True;
2639 supported_radio_sensitive = True;
2640 list_box_sensitive = True;
2641 list_box_traverse = True;
2642 if(PdmOidListCount(me->sizes_ready) > 0)
2643 ready_radio_sensitive = True;
2645 * check to see if the selected size is supported
2647 if(!PdmOidListHasOid(me->sizes_supported, me->selected_size))
2650 * the selected size is not supported
2652 if(PdmOidListCount(me->sizes_ready) > 0)
2655 * use the 1st entry in the ready list
2658 PdmOidListGetOid(me->sizes_ready, 0);
2659 me->selected_list = SIZECTL_SIZES_READY;
2664 * the ready list is empty, use the 1st entry in the
2668 PdmOidListGetOid(me->sizes_supported, 0);
2669 me->selected_list = SIZECTL_SIZES_SUPPORTED;
2672 else if(me->selected_list == SIZECTL_SIZES_READY
2674 !PdmOidListHasOid(me->sizes_ready, me->selected_size))
2677 * the selected size is not in the ready list; use the
2678 * supported list instead
2680 me->selected_list = SIZECTL_SIZES_SUPPORTED;
2683 * set the appropriate radio button and update the list
2685 if(me->selected_list == SIZECTL_SIZES_READY)
2687 XmToggleButtonSetState(me->ready_radio, True, False);
2688 XmToggleButtonSetState(me->supported_radio, False, False);
2690 list = me->sizes_ready_xmstr;
2691 count = PdmOidListCount(me->sizes_ready);
2692 pos = 1 + PdmOidListGetIndex(me->sizes_ready,
2697 XmToggleButtonSetState(me->supported_radio, True, False);
2698 XmToggleButtonSetState(me->ready_radio, False, False);
2700 list = me->sizes_supported_xmstr;
2701 count = PdmOidListCount(me->sizes_supported);
2702 pos = 1 + PdmOidListGetIndex(me->sizes_supported,
2705 XmListAddItemsUnselected(me->list_box, list, count, 0);
2706 SetListBoxSelection(me->list_box, pos);
2710 * update control sensitivities
2712 XtSetSensitive(me->frame_label, frame_label_sensitive);
2713 XtSetSensitive(me->list_box, list_box_sensitive);
2714 XtVaSetValues(me->list_box, XmNtraversalOn, list_box_traverse, NULL);
2715 XtSetSensitive(me->ready_radio, ready_radio_sensitive);
2716 XtSetSensitive(me->supported_radio, supported_radio_sensitive);
2720 * ------------------------------------------------------------------------
2721 * Name: SizeCtlResizeCB
2733 SizeCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
2735 SizeCtl* me = (SizeCtl*)client_data;
2736 XtArgVal /* Dimension */ height, width, margin_width, new_width;
2737 XtArgVal /* Position */ list_x, list_y, radio_x, radio_y;
2738 XtArgVal /* Dimension */ list_h, list_w, radio_h, radio_w;
2739 Widget scrolled_list = XtParent(me->list_box);
2741 * get current layout info
2743 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
2744 XmNmarginWidth, &margin_width,
2746 XtVaGetValues(scrolled_list, XmNheight, &list_h, XmNwidth, &list_w, NULL);
2747 XtVaGetValues(me->radio_box, XmNheight, &radio_h, XmNwidth, &radio_w,
2750 * position controls side by side
2752 list_x = margin_width;
2753 radio_x = list_x + list_w;
2757 list_y = (height - list_h) / 2;
2758 radio_y = (height - radio_h) / 2;
2762 XtVaSetValues(scrolled_list, XmNx, list_x, XmNy, list_y, NULL);
2763 XtVaSetValues(me->radio_box, XmNx, radio_x, XmNy, radio_y, NULL);
2765 * update drawing area width and height
2767 new_width = list_x + list_w + radio_w;
2768 if(new_width > width)
2769 XtVaSetValues(w, XmNwidth, new_width, NULL);
2773 * ------------------------------------------------------------------------
2774 * Name: SizeCtlSetSingleSizeMode
2786 SizeCtlSetSingleSizeMode(SizeCtl* me, PdmOid size)
2788 if(size != pdmoid_none)
2790 me->single_size_mode = True;
2791 me->selected_size = size;
2797 * ------------------------------------------------------------------------
2798 * Name: SizeCtlSetMultiSizeMode
2810 SizeCtlSetMultiSizeMode(SizeCtl* me)
2812 me->single_size_mode = False;
2819 * ------------------------------------------------------------------------
2820 * Name: SizeCtlGetSize
2832 SizeCtlGetSize(SizeCtl* me)
2834 if(me->single_size_mode || me->selected_list == SIZECTL_UNSUPPORTED)
2837 return me->selected_size;
2841 * ------------------------------------------------------------------------
2842 * Name: SizeCtlReadyChangedCB
2854 SizeCtlReadyChangedCB(Widget w,
2855 XtPointer client_data,
2856 XtPointer call_data)
2858 XmToggleButtonCallbackStruct* cbs =
2859 (XmToggleButtonCallbackStruct*)call_data;
2863 SizeCtl* me = (SizeCtl*)client_data;
2864 me->selected_list = SIZECTL_SIZES_READY;
2865 if(!PdmOidListHasOid(me->sizes_ready, me->selected_size))
2866 me->selected_size = pdmoid_none;
2872 * ------------------------------------------------------------------------
2873 * Name: SizeCtlSupportedChangedCB
2885 SizeCtlSupportedChangedCB(Widget w,
2886 XtPointer client_data,
2887 XtPointer call_data)
2889 XmToggleButtonCallbackStruct* cbs =
2890 (XmToggleButtonCallbackStruct*)call_data;
2894 SizeCtl* me = (SizeCtl*)client_data;
2895 me->selected_list = SIZECTL_SIZES_SUPPORTED;
2901 * ------------------------------------------------------------------------
2902 * Name: SizeCtlSelectCB
2914 SizeCtlSelectCB(Widget w,
2915 XtPointer client_data,
2916 XtPointer call_data)
2918 XmListCallbackStruct* cbs = (XmListCallbackStruct*)call_data;
2919 SizeCtl* me = (SizeCtl*)client_data;
2921 if(!me->single_size_mode)
2923 switch(me->selected_list)
2925 case SIZECTL_SIZES_READY:
2927 PdmOidListGetOid(me->sizes_ready, cbs->item_position - 1);
2929 case SIZECTL_SIZES_SUPPORTED:
2931 PdmOidListGetOid(me->sizes_supported, cbs->item_position - 1);
2938 * ------------------------------------------------------------------------
2939 * Name: CreateOptionMenuPulldown
2951 CreateOptionMenuPulldown(String pulldown_name,
2953 XtCallbackProc activate_proc,
2954 XtPointer user_data,
2955 XmString* item_list,
2959 Widget cascade_button;
2961 Widget initial_selected = (Widget)NULL;
2963 char button_name[48];
2967 XmCreatePulldownMenu(XtParent(option_menu), pulldown_name, NULL, 0);
2969 for(i = 0; i < item_count; i++)
2971 sprintf(button_name, "button_%d", i);
2972 button = XtVaCreateManagedWidget(button_name,
2973 xmPushButtonGadgetClass,
2975 XmNuserData, user_data,
2976 XmNlabelString, item_list[i],
2978 if(activate_proc != (XtCallbackProc)NULL)
2979 XtAddCallback(button, XmNactivateCallback,
2980 activate_proc, (XtPointer)(XtArgVal)i);
2981 if(i == initial_item)
2982 initial_selected = button;
2984 XtVaSetValues(option_menu,
2985 XmNsubMenuId, pulldown,
2986 XmNmenuHistory, initial_selected,
2993 * ------------------------------------------------------------------------
2994 * Name: CreateXmStringsFromOidList
3006 CreateXmStringsFromOidList(const PdmOidList* list)
3008 int count = PdmOidListCount(list);
3009 XmString* xmstr_list = (XmString*)NULL;
3017 * build a list of Xm strings for the passed PdmOidList
3019 xmstr_list = (XmString*)XtCalloc(count, sizeof(XmString));
3020 for(i = 0; i < count; i++)
3022 oid = PdmOidListGetOid(list, i);
3023 str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
3025 PdmOidDefaultMsg(oid));
3026 xmstr_list[i] = XmStringCreateLocalized((char*)str);
3033 * ------------------------------------------------------------------------
3034 * Name: FreeXmStringList
3046 FreeXmStringList(XmString* list, int count)
3050 for(i = 0; i < count; i++)
3051 XmStringFree(list[i]);
3052 XtFree((char*)list);
3056 * ------------------------------------------------------------------------
3057 * Name: IconMaxDimension
3069 IconMaxDimension(Widget icon_label,
3070 PdmPixmapList* pixmap_list, int i,
3071 Dimension* max_width, Dimension* max_height)
3073 Dimension width, height;
3074 XtArgVal width0, height0;
3076 * set the pixmap in the label
3078 XtVaSetValues(icon_label,
3079 XmNlabelPixmap, PdmPixmapListGetPixmap(pixmap_list, i),
3082 * get the label dimensions
3084 XtVaGetValues(icon_label,
3086 XmNheight, &height0,
3088 width = (Dimension)width0;
3089 height = (Dimension)height0;
3091 * update the max dimensions
3093 if(width > *max_width)
3095 if(height > *max_height)
3096 *max_height = height;
3100 * ------------------------------------------------------------------------
3101 * Name: PdmPixmapListNew
3112 static PdmPixmapList*
3113 PdmPixmapListNew(int count,
3117 PdmPixmapList* me = (PdmPixmapList*)XtCalloc(1, sizeof(PdmPixmapList));
3120 me->pixmap = (Pixmap*)XtCalloc(count, sizeof(Pixmap));
3121 me->image_name = (char**)XtCalloc(count, sizeof(char*));
3122 me->screen = XtScreen(w);
3125 Widget xmscr = XmGetXmScreen(me->screen);
3126 XtVaGetValues(xmscr, XmNinsensitiveStippleBitmap, &me->stipple, NULL);
3136 me->foreground = (Pixel)fg;
3137 me->background = (Pixel)bg;
3143 * ------------------------------------------------------------------------
3144 * Name: PdmPixmapListDelete
3156 PdmPixmapListDelete(PdmPixmapList* me)
3158 if(me != (PdmPixmapList*)NULL)
3161 for(i = 0; i < PdmPixmapListCount(me); i++)
3163 if(me->pixmap[i] != (Pixmap)NULL)
3165 if(me->stipple == None)
3167 if(me->pixmap[i] != None)
3168 XmDestroyPixmap(me->screen, me->pixmap[i]);
3172 if(me->pixmap[i] != None)
3173 XFreePixmap(DisplayOfScreen(me->screen),
3176 XtFree((char*)me->image_name[i]);
3179 XtFree((char*)me->pixmap);
3180 XtFree((char*)me->image_name);
3186 * ------------------------------------------------------------------------
3187 * Name: PdmPixmapSetImageName
3199 PdmPixmapListSetImageName(PdmPixmapList* me,
3200 const char* image_name,
3203 me->image_name[i] = XtNewString(image_name);
3207 * ------------------------------------------------------------------------
3208 * Name: PdmPixmapListGetPixmap
3220 PdmPixmapListGetPixmap(PdmPixmapList* me, int i)
3222 if(me->pixmap[i] == None)
3224 me->pixmap[i] = XmGetPixmap(me->screen, me->image_name[i],
3225 me->foreground, me->background);
3226 if(me->pixmap[i] == XmUNSPECIFIED_PIXMAP)
3228 me->pixmap[i] = None;
3230 else if(me->stipple != None)
3232 Pixmap xmpixmap = me->pixmap[i];
3233 Display* display = DisplayOfScreen(me->screen);
3236 unsigned int width, height, border_width, depth;
3240 * make a copy of the pixmap cached by motif
3242 XGetGeometry(display, xmpixmap, &root, &x, &y,
3243 &width, &height, &border_width, &depth);
3245 XCreatePixmap(display, xmpixmap, width, height, depth);
3246 gc = XCreateGC(display, me->pixmap[i], (unsigned long)0, &values);
3247 XCopyArea(display, xmpixmap, me->pixmap[i], gc,
3248 0, 0, width, height, 0, 0);
3252 XSetFillStyle(display, gc, FillStippled);
3253 XSetStipple(display, gc, me->stipple);
3254 XFillRectangle(display, me->pixmap[i], gc, 0, 0, width, height);
3258 XFreeGC(display, gc);
3259 XmDestroyPixmap(me->screen, xmpixmap);
3262 return me->pixmap[i];
3266 * ------------------------------------------------------------------------
3267 * Name: SetListBoxSelection
3278 SetListBoxSelection(Widget list_box, int position)
3280 XtArgVal visible_item_count0, item_count0;
3281 int visible_item_count;
3284 int first_visible_pos;
3286 * Scroll the list, making the item at the indicated position
3287 * visible in the center of the list box, and make
3288 * it the initial selection.
3290 XtVaGetValues(list_box,
3291 XmNitemCount, &item_count0,
3292 XmNvisibleItemCount, &visible_item_count0,
3294 item_count = (int)item_count0;
3295 visible_item_count = (int)visible_item_count0;
3297 if(item_count > visible_item_count)
3299 middle_offset = (visible_item_count+1) / 2;
3300 if(position > middle_offset)
3301 if(position > item_count - middle_offset)
3302 first_visible_pos = item_count - visible_item_count +1;
3304 first_visible_pos = position - middle_offset + 1;
3306 first_visible_pos = 1;
3307 XmListSetPos(list_box, first_visible_pos);
3311 XmListSelectPos(list_box, position, False);
3313 XmListDeselectAllItems(list_box);
3317 * ------------------------------------------------------------------------
3318 * Name: GetIconFileName
3329 GetIconFileName(Widget w, String resource_name)
3331 String icon_file_name;
3332 XtResource res_struct;
3334 res_struct.resource_name = resource_name;
3335 res_struct.resource_class = resource_name;
3336 res_struct.resource_type = XmRString;
3337 res_struct.resource_size = sizeof(String);
3338 res_struct.resource_offset = 0;
3339 res_struct.default_type = XmRImmediate;
3340 res_struct.default_addr = (XtPointer)NULL;
3341 XtGetApplicationResources(w, (XtPointer)&icon_file_name,
3342 &res_struct, 1, (ArgList)NULL, 0);
3344 return icon_file_name;