Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!apollo!uunet!pcrat!rick From: pcrat!rick@uunet.UU.NET (Rick Richardson) Newsgroups: comp.windows.x.motif Subject: Re: Stretchable List Summary: Table Widget Does the Trick Message-ID: <4bbb9c35.20b6d@apollo.HP.COM> Date: 21 Jul 90 15:56:00 GMT References: <1990Jul16.172955.11321@pcrat.uucp> <1990Jul16.223021.11654@pcrat.uucp> <1990Jul17.014256.11899@pcrat.uucp> Sender: root@apollo.HP.COM Reply-To: pcrat!rick@uunet.UU.NET (Rick Richardson) Organization: PC Research, Inc., Tinton Falls, NJ Lines: 307 To: comp-windows-x-motif@uunet.UU.NET In article <1990Jul17.014256.11899@pcrat.uucp> rick@pcrat.UUCP (Rick Richardson) writes: >Actually, what I thought was fixed is really still broken. >I think the solution is to toss the Form widget and get something >else (Table was mentioned). Form seems to be terribly broken. I got the Table widget from the Widget Creation Library, and nazgul@alphalpha.com (Kee Hinckley) sent me the patches to make it Motif-ized. I then recoded my example in C, and included a command line option to use the Table widget instead of the Form widget as the inner widget container. It all works as expected using the Table widget. I've appended the C version in a SHAR file for those who care to try this themselves. Also, the comments indicate the various effects I discovered when trying to use the Form. If the OSF is listening, I now consider the Form to be a broken widget that needs fixing. Also, I couldn't find VARARGS versions of XtCreateManagedWidget() and XtSetValues() in my X11R3 libXt.a, so I've included my own versions of vXtCreateManagedWidget() and vXtSetValues() as well. The method used in all the books is so utterly ugly I couldn't stand it. -Rick Richardson #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # ftm.c # This archive created: Sat Jul 21 11:52:09 1990 export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'ftm.c' then echo shar: "will not over-write existing file 'ftm.c'" else sed 's/^X//' << \SHAR_EOF > 'ftm.c' X/* X * ftm.c X * Test Program for Stretchable List (C version, taken from UIL version) X * X * $ ftm 0 # the children of ScrollForm are not constrained X * $ ftm 1 # the children of ScrollForm are constrained X * $ ftm 2 # Use the PD Table widget instead of a Form for ScrollForm X * X * In the first invocation, everything comes up looking normal, except that X * the first line of the ScrollList is buried under the ScrollHdr. X * X * In the second invocation, the vertical ScrollBar of the List is missing, X * and only about 50% of the first line of the ScrollList is displayed. E.G. X * the letters are clipped. X * X * In the third invocation, everything works. Obviously, Table has much X * better (i.e. working) geometry management for its children. X * X * I would expect the second case to be the proper way to code this, but X * it sure doesn't work right on this system, ISC Motif 1.0, X11R3. X * X * If you don't have the PD Table widget, #define NO_TABLE_WIDGET. X * In that case, ftm 2 (the invocation that works) won't be available. X * X * Rick Richardson, uunet!pcrat!rick, rick@pcrat.pcr.com X */ X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X X#ifndef NO_TABLE_WIDGET X#include "Table.h" X#endif X X/* X * Convenience functions X */ Xextern Widget vXtCreateManagedWidget(); Xextern void vXtSetValues(); X#define ASIZEOF(ARRAY) (sizeof(ARRAY)/sizeof(ARRAY[0])) X#define AV (XtArgVal) X#define XMSC(S) XmStringCreate(S, XmSTRING_DEFAULT_CHARSET) X X/* X * Widget Heirarchy X */ XWidget Top; /* Shell */ XWidget OuterForm; /* Form */ XWidget KillButton; /* PushButton */ XWidget ScrollWindow; /* ScrolledWindow */ XWidget ScrollForm; /* Form or Table */ XWidget ScrollHdr; /* Label */ XWidget ScrollList; /* List */ X X/* X * Strings to use for labels and list X */ X#define KILL_LABEL "Select a Process to Kill and Push Me" X#define SCROLL_HDR \ X " UID PID PPID C STIME TTY TIME COMMAND " X Xstatic char *ListItems[] = X{ X" root 0 0 0 Jul 10 ? 0:03 sched", X" root 1 0 0 Jul 10 ? 3:50 /etc/init ", X" root 2 0 0 Jul 10 ? 4:08 vhand", X" root 3 0 0 Jul 10 ? 3:21 bdflush", X" root 97 1 0 Jul 10 console 0:01 /etc/getty console console ", X" rick 101 1 0 Jul 10 vt01 0:19 -ksh ", X" root 9124 1 0 16:43:46 ttyp0 0:01 /etc/faxsrv ", X" root 9125 9124 0 16:43:46 ttyp0 0:01 faxrun1 -Tjfax -D/dev/jfax0", X" root 9126 9124 0 16:43:46 ttyp0 0:01 faxrun2 -Tbfax -D/dev/bfax0", X" root 9127 9124 0 16:43:47 ttyp0 0:01 faxrun3 -Tbfax -D/dev/bfax1", X" root 9128 9124 0 16:43:47 ttyp0 0:03 faxrun4 -Tefax -D/dev/tty00", X" root 9129 9124 0 16:43:48 ttyp0 0:03 faxrun5 -Tefax -D/dev/tty01", X" root 75 1 0 Jul 10 ? 0:21 /etc/cron ", X" root 79 1 0 Jul 10 ? 0:38 /usr/lib/lpsched ", X" root 6242 1 0 Jul 14 vt02 0:00 /etc/getty /dev/vt02 vt02 ", X" root 6243 1 0 Jul 14 vt03 0:00 /etc/getty /dev/vt03 vt03 ", X" root 6244 1 0 Jul 14 vt04 0:00 /etc/getty /dev/vt04 vt04 ", X" rick 8300 101 0 23:42:07 vt01 0:00 xinit ", X" rick 8301 8300 9 23:42:07 vt05 7:05 X :0 ", X" rick 8302 8300 3 23:42:13 ? 1:27 xterm -geometry 80x24+0+0", X" rick 8303 8302 0 23:42:14 ? 0:23 /usr3/bin/X11/uwm ", X" rick 8304 8302 1 23:42:19 ttyp0 0:09 ksh " X}; X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X XmString *litems; X register int i; X int mode = 0; X X /* X * Convert Strings to Motif format X */ X litems = (XmString *) XtMalloc(ASIZEOF(ListItems) * sizeof(XmString)); X for (i = 0; i < ASIZEOF(ListItems); ++i) X litems[i] = XMSC(ListItems[i]); X X /* X * Create the Widget Heirarchy X */ X Top = XtInitialize(argv[0], argv[0], NULL, 0, &argc, argv); X X if (argc > 1) mode = atoi(argv[1]); X else {fprintf(stderr, "Usage: ftm [0|1|2]\n"); exit(1);} X X OuterForm = vXtCreateManagedWidget("OuterForm", X xmFormWidgetClass, Top, X XtNwidth, AV 300, X XtNheight, AV 200, X (String) NULL); X X KillButton = vXtCreateManagedWidget("KillButton", X xmPushButtonWidgetClass, OuterForm, X XmNtopAttachment, AV XmATTACH_FORM, X XmNleftAttachment, AV XmATTACH_FORM, X XmNrightAttachment, AV XmATTACH_FORM, X XmNlabelString, AV XMSC(KILL_LABEL), X (String) NULL); X X ScrollWindow = vXtCreateManagedWidget("ScrollWindow", X xmScrolledWindowWidgetClass, OuterForm, X XmNtopAttachment, AV XmATTACH_WIDGET, X XmNtopWidget, AV KillButton, X XmNleftAttachment, AV XmATTACH_FORM, X XmNrightAttachment, AV XmATTACH_FORM, X XmNbottomAttachment, AV XmATTACH_FORM, X XmNscrollingPolicy, AV XmAUTOMATIC, X XmNvisualPolicy, AV XmCONSTANT, X /* XmNworkWindow, AV scroll_form,*/ X (String) NULL); X X#ifndef NO_TABLE_WIDGET Xif (mode==2) X ScrollForm = vXtCreateManagedWidget("table", X tableWidgetClass, ScrollWindow, X (String) NULL); Xelse X#endif X ScrollForm = vXtCreateManagedWidget("ScrollForm", X xmFormWidgetClass, ScrollWindow, X (String) NULL); X X ScrollHdr = vXtCreateManagedWidget("ScrollHdr", X xmLabelWidgetClass, ScrollForm, X XmNlabelString, AV XMSC(SCROLL_HDR), X mode == 1 ? X XmNtopAttachment : (String) NULL, X AV XmATTACH_FORM, X XmNleftAttachment, AV XmATTACH_FORM, X (String) NULL); X X ScrollList = vXtCreateManagedWidget("ScrollList", X xmListWidgetClass, ScrollForm, X XmNitems, AV litems, X XmNitemCount, AV ASIZEOF(ListItems), X XmNvisibleItemCount, AV ASIZEOF(ListItems), X mode == 1 ? X XmNtopAttachment : (String) NULL, X AV XmATTACH_WIDGET, X XmNtopWidget, AV ScrollHdr, X XmNleftAttachment, AV XmATTACH_FORM, X XmNrightAttachment, AV XmATTACH_FORM, X XmNbottomAttachment, AV XmATTACH_FORM, X (String) NULL); X X /* X * Now fix up stuff we couldn't specify before X */ X vXtSetValues(ScrollWindow, XmNworkWindow, AV ScrollForm, (String) NULL); X# ifndef NO_TABLE_WIDGET X if (mode == 2) X { X XtTblConfig(ScrollHdr, X /* pos */ 0, 0, X /* span*/ 1, 1, X TBL_SM_HEIGHT); X XtTblConfig(ScrollList, X /* pos */ 0, 1, X /* span*/ 1, 1, X TBL_DEF_OPT); X } X# endif X X XtRealizeWidget(Top); X XtMainLoop(); X} X X/* X * Variable arg list version of XtCreateManagedWidget X */ X/* VARARGS */ XWidget XvXtCreateManagedWidget(va_alist) Xva_dcl X{ X va_list args; X X String name; X String class; X Widget parent; X X# define NXARGS 100 X Arg xargs[NXARGS]; X register int i; X X va_start(args); X name = va_arg(args, String); X class = va_arg(args, String); X parent = va_arg(args, Widget); X X for (i = 0; i < NXARGS; ++i) X { X xargs[i].name = va_arg(args, String); X if (xargs[i].name == NULL) break; X xargs[i].value = va_arg(args, XtArgVal); X } X va_end(args); X return (XtCreateManagedWidget(name, class, parent, xargs, i)); X# undef NXARGS X} X X/* VARARGS */ Xvoid XvXtSetValues(va_alist) Xva_dcl X{ X va_list args; X X Widget w; X X# define NXARGS 100 X Arg xargs[NXARGS]; X register int i; X X va_start(args); X w = va_arg(args, Widget); X X for (i = 0; i < NXARGS; ++i) X { X xargs[i].name = va_arg(args, String); X if (xargs[i].name == NULL) break; X xargs[i].value = va_arg(args, XtArgVal); X } X va_end(args); X XtSetValues(w, xargs, i); X# undef NXARGS X} SHAR_EOF fi exit 0 # End of shell archive -- Rick Richardson | Looking for FAX software for UNIX/386 ??? Ask About: |Mention PC Research,Inc.| FaxiX - UNIX Facsimile System (tm) |FAX# for uunet!pcrat!rick| FaxJet - HP LJ PCL to FAX (Send WP,Word,Pagemaker...)|Sample (201) 389-8963 | JetRoff - troff postprocessor for HP LaserJet and FAX|Output