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 librararies 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.
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;
535 * printer model description
537 data->printer_model =
538 PdmXpGetStringValue(pdm_xp, XPPrinterAttr, pdmoid_att_printer_model);
542 strval = PdmXpGetStringValue(pdm_xp, XPDocAttr,
543 pdmoid_att_document_format);
544 data->document_format = PdmOidDocumentFormatParse(strval);
545 if((char*)NULL == data->document_format)
548 * document format not specified, try to obtain
549 * document-formats-supported, and obtain up the default from it
551 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
552 pdmoid_att_document_formats_supported);
553 data->document_format = PdmOidDocumentFormatDefault(strval);
556 * document attributes supported
558 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
559 pdmoid_att_document_attributes_supported);
560 data->document_attrs_supported = PdmOidListNew(strval);
562 * content orientation supported
564 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
565 pdmoid_att_content_orientations_supported);
566 data->orientations_supported = PdmOidListNew(strval);
571 PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_content_orientation);
575 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
576 pdmoid_att_plexes_supported);
577 data->plexes_supported = PdmOidListNew(strval);
581 data->plex = PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_plex);
583 * default input tray, default medium
585 data->default_input_tray =
586 PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_default_input_tray);
587 data->default_medium =
588 PdmXpGetValue(pdm_xp, XPDocAttr, pdmoid_att_default_medium);
590 * medium source sizes supported
592 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
593 pdmoid_att_medium_source_sizes_supported);
594 medium_ss_supported = PdmOidMediumSSNew(strval);
598 strval = PdmXpGetStringValue(pdm_xp, XPPrinterAttr,
599 pdmoid_att_input_trays_medium);
600 input_trays_medium = PdmOidTrayMediumListNew(strval);
602 * build input trays and page sizes ready lists
604 PdmOidMediumSSGetTraysSizes(medium_ss_supported, input_trays_medium,
605 &data->input_trays, &data->tray_sizes);
607 * build list of supported page sizes
609 data->sizes_supported = PdmOidMediumSSGetAllSizes(medium_ss_supported);
613 PdmOidMediumSSDelete(medium_ss_supported);
614 PdmOidTrayMediumListDelete(input_trays_medium);
618 * ------------------------------------------------------------------------
619 * Name: PdmPrinterBoxSetAttr
631 PdmPrinterBoxSetAttr(PdmSetupBox* me, PdmXp* pdm_xp)
633 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
637 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_content_orientation,
638 OrientCtlGetOrientation(data->orient_ctl));
642 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_plex,
643 PlexCtlGetPlex(data->plex_ctl));
647 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_default_medium,
648 SizeCtlGetSize(data->size_ctl));
652 PdmXpSetValue(pdm_xp, XPDocAttr, pdmoid_att_default_input_tray,
653 TrayCtlGetTray(data->tray_ctl));
657 * ------------------------------------------------------------------------
658 * Name: PdmPrinterBoxCreateWindow
662 * Creates the PDM Printer options setup box window.
666 * Widget ID of the new Printer setup box.
670 PdmPrinterBoxCreateWindow(PdmSetupBox* me, Widget parent)
672 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
679 * create the manager for the Printer Setup Box
681 manager = XtVaCreateManagedWidget(
683 xmRowColumnWidgetClass,
687 * create the printer model row
689 if(data->printer_model != (const char*)NULL)
694 row = XtVaCreateManagedWidget(
696 xmRowColumnWidgetClass,
698 XmNorientation, XmHORIZONTAL,
701 * create the printer model label
703 w = XtVaCreateManagedWidget("PrinterModelLabel",
708 * create the printer model using just the 1st line
710 desc = XtNewString(data->printer_model);
711 ptr = Dt_strchr(desc, '\n');
714 label = XmStringCreateLocalized(desc);
716 w = XtVaCreateManagedWidget("PrinterModel",
719 XmNlabelString, label,
724 * create the document format row
726 if((char*)NULL != data->document_format)
729 * create the document format row
731 row = XtVaCreateManagedWidget(
733 xmRowColumnWidgetClass,
735 XmNorientation, XmHORIZONTAL,
738 * create the document format label
740 w = XtVaCreateManagedWidget("DocumentFormatLabel",
745 * create the document format
747 label = XmStringCreateLocalized(data->document_format);
748 w = XtVaCreateManagedWidget("DocumentFormat",
751 XmNlabelString, label,
756 * orientation / plex / tray / sides
758 draw_area = XtVaCreateWidget("PrinterSetupControls",
759 xmDrawingAreaWidgetClass,
762 XtAddCallback(draw_area, XmNresizeCallback,
763 PdmPrinterBoxResizeCB, (XtPointer)me);
765 * orientation control
767 OrientCtlCreate(data->orient_ctl,
770 data->document_attrs_supported,
771 data->orientations_supported);
775 SizeCtlCreate(data->size_ctl,
777 data->default_medium,
778 data->document_attrs_supported,
780 data->sizes_supported);
784 PlexCtlCreate(data->plex_ctl,
787 data->document_attrs_supported,
788 data->plexes_supported);
792 TrayCtlCreate(data->tray_ctl,
794 data->default_input_tray,
795 data->default_medium,
796 data->document_attrs_supported,
800 XtManageChild(draw_area);
802 * return the new Printer Setup Box
808 * ------------------------------------------------------------------------
809 * Name: PdmPrinterBoxResizeCB
821 PdmPrinterBoxResizeCB(Widget w,
822 XtPointer client_data,
825 PdmSetupBox* me = (PdmSetupBox*)client_data;
826 PdmPrinterBoxData* data = (PdmPrinterBoxData*)me->subclass_data;
829 Dimension width, height;
831 PdmRect rt, rs, ro, rp, c1, c2, r1, r2;
833 * retrieve child dimensions
835 XtVaGetValues(TrayCtlGetWidget(data->tray_ctl),
839 XmNheight, &rt.height,
841 XtVaGetValues(SizeCtlGetWidget(data->size_ctl),
845 XmNheight, &rs.height,
847 XtVaGetValues(OrientCtlGetWidget(data->orient_ctl),
851 XmNheight, &ro.height,
853 XtVaGetValues(PlexCtlGetWidget(data->plex_ctl),
857 XmNheight, &rp.height,
860 * calculate rows and columns dimensions
862 r1.x = r2.x = c1.x = 0;
863 r1.y = c1.y = c2.y = 0;
864 r1.height = MAX(ro.height, rp.height);
865 r2.height = MAX(rs.height, rt.height);
866 c1.width = MAX(ro.width, rs.width);
867 c2.width = MAX(rp.width, rt.width);
868 r2.y = r1.height + 5;
870 r1.width = r2.width = c2.x + c2.width;
871 c1.height = c2.height = r2.y + r2.height;
873 * position the children
875 XtVaSetValues(OrientCtlGetWidget(data->orient_ctl),
879 XmNheight, r1.height,
881 XtVaSetValues(PlexCtlGetWidget(data->plex_ctl),
885 XmNheight, r1.height,
887 XtVaSetValues(SizeCtlGetWidget(data->size_ctl),
891 XmNheight, r2.height,
893 XtVaSetValues(TrayCtlGetWidget(data->tray_ctl),
897 XmNheight, r2.height,
900 * resize the drawing area to accomodate the new layout
904 XmNheight, c1.height,
909 * ------------------------------------------------------------------------
922 OrientCtlNew(PlexCtl* plex_ctl)
924 OrientCtl* me = (OrientCtl*)XtCalloc(1, sizeof(OrientCtl));
925 me->plex_ctl = plex_ctl;
930 * ------------------------------------------------------------------------
931 * Name: OrientCtlDelete
943 OrientCtlDelete(OrientCtl* me)
945 PdmOidListDelete(me->dummy_orientations_supported);
946 PdmPixmapListDelete(me->pixmap_list);
947 PdmPixmapListDelete(me->i_pixmap_list);
953 * ------------------------------------------------------------------------
954 * Name: OrientCtlCreate
966 OrientCtlCreate(OrientCtl* me,
969 const PdmOidList* document_attrs_supported,
970 const PdmOidList* orientations_supported)
974 * determine if setting the content orientation is supported
976 if(PdmOidListHasOid(document_attrs_supported,
977 pdmoid_att_content_orientation)
979 PdmOidListCount(orientations_supported) > 0)
982 me->orientations_supported = orientations_supported;
988 * dummy up a list to be presented (insensitive)
990 me->dummy_orientations_supported =
991 PdmOidListNew(PdmOidString(pdmoid_val_content_orientation_portrait));
992 me->orientations_supported = me->dummy_orientations_supported;
993 orientation = pdmoid_none;
996 * set the initially selected list item
998 OrientCtlSetSelectedItem(me,
999 PdmOidListGetIndex(me->orientations_supported,
1002 * create the orientations control window
1004 OrientCtlCreateWindow(me, parent);
1006 * initialize the window components
1008 OrientCtlCreatePulldown(me);
1009 OrientCtlInitPixmapList(me);
1010 OrientCtlUpdateIcon(me);
1012 * if content-orientation is not supported, disable the control
1015 OrientCtlDisable(me);
1019 * ------------------------------------------------------------------------
1020 * Name: OrientCtlCreateWindow
1032 OrientCtlCreateWindow(OrientCtl* me,
1035 Widget control_manager;
1040 me->widget = XtVaCreateManagedWidget("OrientCtlTop",
1043 XmNshadowType, XmSHADOW_ETCHED_IN,
1049 XtVaCreateManagedWidget("OrientationLabel",
1052 XmNframeChildType, XmFRAME_TITLE_CHILD,
1055 * orientation controls manager
1058 XtVaCreateManagedWidget("OrientationControls",
1059 xmDrawingAreaWidgetClass,
1061 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
1063 XtAddCallback(control_manager, XmNresizeCallback, OrientCtlResizeCB, me);
1065 * orientations option menu
1068 XtVaCreateManagedWidget("OrientationOptionMenu",
1069 xmRowColumnWidgetClass,
1072 XmNrowColumnType, XmMENU_OPTION,
1078 XtVaCreateManagedWidget("OrientationIcon",
1081 XmNlabelType, XmPIXMAP,
1082 XmNalignment, XmALIGNMENT_CENTER,
1087 * ------------------------------------------------------------------------
1088 * Name: OrientCtlDisable
1092 * Disable the orientation controls.
1100 OrientCtlDisable(OrientCtl* me)
1102 XtSetSensitive(me->frame_label, False);
1103 XtSetSensitive(me->option_menu, False);
1104 XtSetSensitive(me->icon_label, False);
1108 * ------------------------------------------------------------------------
1109 * Name: OrientCtlResizeCB
1121 OrientCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
1123 OrientCtl* me = (OrientCtl*)client_data;
1124 Dimension height, width, margin_width, new_width;
1125 Position menu_x, menu_y, icon_x, icon_y;
1126 Dimension menu_h, menu_w, icon_h, icon_w;
1128 * get current layout info
1130 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
1131 XmNmarginWidth, &margin_width,
1133 XtVaGetValues(me->option_menu, XmNheight, &menu_h, XmNwidth, &menu_w,
1135 XtVaGetValues(me->icon_label, XmNheight, &icon_h, XmNwidth, &icon_w,
1138 * position controls side by side
1141 icon_x = menu_x + menu_w;
1145 menu_y = (height - menu_h) / 2;
1146 icon_y = (height - icon_h) / 2;
1150 XtVaSetValues(me->option_menu, XmNx, menu_x, XmNy, menu_y, NULL);
1151 XtVaSetValues(me->icon_label, XmNx, icon_x, XmNy, icon_y, NULL);
1153 * update drawing area width
1155 new_width = menu_x + menu_w + icon_w + margin_width;
1156 if(new_width > width)
1157 XtVaSetValues(w, XmNwidth, new_width, NULL);
1161 * ------------------------------------------------------------------------
1162 * Name: OrientCtlCreatePulldown
1174 OrientCtlCreatePulldown(OrientCtl* me)
1179 * create a list of XmStrings for the content orientations
1181 list = CreateXmStringsFromOidList(me->orientations_supported);
1183 * create the option menu pulldown
1185 count = PdmOidListCount(me->orientations_supported);
1186 CreateOptionMenuPulldown("OrientationOptions",
1195 FreeXmStringList(list, count);
1199 * ------------------------------------------------------------------------
1200 * Name: OrientCtlSelectCB
1212 OrientCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
1215 int selected_item = (int)client_data;
1217 XtVaGetValues(w, XmNuserData, &me, NULL);
1218 OrientCtlSetSelectedItem(me, selected_item);
1219 OrientCtlUpdateIcon(me);
1223 * ------------------------------------------------------------------------
1224 * Name: OrientCtlInitPixmapList
1236 OrientCtlInitPixmapList(OrientCtl* me)
1239 const char* image_name;
1241 Dimension max_width = 0;
1242 Dimension max_height = 0;
1245 * initialize the list of pixmaps based on the supported orientations
1247 count = PdmOidListCount(me->orientations_supported);
1248 me->pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
1249 me->i_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
1250 for(i = 0; i < count; i++)
1252 switch(PdmOidListGetOid(me->orientations_supported, i))
1254 case pdmoid_val_content_orientation_portrait:
1255 image_name = GetIconFileName(me->widget, "PortraitIconFileName");
1257 case pdmoid_val_content_orientation_landscape:
1258 image_name = GetIconFileName(me->widget, "LandscapeIconFileName");
1260 case pdmoid_val_content_orientation_reverse_portrait:
1262 GetIconFileName(me->widget, "ReversePortraitIconFileName");
1264 case pdmoid_val_content_orientation_reverse_landscape:
1266 GetIconFileName(me->widget, "ReverseLandscapeIconFileName");
1271 PdmPixmapListSetImageName(me->pixmap_list, image_name, i);
1272 PdmPixmapListSetImageName(me->i_pixmap_list, image_name, i);
1273 IconMaxDimension(me->icon_label,
1275 &max_width, &max_height);
1277 XtVaSetValues(me->icon_label,
1278 XmNwidth, max_width,
1279 XmNheight, max_height,
1280 XmNrecomputeSize, False,
1285 * ------------------------------------------------------------------------
1286 * Name: OrientCtlSetSelectedItem
1298 OrientCtlSetSelectedItem(OrientCtl* me, int selected_item)
1300 if(selected_item == -1)
1301 me->selected_item = 0;
1303 me->selected_item = selected_item;
1305 if(me->plex_ctl != (PlexCtl*)NULL)
1306 PlexCtlSetOrientation(me->plex_ctl, OrientCtlGetOrientation(me));
1311 * ------------------------------------------------------------------------
1312 * Name: OrientCtlUpdateIcon
1324 OrientCtlUpdateIcon(OrientCtl* me)
1326 if(me->icon_label != (Widget)NULL)
1327 XtVaSetValues(me->icon_label,
1329 PdmPixmapListGetPixmap(me->pixmap_list,
1331 XmNlabelInsensitivePixmap,
1332 PdmPixmapListGetPixmap(me->i_pixmap_list,
1338 * ------------------------------------------------------------------------
1339 * Name: OrientCtlGetOrientation
1351 OrientCtlGetOrientation(OrientCtl* me)
1353 if(me->orientations_supported == me->dummy_orientations_supported)
1356 return PdmOidListGetOid(me->orientations_supported, me->selected_item);
1361 * ------------------------------------------------------------------------
1376 PlexCtl* me = (PlexCtl*)XtCalloc(1, sizeof(PlexCtl));
1377 me->pixmap_list_ptr = &me->portrait_pixmap_list;
1378 me->i_pixmap_list_ptr = &me->i_portrait_pixmap_list;
1383 * ------------------------------------------------------------------------
1384 * Name: PlexCtlDelete
1396 PlexCtlDelete(PlexCtl* me)
1398 PdmOidListDelete(me->dummy_plexes_supported);
1399 PdmPixmapListDelete(me->portrait_pixmap_list);
1400 PdmPixmapListDelete(me->i_portrait_pixmap_list);
1401 PdmPixmapListDelete(me->landscape_pixmap_list);
1402 PdmPixmapListDelete(me->i_landscape_pixmap_list);
1408 * ------------------------------------------------------------------------
1409 * Name: PlexCtlCreate
1421 PlexCtlCreate(PlexCtl* me,
1424 const PdmOidList* document_attrs_supported,
1425 const PdmOidList* plexes_supported)
1429 * determine if setting the content orientation is supported
1431 if(PdmOidListHasOid(document_attrs_supported, pdmoid_att_plex)
1433 PdmOidListCount(plexes_supported) > 0)
1436 me->plexes_supported = plexes_supported;
1442 * dummy up a list to be presented (insensitive)
1444 me->dummy_plexes_supported =
1445 PdmOidListNew(PdmOidString(pdmoid_val_plex_simplex));
1446 me->plexes_supported = me->dummy_plexes_supported;
1451 * set the initially selected list item
1453 PlexCtlSetSelectedItem(me, PdmOidListGetIndex(me->plexes_supported, plex));
1455 * create the plexes control window
1457 PlexCtlCreateWindow(me, parent);
1459 * initialize the window components
1461 PlexCtlCreatePulldown(me);
1462 PlexCtlInitPixmapLists(me);
1463 PlexCtlUpdateIcon(me);
1465 * if plex is not supported, disable the control
1472 * ------------------------------------------------------------------------
1473 * Name: PlexCtlCreateWindow
1485 PlexCtlCreateWindow(PlexCtl* me,
1488 Widget control_manager;
1492 me->widget = XtVaCreateManagedWidget("PlexCtlTop",
1495 XmNshadowType, XmSHADOW_ETCHED_IN,
1501 XtVaCreateManagedWidget("PlexLabel",
1504 XmNframeChildType, XmFRAME_TITLE_CHILD,
1507 * plex controls manager
1510 XtVaCreateManagedWidget(
1512 xmDrawingAreaWidgetClass,
1514 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
1516 XtAddCallback(control_manager, XmNresizeCallback, PlexCtlResizeCB, me);
1518 * plexes option menu
1521 XtVaCreateManagedWidget("PlexOptionMenu",
1522 xmRowColumnWidgetClass,
1524 XmNrowColumnType, XmMENU_OPTION,
1531 XtVaCreateManagedWidget("PlexIcon",
1534 XmNlabelType, XmPIXMAP,
1535 XmNalignment, XmALIGNMENT_CENTER,
1540 * ------------------------------------------------------------------------
1541 * Name: PlexCtlDisable
1545 * Disable the plex controls.
1553 PlexCtlDisable(PlexCtl* me)
1555 XtSetSensitive(me->frame_label, False);
1556 XtSetSensitive(me->option_menu, False);
1557 XtSetSensitive(me->icon_label, False);
1561 * ------------------------------------------------------------------------
1562 * Name: PlexCtlResizeCB
1574 PlexCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
1576 PlexCtl* me = (PlexCtl*)client_data;
1577 Dimension height, width, margin_width, new_width;
1578 Position menu_x, menu_y, icon_x, icon_y;
1579 Dimension menu_h, menu_w, icon_h, icon_w;
1581 * get current layout info
1583 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
1584 XmNmarginWidth, &margin_width,
1586 XtVaGetValues(me->option_menu, XmNheight, &menu_h, XmNwidth, &menu_w,
1588 XtVaGetValues(me->icon_label, XmNheight, &icon_h, XmNwidth, &icon_w,
1591 * position controls side by side
1594 icon_x = menu_x + menu_w;
1598 menu_y = (height - menu_h) / 2;
1599 icon_y = (height - icon_h) / 2;
1603 XtVaSetValues(me->option_menu, XmNx, menu_x, XmNy, menu_y, NULL);
1604 XtVaSetValues(me->icon_label, XmNx, icon_x, XmNy, icon_y, NULL);
1606 * update drawing area width
1608 new_width = menu_x + menu_w + icon_w + margin_width;
1609 if(new_width > width)
1610 XtVaSetValues(w, XmNwidth, new_width, NULL);
1614 * ------------------------------------------------------------------------
1615 * Name: PlexCtlCreatePulldown
1627 PlexCtlCreatePulldown(PlexCtl* me)
1632 * build a list of Xm strings for the supported plexes
1634 list = CreateXmStringsFromOidList(me->plexes_supported);
1636 * create the option menu pulldown
1638 count = PdmOidListCount(me->plexes_supported);
1639 CreateOptionMenuPulldown("PlexOptions",
1648 FreeXmStringList(list, count);
1652 * ------------------------------------------------------------------------
1653 * Name: PlexCtlSelectCB
1665 PlexCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
1668 int selected_item = (int)client_data;
1670 XtVaGetValues(w, XmNuserData, &me, NULL);
1671 PlexCtlSetSelectedItem(me, selected_item);
1672 PlexCtlUpdateIcon(me);
1676 * ------------------------------------------------------------------------
1677 * Name: PlexCtlSetOrientation
1689 PlexCtlSetOrientation(PlexCtl* me,
1694 case pdmoid_val_content_orientation_landscape:
1695 case pdmoid_val_content_orientation_reverse_landscape:
1696 me->pixmap_list_ptr = &me->landscape_pixmap_list;
1697 me->i_pixmap_list_ptr = &me->i_landscape_pixmap_list;
1700 me->pixmap_list_ptr = &me->portrait_pixmap_list;
1701 me->i_pixmap_list_ptr = &me->i_portrait_pixmap_list;
1704 PlexCtlUpdateIcon(me);
1708 * ------------------------------------------------------------------------
1709 * Name: PlexCtlInitPixmapLists
1721 PlexCtlInitPixmapLists(PlexCtl* me)
1724 const char* portrait_image_name;
1725 const char* landscape_image_name;
1727 Dimension max_width = 0;
1728 Dimension max_height = 0;
1731 * initialize the list of pixmaps based on the list of plexes
1733 count = PdmOidListCount(me->plexes_supported);
1734 me->portrait_pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
1735 me->i_portrait_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
1736 me->landscape_pixmap_list = PdmPixmapListNew(count, me->icon_label, False);
1737 me->i_landscape_pixmap_list = PdmPixmapListNew(count, me->icon_label, True);
1738 for(i = 0; i < count; i++)
1740 switch(PdmOidListGetOid(me->plexes_supported, i))
1742 case pdmoid_val_plex_simplex:
1743 portrait_image_name =
1744 GetIconFileName(me->widget, "SimplexPortraitIconFileName");
1745 landscape_image_name =
1746 GetIconFileName(me->widget, "SimplexLandscapeIconFileName");
1748 case pdmoid_val_plex_duplex:
1749 portrait_image_name =
1750 GetIconFileName(me->widget, "DuplexPortraitIconFileName");
1751 landscape_image_name =
1752 GetIconFileName(me->widget, "DuplexLandscapeIconFileName");
1754 case pdmoid_val_plex_tumble:
1755 portrait_image_name =
1756 GetIconFileName(me->widget, "TumblePortraitIconFileName");
1757 landscape_image_name =
1758 GetIconFileName(me->widget, "TumbleLandscapeIconFileName");
1763 PdmPixmapListSetImageName(me->portrait_pixmap_list,
1764 portrait_image_name, i);
1765 PdmPixmapListSetImageName(me->i_portrait_pixmap_list,
1766 portrait_image_name, i);
1767 PdmPixmapListSetImageName(me->landscape_pixmap_list,
1768 landscape_image_name, i);
1769 PdmPixmapListSetImageName(me->i_landscape_pixmap_list,
1770 landscape_image_name, i);
1771 IconMaxDimension(me->icon_label,
1772 me->portrait_pixmap_list, i,
1773 &max_width, &max_height);
1774 IconMaxDimension(me->icon_label,
1775 me->landscape_pixmap_list, i,
1776 &max_width, &max_height);
1778 XtVaSetValues(me->icon_label,
1779 XmNwidth, max_width,
1780 XmNheight, max_height,
1781 XmNrecomputeSize, False,
1786 * ------------------------------------------------------------------------
1787 * Name: PlexCtlSetSelectedItem
1799 PlexCtlSetSelectedItem(PlexCtl* me, int selected_item)
1801 if(selected_item == -1)
1802 me->selected_item = 0;
1804 me->selected_item = selected_item;
1808 * ------------------------------------------------------------------------
1809 * Name: PlexCtlUpdateIcon
1821 PlexCtlUpdateIcon(PlexCtl* me)
1823 if(me->icon_label != (Widget)NULL)
1824 XtVaSetValues(me->icon_label,
1826 PdmPixmapListGetPixmap(*me->pixmap_list_ptr,
1828 XmNlabelInsensitivePixmap,
1829 PdmPixmapListGetPixmap(*me->i_pixmap_list_ptr,
1835 * ------------------------------------------------------------------------
1836 * Name: PlexCtlGetPlex
1848 PlexCtlGetPlex(PlexCtl* me)
1850 if(me->plexes_supported == me->dummy_plexes_supported)
1853 return PdmOidListGetOid(me->plexes_supported, me->selected_item);
1857 * ------------------------------------------------------------------------
1870 TrayCtlNew(SizeCtl* size_ctl)
1872 TrayCtl* me = (TrayCtl*)XtCalloc(1, sizeof(TrayCtl));
1874 me->size_ctl = size_ctl;
1880 * ------------------------------------------------------------------------
1881 * Name: TrayCtlDelete
1893 TrayCtlDelete(TrayCtl* me)
1899 * ------------------------------------------------------------------------
1900 * Name: TrayCtlCreate
1912 TrayCtlCreate(TrayCtl* me,
1914 PdmOid default_input_tray,
1915 PdmOid default_medium,
1916 const PdmOidList* document_attrs_supported,
1917 const PdmOidList* input_trays,
1918 const PdmOidList* tray_sizes)
1922 * save the trays and sizes list pointers
1924 me->input_trays = input_trays;
1925 me->tray_sizes = tray_sizes;
1927 * determine if setting the input tray is supported
1929 if(PdmOidListHasOid(document_attrs_supported,
1930 pdmoid_att_default_input_tray)
1932 PdmOidListCount(me->input_trays) > 0)
1939 * set the initially selected list item
1941 if(default_medium != pdmoid_none)
1944 * default-medium has precedence; set "Auto-select" (index 0)
1946 TrayCtlSetSelectedItem(me, 0);
1950 int i = PdmOidListGetIndex(me->input_trays, default_input_tray);
1951 if(!supported || i == -1)
1953 * default-input-tray unsupported or not found in list; set
1954 * "Auto-select" (index 0)
1956 TrayCtlSetSelectedItem(me, 0);
1959 * Select the list item corresponding to default-input-tray -
1960 * ie. add 1 to the input trays list index since the option
1961 * menu is always built with "Auto-select" as the first
1962 * entry, followed by the input trays list entries.
1964 TrayCtlSetSelectedItem(me, i+1);
1967 * create the tray control window
1969 TrayCtlCreateWindow(me, parent);
1971 * initialize the window components
1973 TrayCtlCreatePulldown(me);
1975 * if tray selection is not supported, disable the control
1982 * ------------------------------------------------------------------------
1983 * Name: TrayCtlCreateWindow
1995 TrayCtlCreateWindow(TrayCtl* me, Widget parent)
1997 Widget control_manager;
2002 me->widget = XtVaCreateManagedWidget("TrayCtlTop",
2005 XmNshadowType, XmSHADOW_ETCHED_IN,
2011 = XtVaCreateManagedWidget("TrayLabel",
2014 XmNframeChildType, XmFRAME_TITLE_CHILD,
2017 * tray controls manager
2020 XtVaCreateManagedWidget("TrayControls",
2021 xmDrawingAreaWidgetClass,
2023 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
2025 XtAddCallback(control_manager, XmNresizeCallback, TrayCtlResizeCB, me);
2030 XtVaCreateManagedWidget("TrayOptionMenu",
2031 xmRowColumnWidgetClass,
2034 XmNrowColumnType, XmMENU_OPTION,
2039 * ------------------------------------------------------------------------
2040 * Name: TrayCtlDisable
2044 * Disable the input tray controls.
2052 TrayCtlDisable(TrayCtl* me)
2054 XtSetSensitive(me->frame_label, False);
2055 XtSetSensitive(me->option_menu, False);
2059 * ------------------------------------------------------------------------
2060 * Name: TrayCtlResizeCB
2072 TrayCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
2074 TrayCtl* me = (TrayCtl*)client_data;
2075 Dimension height, menu_h;
2078 * get current layout info
2080 XtVaGetValues(w, XmNheight, &height, NULL);
2081 XtVaGetValues(me->option_menu, XmNheight, &menu_h, NULL);
2085 menu_y = (height - menu_h) / 2;
2089 XtVaSetValues(me->option_menu, XmNx, 0, XmNy, menu_y, NULL);
2093 * ------------------------------------------------------------------------
2094 * Name: TrayCtlGetTray
2106 TrayCtlGetTray(TrayCtl* me)
2108 if(me->selected_item == 0)
2111 return PdmOidListGetOid(me->input_trays, me->selected_item - 1);
2115 * ------------------------------------------------------------------------
2116 * Name: TrayCtlCreatePulldown
2128 TrayCtlCreatePulldown(TrayCtl* me)
2130 XmString* xmstr_list;
2136 * create a list of XmStrings for the Auto-select item plus the list
2139 count = 1 + PdmOidListCount(me->input_trays);
2140 xmstr_list = (XmString*)XtCalloc(count, sizeof(XmString));
2142 * set the "Auto-select" item as the first item
2145 xmstr_list[i++] = XmStringCreateLocalized((char*)PDM_MSG_TRAY_AUTO_SELECT);
2147 * add the input trays
2149 for(; i < count; i++)
2151 oid = PdmOidListGetOid(me->input_trays, i-1);
2152 str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
2154 PdmOidDefaultMsg(oid));
2155 xmstr_list[i] = XmStringCreateLocalized((char*)str);
2158 * create the option menu pulldown
2160 CreateOptionMenuPulldown("TrayOptions",
2169 FreeXmStringList(xmstr_list, count);
2173 * ------------------------------------------------------------------------
2174 * Name: TrayCtlSetSelectedItem
2186 TrayCtlSetSelectedItem(TrayCtl* me, int selected_item)
2188 if(selected_item == -1)
2189 me->selected_item = 0;
2191 me->selected_item = selected_item;
2193 * update the page size control accordingly
2195 if(me->selected_item == 0)
2196 SizeCtlSetMultiSizeMode(me->size_ctl);
2198 SizeCtlSetSingleSizeMode(me->size_ctl,
2199 PdmOidListGetOid(me->tray_sizes,
2200 me->selected_item - 1));
2204 * ------------------------------------------------------------------------
2205 * Name: TrayCtlSelectCB
2217 TrayCtlSelectCB(Widget w, XtPointer client_data, XtPointer call_data)
2220 int selected_item = (int)client_data;
2222 XtVaGetValues(w, XmNuserData, &me, NULL);
2223 TrayCtlSetSelectedItem(me, selected_item);
2228 * ------------------------------------------------------------------------
2243 SizeCtl* me = (SizeCtl*)XtCalloc(1, sizeof(SizeCtl));
2248 * ------------------------------------------------------------------------
2249 * Name: SizeCtlDelete
2261 SizeCtlDelete(SizeCtl* me)
2263 if(me != (SizeCtl*)NULL)
2265 if(me->sizes_ready_xmstr != (XmString*)NULL)
2266 FreeXmStringList(me->sizes_ready_xmstr,
2267 PdmOidListCount(me->sizes_ready));
2268 if(me->sizes_supported_xmstr != (XmString*)NULL)
2269 FreeXmStringList(me->sizes_supported_xmstr,
2270 PdmOidListCount(me->sizes_supported));
2271 PdmOidListDelete(me->sizes_ready);
2272 PdmOidListDelete(me->sizes_supported);
2278 * ------------------------------------------------------------------------
2279 * Name: SizeCtlStrColl
2283 * An adaptor for using strcoll on SizeCtlSortRec's with qsort.
2287 * The return value for strcoll given the strings in the passed
2292 SizeCtlStrColl(const void* e1, const void* e2)
2294 const SizeCtlSortRec *r1 = e1, *r2 = e2;
2296 return strcoll(r1->str, r2->str);
2300 * ------------------------------------------------------------------------
2301 * Name: SizeCtlSetSizeLists
2305 * Creates a sorted XmStringTable and PdmOidList using
2306 * the oids from the passed PdmOidLinkedList. The newly created lists
2307 * are returned via the 'oids' and 'xmstrs' parms.
2315 SizeCtlSetSizeLists(PdmOidList** oid_list,
2316 XmStringTable* xmstrs,
2317 PdmOidLinkedList* oid_ll)
2321 count = PdmOidLinkedListCount(oid_ll);
2324 *oid_list = (PdmOidList*)NULL;
2325 *xmstrs = (XmStringTable)NULL;
2329 SizeCtlSortList sort_list;
2333 * sort the passed sizes
2335 sort_list = (SizeCtlSortList)XtCalloc(count, sizeof(SizeCtlSortRec));
2336 for(i = 0, oid = PdmOidLinkedListFirstOid(oid_ll);
2338 i++, oid = PdmOidLinkedListNextOid(oid_ll))
2340 sort_list[i].oid = oid;
2341 sort_list[i].str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
2343 PdmOidDefaultMsg(oid));
2345 qsort(sort_list, count, sizeof(SizeCtlSortRec), SizeCtlStrColl);
2347 * create the return lists of oids and XmStrings
2349 *oid_list = (PdmOidList*)XtCalloc(1, sizeof(PdmOidList));
2350 (*oid_list)->list = (PdmOid*)XtCalloc(count, sizeof(PdmOid));
2351 (*oid_list)->count = count;
2352 *xmstrs = (XmStringTable)XtCalloc(count, sizeof(XmString));
2353 for(i = 0; i < count; i++)
2355 ((*oid_list)->list)[i] = sort_list[i].oid;
2356 (*xmstrs)[i] = XmStringCreateLocalized((char*)sort_list[i].str);
2358 XtFree((char*)sort_list);
2363 * ------------------------------------------------------------------------
2364 * Name: SizeCtlCreate
2376 SizeCtlCreate(SizeCtl* me,
2378 PdmOid default_medium,
2379 const PdmOidList* document_attrs_supported,
2380 const PdmOidList* tray_sizes,
2381 PdmOidLinkedList* sizes_supported)
2386 PdmOidLinkedList* sizes_ready_ll;
2388 * initialize the selected size
2390 me->selected_size = default_medium;
2392 * build the sizes ready list using unique elements of the tray sizes
2395 sizes_ready_ll = PdmOidLinkedListNew();
2396 for(i = 0; i < PdmOidListCount(tray_sizes); i++)
2398 oid = PdmOidListGetOid(tray_sizes, i);
2399 if(!PdmOidLinkedListHasOid(sizes_ready_ll, oid))
2401 PdmOidLinkedListAddOid(sizes_ready_ll, oid);
2405 * determine if setting the medium is supported
2407 if(!PdmOidListHasOid(document_attrs_supported,
2408 pdmoid_att_default_medium)
2410 PdmOidLinkedListCount(sizes_supported) == 0)
2412 me->selected_list = SIZECTL_UNSUPPORTED;
2417 * default to the ready list
2419 me->selected_list = SIZECTL_SIZES_READY;
2422 * create the XmString versions of the sizes lists
2424 SizeCtlSetSizeLists(&me->sizes_ready, &me->sizes_ready_xmstr,
2426 PdmOidLinkedListDelete(sizes_ready_ll);
2427 SizeCtlSetSizeLists(&me->sizes_supported, &me->sizes_supported_xmstr,
2430 * create the size control window
2432 SizeCtlCreateWindow(me, parent);
2434 * update the control state
2440 * ------------------------------------------------------------------------
2441 * Name: SizeCtlCreateWindow
2453 SizeCtlCreateWindow(SizeCtl* me, Widget parent)
2457 Widget control_manager;
2459 XmString default_xmstr = (XmString)NULL;
2463 me->widget = XtVaCreateManagedWidget("PageSizeCtlTop",
2466 XmNshadowType, XmSHADOW_ETCHED_IN,
2472 = XtVaCreateManagedWidget("PageSizeLabel",
2475 XmNframeChildType, XmFRAME_TITLE_CHILD,
2479 * page size controls manager
2482 XtVaCreateManagedWidget("PageSizeControls",
2483 xmDrawingAreaWidgetClass,
2485 XmNframeChildType, XmFRAME_WORKAREA_CHILD,
2487 XtAddCallback(control_manager, XmNresizeCallback, SizeCtlResizeCB, me);
2489 * page sizes list box
2492 XtSetArg(args[n], XmNvisibleItemCount, 3); n++;
2493 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); n++;
2494 XtSetArg(args[n], XmNhorizontalScrollBar, NULL); n++;
2496 * set the supported sizes list in the list box, in order to lock
2497 * down the maximum dimensions - the list box does not support
2498 * changes to the list size policy after creation
2500 if(me->selected_list == SIZECTL_UNSUPPORTED)
2503 * unsupported, use "Default"
2506 XmStringCreateLocalized((char*)PDM_MSG_SIZE_DEFAULT);
2507 XtSetArg(args[n], XmNitemCount, 1); n++;
2508 XtSetArg(args[n], XmNitems, &default_xmstr); n++;
2512 XtSetArg(args[n], XmNitems, me->sizes_supported_xmstr); n++;
2513 XtSetArg(args[n], XmNitemCount,
2514 PdmOidListCount(me->sizes_supported)); n++;
2516 XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++;
2518 me->list_box = XmCreateScrolledList(control_manager, "PageSizes", args, n);
2519 if((XmString)NULL != default_xmstr) XmStringFree(default_xmstr);
2520 XtAddCallback(me->list_box, XmNbrowseSelectionCallback,
2521 SizeCtlSelectCB, (XtPointer)me);
2523 * hide the horizontal scroll bar, since the width of the list has
2524 * been set to accomodate the widest item.
2526 hscroll = XtNameToWidget(XtParent(me->list_box), "*HorScrollBar");
2527 XtVaSetValues(hscroll,
2528 XmNmappedWhenManaged, False,
2529 XmNx, 0, XmNy, 0, XmNwidth, 1, XmNheight, 1,
2532 * manage the scrolled list
2534 XtManageChild(me->list_box);
2535 XtManageChild(XtParent(me->list_box));
2537 * loaded / allowed sizes radio buttons
2539 me->radio_box = XtVaCreateWidget(
2541 xmRowColumnWidgetClass,
2543 XmNradioBehavior, True,
2545 me->ready_radio = XtVaCreateManagedWidget("button_0",
2546 xmToggleButtonWidgetClass,
2549 XtAddCallback(me->ready_radio, XmNvalueChangedCallback,
2550 SizeCtlReadyChangedCB, (XtPointer)me);
2551 me->supported_radio = XtVaCreateManagedWidget("button_1",
2552 xmToggleButtonWidgetClass,
2555 XtAddCallback(me->supported_radio, XmNvalueChangedCallback,
2556 SizeCtlSupportedChangedCB, (XtPointer)me);
2558 XtManageChild(me->radio_box);
2562 * ------------------------------------------------------------------------
2563 * Name: SizeCtlUpdate
2567 * Update the state of the size control
2575 SizeCtlUpdate(SizeCtl* me)
2577 Boolean frame_label_sensitive = False;
2578 Boolean list_box_sensitive = False;
2579 Boolean list_box_traverse = False;
2580 Boolean ready_radio_sensitive = False;
2581 Boolean supported_radio_sensitive = False;
2583 * clear the current list
2585 XmListDeleteAllItems(me->list_box);
2587 if(me->single_size_mode)
2590 PdmOid oid = me->selected_size;
2593 XmStringCreateLocalized((char*)
2594 DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
2596 PdmOidDefaultMsg(oid)));
2597 XmListAddItem(me->list_box, item, 0);
2598 XmListSelectPos(me->list_box, 0, False);
2601 if(me->selected_list != SIZECTL_UNSUPPORTED)
2603 frame_label_sensitive = True;
2604 list_box_sensitive = True;
2605 me->selected_list = SIZECTL_SIZES_READY;
2606 XmToggleButtonSetState(me->ready_radio, True, False);
2607 XmToggleButtonSetState(me->supported_radio, False, False);
2612 if(me->selected_list == SIZECTL_UNSUPPORTED)
2614 XmString default_item;
2617 XmStringCreateLocalized((char*)PDM_MSG_SIZE_DEFAULT);
2618 XmListAddItem(me->list_box, default_item, 0);
2619 XmListSelectPos(me->list_box, 0, False);
2620 XmStringFree(default_item);
2628 * set control sensitivities
2630 frame_label_sensitive = True;
2631 supported_radio_sensitive = True;
2632 list_box_sensitive = True;
2633 list_box_traverse = True;
2634 if(PdmOidListCount(me->sizes_ready) > 0)
2635 ready_radio_sensitive = True;
2637 * check to see if the selected size is supported
2639 if(!PdmOidListHasOid(me->sizes_supported, me->selected_size))
2642 * the selected size is not supported
2644 if(PdmOidListCount(me->sizes_ready) > 0)
2647 * use the 1st entry in the ready list
2650 PdmOidListGetOid(me->sizes_ready, 0);
2651 me->selected_list = SIZECTL_SIZES_READY;
2656 * the ready list is empty, use the 1st entry in the
2660 PdmOidListGetOid(me->sizes_supported, 0);
2661 me->selected_list = SIZECTL_SIZES_SUPPORTED;
2664 else if(me->selected_list == SIZECTL_SIZES_READY
2666 !PdmOidListHasOid(me->sizes_ready, me->selected_size))
2669 * the selected size is not in the ready list; use the
2670 * supported list instead
2672 me->selected_list = SIZECTL_SIZES_SUPPORTED;
2675 * set the appropriate radio button and update the list
2677 if(me->selected_list == SIZECTL_SIZES_READY)
2679 XmToggleButtonSetState(me->ready_radio, True, False);
2680 XmToggleButtonSetState(me->supported_radio, False, False);
2682 list = me->sizes_ready_xmstr;
2683 count = PdmOidListCount(me->sizes_ready);
2684 pos = 1 + PdmOidListGetIndex(me->sizes_ready,
2689 XmToggleButtonSetState(me->supported_radio, True, False);
2690 XmToggleButtonSetState(me->ready_radio, False, False);
2692 list = me->sizes_supported_xmstr;
2693 count = PdmOidListCount(me->sizes_supported);
2694 pos = 1 + PdmOidListGetIndex(me->sizes_supported,
2697 XmListAddItemsUnselected(me->list_box, list, count, 0);
2698 SetListBoxSelection(me->list_box, pos);
2702 * update control sensitivities
2704 XtSetSensitive(me->frame_label, frame_label_sensitive);
2705 XtSetSensitive(me->list_box, list_box_sensitive);
2706 XtVaSetValues(me->list_box, XmNtraversalOn, list_box_traverse, NULL);
2707 XtSetSensitive(me->ready_radio, ready_radio_sensitive);
2708 XtSetSensitive(me->supported_radio, supported_radio_sensitive);
2712 * ------------------------------------------------------------------------
2713 * Name: SizeCtlResizeCB
2725 SizeCtlResizeCB(Widget w, XtPointer client_data, XtPointer call_data)
2727 SizeCtl* me = (SizeCtl*)client_data;
2728 Dimension height, width, margin_width, new_width;
2729 Position list_x, list_y, radio_x, radio_y;
2730 Dimension list_h, list_w, radio_h, radio_w;
2731 Widget scrolled_list = XtParent(me->list_box);
2733 * get current layout info
2735 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
2736 XmNmarginWidth, &margin_width,
2738 XtVaGetValues(scrolled_list, XmNheight, &list_h, XmNwidth, &list_w, NULL);
2739 XtVaGetValues(me->radio_box, XmNheight, &radio_h, XmNwidth, &radio_w,
2742 * position controls side by side
2744 list_x = margin_width;
2745 radio_x = list_x + list_w;
2749 list_y = (height - list_h) / 2;
2750 radio_y = (height - radio_h) / 2;
2754 XtVaSetValues(scrolled_list, XmNx, list_x, XmNy, list_y, NULL);
2755 XtVaSetValues(me->radio_box, XmNx, radio_x, XmNy, radio_y, NULL);
2757 * update drawing area width and height
2759 new_width = list_x + list_w + radio_w;
2760 if(new_width > width)
2761 XtVaSetValues(w, XmNwidth, new_width, NULL);
2765 * ------------------------------------------------------------------------
2766 * Name: SizeCtlSetSingleSizeMode
2778 SizeCtlSetSingleSizeMode(SizeCtl* me, PdmOid size)
2780 if(size != pdmoid_none)
2782 me->single_size_mode = True;
2783 me->selected_size = size;
2789 * ------------------------------------------------------------------------
2790 * Name: SizeCtlSetMultiSizeMode
2802 SizeCtlSetMultiSizeMode(SizeCtl* me)
2804 me->single_size_mode = False;
2811 * ------------------------------------------------------------------------
2812 * Name: SizeCtlGetSize
2824 SizeCtlGetSize(SizeCtl* me)
2826 if(me->single_size_mode || me->selected_list == SIZECTL_UNSUPPORTED)
2829 return me->selected_size;
2833 * ------------------------------------------------------------------------
2834 * Name: SizeCtlReadyChangedCB
2846 SizeCtlReadyChangedCB(Widget w,
2847 XtPointer client_data,
2848 XtPointer call_data)
2850 XmToggleButtonCallbackStruct* cbs =
2851 (XmToggleButtonCallbackStruct*)call_data;
2855 SizeCtl* me = (SizeCtl*)client_data;
2856 me->selected_list = SIZECTL_SIZES_READY;
2857 if(!PdmOidListHasOid(me->sizes_ready, me->selected_size))
2858 me->selected_size = pdmoid_none;
2864 * ------------------------------------------------------------------------
2865 * Name: SizeCtlSupportedChangedCB
2877 SizeCtlSupportedChangedCB(Widget w,
2878 XtPointer client_data,
2879 XtPointer call_data)
2881 XmToggleButtonCallbackStruct* cbs =
2882 (XmToggleButtonCallbackStruct*)call_data;
2886 SizeCtl* me = (SizeCtl*)client_data;
2887 me->selected_list = SIZECTL_SIZES_SUPPORTED;
2893 * ------------------------------------------------------------------------
2894 * Name: SizeCtlSelectCB
2906 SizeCtlSelectCB(Widget w,
2907 XtPointer client_data,
2908 XtPointer call_data)
2910 XmListCallbackStruct* cbs = (XmListCallbackStruct*)call_data;
2911 SizeCtl* me = (SizeCtl*)client_data;
2913 if(!me->single_size_mode)
2915 switch(me->selected_list)
2917 case SIZECTL_SIZES_READY:
2919 PdmOidListGetOid(me->sizes_ready, cbs->item_position - 1);
2921 case SIZECTL_SIZES_SUPPORTED:
2923 PdmOidListGetOid(me->sizes_supported, cbs->item_position - 1);
2930 * ------------------------------------------------------------------------
2931 * Name: CreateOptionMenuPulldown
2943 CreateOptionMenuPulldown(String pulldown_name,
2945 XtCallbackProc activate_proc,
2946 XtPointer user_data,
2947 XmString* item_list,
2951 Widget cascade_button;
2953 Widget initial_selected = (Widget)NULL;
2955 char button_name[48];
2959 XmCreatePulldownMenu(XtParent(option_menu), pulldown_name, NULL, 0);
2961 for(i = 0; i < item_count; i++)
2963 sprintf(button_name, "button_%d", i);
2964 button = XtVaCreateManagedWidget(button_name,
2965 xmPushButtonGadgetClass,
2967 XmNuserData, user_data,
2968 XmNlabelString, item_list[i],
2970 if(activate_proc != (XtCallbackProc)NULL)
2971 XtAddCallback(button, XmNactivateCallback,
2972 activate_proc, (XtPointer)i);
2973 if(i == initial_item)
2974 initial_selected = button;
2976 XtVaSetValues(option_menu,
2977 XmNsubMenuId, pulldown,
2978 XmNmenuHistory, initial_selected,
2985 * ------------------------------------------------------------------------
2986 * Name: CreateXmStringsFromOidList
2998 CreateXmStringsFromOidList(const PdmOidList* list)
3000 int count = PdmOidListCount(list);
3001 XmString* xmstr_list = (XmString*)NULL;
3009 * build a list of Xm strings for the passed PdmOidList
3011 xmstr_list = (XmString*)XtCalloc(count, sizeof(XmString));
3012 for(i = 0; i < count; i++)
3014 oid = PdmOidListGetOid(list, i);
3015 str = DTPDM_GETMESSAGE(PdmOidMsgSet(oid),
3017 PdmOidDefaultMsg(oid));
3018 xmstr_list[i] = XmStringCreateLocalized((char*)str);
3025 * ------------------------------------------------------------------------
3026 * Name: FreeXmStringList
3038 FreeXmStringList(XmString* list, int count)
3042 for(i = 0; i < count; i++)
3043 XmStringFree(list[i]);
3044 XtFree((char*)list);
3048 * ------------------------------------------------------------------------
3049 * Name: IconMaxDimension
3061 IconMaxDimension(Widget icon_label,
3062 PdmPixmapList* pixmap_list, int i,
3063 Dimension* max_width, Dimension* max_height)
3065 Dimension width, height;
3067 * set the pixmap in the label
3069 XtVaSetValues(icon_label,
3070 XmNlabelPixmap, PdmPixmapListGetPixmap(pixmap_list, i),
3073 * get the label dimensions
3075 XtVaGetValues(icon_label,
3080 * update the max dimensions
3082 if(width > *max_width)
3084 if(height > *max_height)
3085 *max_height = height;
3089 * ------------------------------------------------------------------------
3090 * Name: PdmPixmapListNew
3101 static PdmPixmapList*
3102 PdmPixmapListNew(int count,
3106 PdmPixmapList* me = (PdmPixmapList*)XtCalloc(1, sizeof(PdmPixmapList));
3108 me->pixmap = (Pixmap*)XtCalloc(count, sizeof(Pixmap));
3109 me->image_name = (char**)XtCalloc(count, sizeof(char*));
3110 me->screen = XtScreen(w);
3113 Widget xmscr = XmGetXmScreen(me->screen);
3114 XtVaGetValues(xmscr, XmNinsensitiveStippleBitmap, &me->stipple, NULL);
3121 XmNforeground, &me->foreground,
3122 XmNbackground, &me->background,
3129 * ------------------------------------------------------------------------
3130 * Name: PdmPixmapListDelete
3142 PdmPixmapListDelete(PdmPixmapList* me)
3144 if(me != (PdmPixmapList*)NULL)
3147 for(i = 0; i < PdmPixmapListCount(me); i++)
3149 if(me->pixmap[i] != (Pixmap)NULL)
3151 if(me->stipple == None)
3153 if(me->pixmap[i] != None)
3154 XmDestroyPixmap(me->screen, me->pixmap[i]);
3158 if(me->pixmap[i] != None)
3159 XFreePixmap(DisplayOfScreen(me->screen),
3162 XtFree((char*)me->image_name[i]);
3165 XtFree((char*)me->pixmap);
3166 XtFree((char*)me->image_name);
3172 * ------------------------------------------------------------------------
3173 * Name: PdmPixmapSetImageName
3185 PdmPixmapListSetImageName(PdmPixmapList* me,
3186 const char* image_name,
3189 me->image_name[i] = XtNewString(image_name);
3193 * ------------------------------------------------------------------------
3194 * Name: PdmPixmapListGetPixmap
3206 PdmPixmapListGetPixmap(PdmPixmapList* me, int i)
3208 if(me->pixmap[i] == None)
3210 me->pixmap[i] = XmGetPixmap(me->screen, me->image_name[i],
3211 me->foreground, me->background);
3212 if(me->pixmap[i] == XmUNSPECIFIED_PIXMAP)
3214 me->pixmap[i] == None;
3216 else if(me->stipple != None)
3218 Pixmap xmpixmap = me->pixmap[i];
3219 Display* display = DisplayOfScreen(me->screen);
3222 unsigned int width, height, border_width, depth;
3226 * make a copy of the pixmap cached by motif
3228 XGetGeometry(display, xmpixmap, &root, &x, &y,
3229 &width, &height, &border_width, &depth);
3231 XCreatePixmap(display, xmpixmap, width, height, depth);
3232 gc = XCreateGC(display, me->pixmap[i], (unsigned long)0, &values);
3233 XCopyArea(display, xmpixmap, me->pixmap[i], gc,
3234 0, 0, width, height, 0, 0);
3238 XSetFillStyle(display, gc, FillStippled);
3239 XSetStipple(display, gc, me->stipple);
3240 XFillRectangle(display, me->pixmap[i], gc, 0, 0, width, height);
3244 XFreeGC(display, gc);
3245 XmDestroyPixmap(me->screen, xmpixmap);
3248 return me->pixmap[i];
3252 * ------------------------------------------------------------------------
3253 * Name: SetListBoxSelection
3264 SetListBoxSelection(Widget list_box, int position)
3266 int visible_item_count;
3269 int first_visible_pos;
3271 * Scroll the list, making the item at the indicated position
3272 * visible in the center of the list box, and make
3273 * it the initial selection.
3275 XtVaGetValues(list_box,
3276 XmNitemCount, &item_count,
3277 XmNvisibleItemCount, &visible_item_count,
3280 if(item_count > visible_item_count)
3282 middle_offset = (visible_item_count+1) / 2;
3283 if(position > middle_offset)
3284 if(position > item_count - middle_offset)
3285 first_visible_pos = item_count - visible_item_count +1;
3287 first_visible_pos = position - middle_offset + 1;
3289 first_visible_pos = 1;
3290 XmListSetPos(list_box, first_visible_pos);
3294 XmListSelectPos(list_box, position, False);
3296 XmListDeselectAllItems(list_box);
3300 * ------------------------------------------------------------------------
3301 * Name: GetIconFileName
3312 GetIconFileName(Widget w, String resource_name)
3314 String icon_file_name;
3315 XtResource res_struct;
3317 res_struct.resource_name = resource_name;
3318 res_struct.resource_class = resource_name;
3319 res_struct.resource_type = XmRString;
3320 res_struct.resource_size = sizeof(String);
3321 res_struct.resource_offset = 0;
3322 res_struct.default_type = XmRImmediate;
3323 res_struct.default_addr = (XtPointer)NULL;
3324 XtGetApplicationResources(w, (XtPointer)&icon_file_name,
3325 &res_struct, 1, (ArgList)NULL, 0);
3327 return icon_file_name;