EditTable Widget WebFAQ - Q14


  /*****************************************************
  Suppose you wnat to attach a pulldown option manu to
  all cells in column one. The pulldown menu consists of
  3 PB widgets each labeled as "one", "two" and "three",
  respectively.
  *****************************************************/
  :
  :
  /* In CreateTargetWidgets() */
  :
  :
  XintCellWidgetRange  range;
  static char *labels[] = {"one", "two", "three"};
  Widget pb[3];
  Widget pulldown_menu, option_menu;
  int i;
  XFontStruct *font;
  XmFontList font_list = NULL;
  XmString cstring;
  :
  Table = XtVaCreateWidget("Table", xintEditTableWidgetClass, Scroll,
                   :
                   :
                   XmNcellSizeUnit,                 XintUNIT_PIXEL,
                   XmNdefaultCellHeight,            30,
                   XmNdefaultCellWidth,             80,

                   :
                   :
                   NULL);
   XtAddCallback(Table, XmNcellWidgetDisplayCallback,
              (XtCallbackProc) CellWidgetDisplayCB, (XtPointer)NULL);

   if ((font = XLoadQueryFont(XtDisplay(Toplevel), "*helvetica*14*")) == NULL)
      font = XLoadQueryFont(XtDisplay(Toplevel), "fixed");

   font_list = XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);

   pulldown_menu = XmCreatePulldownMenu (Scroll, "pulldown_menu", NULL, 0);

   for (i=0; i<3; i++) { n="0;" cstring="XmStringCreateLtoR(labels[i]," XmSTRING_DEFAULT_CHARSET); XtSetArg(arg[n], XmNbackground, XintLoadColor(XtDisplay(Toplevel),"gray")); n++; XtSetArg(arg[n], XmNforeground, XintLoadColor(XtDisplay(Toplevel),"white")); n++; XtSetArg(arg[n], XmNlabelString, cstring); n++; XtSetArg(arg[n], XmNlabelFont, font_list); n++; XtSetArg(arg[n], XmNalignment, XmALIGNMENT_END); n++; pb[i]="XmCreatePushButton(pulldown_menu," labels[i], arg, n); XtManageChild(pb[i]); XmStringFree(cstring); } XtFree((char*)font); XmFontListFree(font_list); range.row="1;" range.rows="0;" range.column="1;" range.columns="1;" n="0;" XtSetArg(arg[n], XmNmenuHistory, pb[0]); n++; XtSetArg(arg[n], XmNsubMenuId, pulldown_menu); n++; XtSetArg(arg[n], XmNcellWidgetRange, &range); n++; XtSetArg(arg[n], XmNcellWidgetSetResources, False); n++; XtSetArg(arg[n], XmNcellWidgetOverrideTranslations, True); n++; XtSetArg(arg[n], XmNwidth, 80); n++; XtSetArg(arg[n], XmNheight, 30); n++; option_menu="XmCreateOptionMenu(Table," "option_menu", arg, n); XtUnmanageChild(XmOptionLabelGadget(option_menu)); : : 

Click here for the Image
Back to EditTable FAQ

© INT 1996.