[comp.windows.x.motif] XmList doesn't work

george@osc.COM (George Baggott) (01/15/91)

I've been trying for the past few days to create a scrolled list with a
certain width and height but cannot do it.  Depending on exactly how I code,
either the list will only be one line in height, the program will segmentation
fault when the list gets the input focus, or the program will segmentatation
fault when I click on an item in the list.  Can anyone out there help me out?

I'm working on a Sun 3/80 with X11R4, Motif 1.1, and C++.  Below, I have
appended a short test program and the gdb stack trace from the core dump
it produces when it gets the input focus.


George

-------------------------------------------------------------------------------
The code:
-------------------------------------------------------------------------------

#define XTFUNCPROTO
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/List.h>
#include <Xm/ScrolledW.h>
#include <Xm/BulletinB.h>

#include <stream.h>

void
main(Cardinal argc, String *argv)
{
    XtAppContext appContext;
    Widget topLevel = XtAppInitialize(&appContext, "Bug Demo",
        NULL, 0, &argc, argv, NULL, NULL, 0);

    Widget bulletinBoard = XtVaCreateManagedWidget(
        "test_bulletin_board", xmBulletinBoardWidgetClass, topLevel,
        XmNx, (Position)0,
        XmNy, (Position)0,
        XmNwidth, (Dimension)300,
        XmNheight, (Dimension)300,
        NULL);

    Arg args[10];
    int argCount = 0;
    XtSetArg(args[argCount], XmNselectionPolicy, XmMULTIPLE_SELECT); argCount++;
    XtSetArg(args[argCount], XmNx, (Position)10); argCount++;
    XtSetArg(args[argCount], XmNy, (Position)10); argCount++;
    XtSetArg(args[argCount], XmNwidth, (Dimension)280); argCount++;
    XtSetArg(args[argCount], XmNheight, (Dimension)280); argCount++;

    Widget listWidget =
        XmCreateScrolledList(bulletinBoard, "test_list", args, argCount);
    XtManageChild(listWidget);

    for (int i = 0; i < 5; ++ i) {
        XmString string
            = XmStringCreate(form("item #%d", i), XmSTRING_DEFAULT_CHARSET);
        XmListAddItem(listWidget, string, 0);
        XmStringFree(string);
    }

    XtRealizeWidget(topLevel);

    XtAppMainLoop(appContext);
}

-------------------------------------------------------------------------------
Stack trace of the core dump:
-------------------------------------------------------------------------------

#0  0xdbe0 in XmCreateLabelGadget ()
#1  0x113da in XmCreateLabelGadget ()
#2  0x76534 in _XtTranslateEvent ()
#3  0x5fa52 in XtWindowToWidget ()
#4  0x60800 in _XtSendFocusEvent ()
#5  0x66446 in _XtHandleFocus ()
#6  0x66722 in XtSetKeyboardFocus ()
#7  0x33afa in _XmMgrTraversal ()
#8  0x33644 in _XmMgrTraversal ()
#9  0x33588 in _XmMgrTraversal ()
#10 0x34412 in XmProcessTraversal ()
#11 0x10468 in XmCreateLabelGadget ()
#12 0x76534 in _XtTranslateEvent ()
#13 0x5fa52 in XtWindowToWidget ()
#14 0x6018c in _XtOnGrabList ()
#15 0x60256 in XtDispatchEvent ()
#16 0x6053e in XtAppMainLoop ()
#17 0x29e4 in main (...) (...)