gates@IPSUN.LARC.NASA.GOV (Ray Gates) (08/23/89)
Forgive me if this message gets posted more than once (Mailer problems).
HELP!!!!!
Does anyone have an example program (or code segment) that will show me how
to setup an Athena list widget (with multiple list items)???? Thanks in advance.
_______________________________________________________________________________
"Mama, mama, many worlds | Ray Gates
I've seen since I first | CSC/NASA-Langley
left home." | gates@ipsun.larc.nasa.gov
| 804.865.1725
-------------------------------------------------------------------------------
DISCLAIMER: The comments/opinions contained within are my own and do not
necessarily represent the opinions of my employer(s).
-------------------------------------------------------------------------------
kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (08/25/89)
> HELP!!!!! > Does anyone have an example program (or code segment) that will show me how > to setup an Athena list widget (with multiple list items)???? Thanks in advance. Take a look at "clients/xman" this application uses a List widget. Chris D. Peterson MIT X Consortium Net: kit@expo.lcs.mit.edu Phone: (617) 253 - 9608 Address: MIT - Room NE43-213
mlm@odi.com (Mitchell Model) (08/28/89)
HELP!!!!! Does anyone have an example program (or code segment) that will show me how to setup an Athena list widget (with multiple list items)???? Thanks in advance. Here is the source for a popup menu facility that uses the Athena list widget. Select(stringlist) takes a null-terminated lists of strings, popsup a menu showing the strings, waits for the user to select one, then returns the index of the selection. Menu(stringlist, fnlist) is takes a list of strings and a parallel list of (pointers to) functions; when a selection is made, the corresponding function is invoked. The code is entwined in an application. I've tried to provide an independent version here, but haven't spent much time verifying it. If you need a function or declaration that isn't here let me know. (In particular, display, screen_num, and top are application-global #definevariables.) /*******************************************************************/ /* */ /* menu.c */ /* */ /* Popup Menu */ /* */ /*******************************************************************/ #include <X11/StringDefs.h> #include <X11/Intrinsic.h> #include <X11/Shell.h> #include <X11/List.h> static int root_x, root_y, child_x, child_y, buttons; static void (**MFNS)(); /* fake closure */ #define warpx 9 /* hacks to start cursor within */ #define warpy 38 /* menu at at second item */ /* (I often place CANCEL first.) */ #define SetArg(which, val) {XtSetArg(args[nargs], (which), ((XtArgVal) val));\ nargs++;} static Widget shell; /* ARGSUSED */ void DoMenuItem(w, user_data, arg) Widget w; caddr_t user_data; XtListReturnStruct *arg; { XtPopdown(shell); XWarpPointer(display, None, root, 0, 0, 0, 0, root_x, root_y); /* return pointer to where it was before the menu was popped */ XtDestroyWidget(shell); (MFNS[arg->index])(); } static XtCallbackRec menucb[] = { {DoMenuItem, NULL}, {NULL, NULL} }; /* popup the shell making sure it is all on the screen */ void popup_shell(dshell) Widget dshell; { static Arg args[] = { {XtNx, NULL}, {XtNy, NULL}, {XtNwidth, NULL}, {XtNheight, NULL }, }; int n, leftx, upy; XtRealizeWidget(dshell); for (n=0; n<4; n++) args[n].value = NULL; /* not sure why need; breaks without, though */ XtGetValues(dshell,args,4); leftx = args[0].value - (XDisplayWidth(display, screen_num) - args[2].value); upy = args[1].value - (XDisplayHeight(display, screen_num) - args[3].value); if (leftx <= 0) leftx = 0; else args[0].value -= leftx; if (upy < 0) upy = 0; else args[1].value -= upy; if (leftx || upy) XtSetValues(dshell,args,2); XtPopup(dshell, XtGrabExclusive); if (leftx || upy) XWarpPointer(display, None, root, 0, 0, 0, 0, root_x - leftx, root_y - upy); } void Menu(strings, fns) String strings[]; void (*fns[])(); { static Arg args[10]; static int nargs; MFNS = fns; XQueryPointer(display, XtWindow(top), &root, &child, &root_x, &root_y, &child_x, &child_y, &buttons); nargs = 0; SetArg(XtNx, root_x-warpx); SetArg(XtNy, root_y-warpy); SetArg(XtNinput, True); shell = XtCreatePopupShell("actionMenuShell", transientShellWidgetClass, top, args, nargs); nargs = 0; SetArg(XtNlist, strings); SetArg(XtNcallback, menucb); SetArg(XtNdefaultColumns, 1); XtCreateManagedWidget("actionMenu", listWidgetClass, shell, args, nargs); popup_shell(shell); } static int INDEX; static Bool POPPED; /* ARGSUSED */ void Selection(w, user_data, arg) Widget w; caddr_t user_data; /* want this to be shell, but can't set */ XtListReturnStruct *arg; { XtPopdown(shell); XWarpPointer(display, None, root, 0, 0, 0, 0, root_x, root_y); XtDestroyWidget(shell); INDEX = arg->index; POPPED = False; } static XtCallbackRec selectcb[] = { {Selection, NULL}, {NULL, NULL} }; int Select(strings) String strings[]; { static Arg args[10]; static int nargs; XQueryPointer(display, XtWindow(top), &root, &child, &root_x, &root_y, &child_x, &child_y, &buttons); nargs = 0; SetArg(XtNx, root_x-warpx); SetArg(XtNy, root_y-warpy); SetArg(XtNinput, True); shell = XtCreatePopupShell("actionMenuShell", transientShellWidgetClass, top, args, nargs); nargs = 0; SetArg(XtNlist, strings); SetArg(XtNcallback, selectcb); SetArg(XtNdefaultColumns, 1); XtCreateManagedWidget("selectionMenu", listWidgetClass, shell, args, nargs); popup_shell(shell); POPPED = True; while (POPPED) ProcessOneEvent(display); return INDEX; } -- Mitchell L Model Director, HeadStart Program Object-Design, Inc., 1 New England Executive Park, Burlington MA 01803 (617) 270-9797
mlm@odi.com (Mitchell Model) (08/28/89)
Regarding the Menu facility I just posted, it should have also
included the following function:
void ProcessOneEvent(display)
Display *display;
{
static XEvent event;
XNextEvent(display, &event);
XtDispatchEvent(&event);
}
Sorry.
--
Mitchell L Model
Director, HeadStart Program
Object-Design, Inc., 1 New England Executive Park, Burlington MA 01803
(617) 270-9797
Jean-Christophe.Dhellemmes@MAPS.CS.CMU.EDU (06/07/90)
Hi X11R4 experts, I am using the Athena toolkit under X11R4 and I am dealing with a "List" widget inside a "Viewport" widget, for which I force a vertical scrollbar. I want to scroll the list up and down and select a line. I am dealing with very long lists: * I have no problem with a moderately sized list (48 elements). * For a long list (1112 elements), the scrolling works OK, but when I try to select elements near the end of the list, they don't appear in reverse video anymore, they disappear instead until another line is clicked on. Eventually, I lose control and have to kill the server... * For a huge list (8395 elements), the scrolling is kind of weird. The thumb in the scroll bar has its minimum thickness (sounds noraml), but the bottom of the view port is reached well before the thumb is at the bottom position (i.e. position 100% is actually about 70%). Selecting lines at the beginning of the list is OK, but as soon as I try selecting a line at the end of the list, I lose control and the server dies badly. Questions: 1) Can somebody explain what's going on ? 2) Is there a (settable) limit to the number of entries in a list widget ? 3) Is it a bug in X11R4 ? Is there a patch for it ? Thanks. * JCD