home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / windows / x / 16666 < prev    next >
Encoding:
Text File  |  1992-09-14  |  5.5 KB  |  199 lines

  1. Xref: sparky comp.windows.x:16666 comp.windows.x.motif:6185
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!wupost!micro-heart-of-gold.mit.edu!bu.edu!dartvax!fluent!creare!inb
  3. From: inb@creare.creare.com (Ian Brown)
  4. Newsgroups: comp.windows.x,comp.windows.x.motif
  5. Subject: Too many push buttons?
  6. Message-ID: <BuL16n.L51@creare.creare.com>
  7. Date: 14 Sep 92 19:08:45 GMT
  8. Reply-To: inb@creare.UUCP (Ian Brown)
  9. Organization: Creare Inc., Hanover, NH
  10. Lines: 187
  11.  
  12.  
  13. The program included at the end of this file crashes with core dumps on two
  14. machines (an HP running HPUX 8.0 and a Masscomp, both running Motif 1.1, and
  15. X11R4.)  It appears that trying to create more than about 256 (258 seems to be
  16. the trigger point) children of a row column causes problems in the pulldown
  17. widget code.  Does anyone have any ideas (like, is this an X bug or what)?
  18.  
  19. Compile and link with Motif and X.  To run, type '<program> 774'.  This should
  20. attempt to create 258 push buttons per row column and, for my machines at
  21. least, crashes when I hit the pulldownButton.
  22.  
  23. ------------------------------ cut here ------------------------------
  24. # include    <stdio.h>
  25. # include    <unistd.h>
  26. # include    <math.h>
  27. # include    <X11/Intrinsic.h>
  28. # include    <X11/Shell.h>
  29. # include    <Xm/Xm.h>
  30. # include    <Xm/MainW.h>
  31. # include    <Xm/RowColumn.h>
  32. # include    <Xm/PushB.h>
  33. # include    <Xm/CascadeB.h>
  34. /*
  35.   *****************************************************************
  36.   ***                                ***
  37.   ***    Name :    Xuseful.h    (Useful definitions)        ***
  38.   ***    By   :    Ian Brown    (Creare Inc., Hanover, NH)    ***
  39.   ***    For  :    Games                        ***
  40.   ***    Date :    May, 1992                    ***
  41.   ***                                ***
  42.   ***    Description :                        ***
  43.   ***       Useful X related definitions.            ***
  44.   ***                                ***
  45.   *****************************************************************
  46. */
  47.  
  48. # ifndef Xuseful_defined
  49. #  define Xuseful_defined
  50.  
  51. /*
  52.    Widget Resource Argument macros:
  53.  
  54.    By including this file at the beginning of each module in which argument
  55.    setting is to be done, one can use a global store of arguments, with a
  56.    global argument counter.  Note that since these are global, only one set of
  57.    arguments can be prepared at one time (careful not to nest argument
  58.    setting unless you mean to).  Each time you need to set arguments, call
  59.    INIT_ARGS, followed by SET_ARG calls.  When using a widget creation routine
  60.    or a set or get values routine, use ARGS in place of the argument list and 
  61.    argument counter.
  62.  
  63.    If you are reusing argument lists (perhaps modifying a few resources only
  64.    each time), it may be wiser to create your own.
  65.  
  66.    If not setting any args for a particular call, just call INIT_ARGS and pass
  67.    in ARGS. (Don't forget to call INIT_ARGS).
  68.  
  69.    Make sure not to exceed the ___MAX_ARGS value that you set!
  70. */
  71.  
  72. #  define ___MAX_ARGS        50
  73. #  define INIT_ARGS        (___num_args = 0)
  74. #  define SET_ARG(a,b) \
  75.      { \
  76.         XtSetArg(___args[___num_args], (a), (XtArgVal)(b)); \
  77.         ___num_args++; \
  78.      }
  79. #  define ARGS            ___args, ___num_args
  80.  
  81.    static Arg            ___args[___MAX_ARGS];
  82.    static Cardinal        ___num_args;
  83.  
  84. #  define HandlePendingEvents() \
  85.      { \
  86.         XEvent    event; \
  87.         while (XtPending()) { \
  88.            XtNextEvent(&event); \
  89.            XtDispatchEvent(&event); \
  90.         } \
  91.      }
  92.  
  93. #  define Sensitize(button,state) \
  94.      { \
  95.         ___num_args = 0; \
  96.         XtSetArg(___args[___num_args],XmNsensitive,state); \
  97.         ___num_args++; \
  98.         XtSetValues(button,ARGS); \
  99.      }
  100. # endif
  101.  
  102.  
  103.  
  104.  
  105. static void exitCallback(widget,data1,data2)
  106.  
  107.    Widget    widget;
  108.    caddr_t    data1,
  109.         data2;
  110.  
  111. {
  112.    exit(0);
  113. }
  114.  
  115. main(argc,argv)
  116.  
  117.    int        argc;
  118.    String    argv[];
  119.  
  120. {
  121.    XmString    label;
  122.    char        string[256];
  123.    Widget    shell,
  124.         mainW,
  125.         menuBar,
  126.         workArea,
  127.         workSubAreas[3],
  128.         pulldown,
  129.         button;
  130.    XtAppContext    appcontext;
  131.    Display    *display;
  132.    int        idx,idx1,
  133.         columns;
  134.  
  135.  
  136.    INIT_ARGS;
  137.    shell = XtAppInitialize(&appcontext,"Test",NULL,0,&argc,argv,NULL,ARGS);
  138.    display = XtDisplay(shell);
  139.  
  140.    INIT_ARGS;
  141.    mainW = XmCreateMainWindow(shell,"mainW",ARGS);
  142.  
  143.    INIT_ARGS;
  144.    menuBar = XmCreateMenuBar(mainW,"menuBar",ARGS);
  145.    XtManageChild(menuBar);
  146.  
  147.    INIT_ARGS;
  148.    button = XmCreateCascadeButton(menuBar,"exitButton",ARGS);
  149.    XtManageChild(button);
  150.    XtAddCallback(button,XmNactivateCallback,exitCallback,NULL);
  151.  
  152.    INIT_ARGS;
  153.    pulldown = XmCreatePulldownMenu(menuBar,"pulldownMenu",ARGS);
  154.    for (idx = 0; idx < 4; ++idx) {
  155.       sprintf(string,"pulldownButton%d",idx);
  156.       INIT_ARGS;
  157.       button = XmCreateCascadeButton(pulldown,string,ARGS);
  158.       XtManageChild(button);
  159.    }
  160.    INIT_ARGS;
  161.    SET_ARG(XmNsubMenuId,pulldown);
  162.    button = XmCreateCascadeButton(menuBar,"pulldownButton",ARGS);
  163.    XtManageChild(button);
  164.  
  165.    XtManageChild(menuBar);
  166.  
  167.    INIT_ARGS;
  168.    SET_ARG(XmNpacking,XmPACK_COLUMN);
  169.    workArea = XmCreateRowColumn(mainW,"workArea",ARGS);
  170.    columns = (int) sqrt(atof(argv[1])/3.);
  171.    if (columns > 10)
  172.       columns = 10;
  173.    for (idx1 = 0; idx1 < 3; ++idx1) {
  174.       sprintf(string,"workSubArea%d",idx1);
  175.       INIT_ARGS;
  176.       SET_ARG(XmNpacking,XmPACK_COLUMN);
  177.       SET_ARG(XmNnumColumns,columns);
  178.       SET_ARG(XmNorientation,XmHORIZONTAL);
  179.       workSubAreas[idx1] = XmCreateRowColumn(workArea,string,ARGS);
  180.       for (idx = 0; idx < (atoi(argv[1]) + idx1)/3; ++idx) {
  181.      sprintf(string,"%d%%d",idx1,idx);
  182.      INIT_ARGS;
  183.      button = XmCreatePushButton(workSubAreas[idx1],string,ARGS);
  184.      XtManageChild(button);
  185.       }
  186.    }
  187.    XtManageChildren(workSubAreas,3);
  188.    XtManageChild(workArea);
  189.  
  190.    XmMainWindowSetAreas(mainW,menuBar,NULL,NULL,NULL,workArea);
  191.    XtManageChild(mainW);
  192.    XtRealizeWidget(shell);
  193.  
  194.    XtAppMainLoop(appcontext);
  195. }
  196. -- 
  197. Ian Brown
  198. inb@creare.com
  199.