1

I have the following code, which is basically an option menu inside a form in Motif.

#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>

Widget make_menu_item(char *item_name, Widget menu);

/* XT/XM RELATED VARIABLES */
XtAppContext context;
XmStringCharSet char_set = XmSTRING_DEFAULT_CHARSET;

/* WIDGETS */
Widget toplevel; 
Widget form;
Widget pulldown_menu;
Widget option_menu;
Widget option_item[100];
int option_items = 0;

int main(int argc, char *argv[]) {

    Arg al[10];
    int ac;

    /* CREATE TOP SHELL WIDGET */
    toplevel = XtAppInitialize(&context, "", NULL, 0, &argc, argv, NULL, NULL, 0);

    /* RESIZE TOP LEVEL*/
    ac = 0;
    XtSetArg(al[ac], XmNheight, 900); ac++;
    XtSetArg(al[ac], XmNwidth, 600); ac++;
    XtSetValues(toplevel, al, ac);

    /* CREATE FORM MANAGER WIDGET */
    form = XmCreateForm(toplevel, "form", al, ac);
    XtManageChild(form);

    /* PULLDOWN MENU */
    ac = 0;
    pulldown_menu = XmCreatePulldownMenu(form, "pulldown_menu", al, ac);

    ac = 0;
    XtSetArg(al[ac], XmNsubMenuId, pulldown_menu); ac++;
    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
    XtSetArg(al[ac], XmNlabelString, XmStringCreate("Pulldown Menu", char_set)); ac++;
    option_menu = XmCreateOptionMenu(form, "option_menu", al, ac);
    XtManageChild(option_menu);
    make_menu_item("FOO", pulldown_menu);
    make_menu_item("BAR", pulldown_menu);

    /* REALIZE TOPLEVEL */
    XtRealizeWidget(toplevel);
    XtAppMainLoop(context);

    return 0;

}

Widget make_menu_item(char *item_name,  Widget menu) {

    int ac;
    Arg al[10];
    Widget item;

    ac = 0;
    XtSetArg(al[ac], XmNlabelString, XmStringCreateLtoR(item_name, char_set)); ac++;
    item = XmCreatePushButton(menu, item_name, al, ac);
    XtManageChild(item);
    /*XtAddCallback(item, XmNactivateCallback, menuCB, client_data);*/
    XtSetSensitive(item, True);
    return(item);

}

I tried to stretch the option menu created with XmCreateOptionMenu by using:

    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;

However, the end result is that the Option Menu is not streched.

Is it possible to achieve that with an Option Menu?

My expectation would be seeing the OptionMenu pulldown button using the whole width of the parent form.

OptionMenu Stretch

M.E.
  • 4,955
  • 4
  • 49
  • 128
  • 1
    If your objective is create a Menubar, then I would suggest to use the a Menubar. Option Menus are a composite widget which stretch to the longest option. The Dan Heller book may assist you on Programing with Motif http://www.ist.co.uk/motif/download/6A/6A_book.pdf – PaulB Apr 07 '21 at 18:15
  • My objective would be just to align the OptionMenu's width to the width of the form, as it can be often be done in other Widgets (for example http://www.java2s.com/Code/CSharp/GUI-Windows-Form/ComboBoxwithcolorcellrenderer.htm), I understand from your comment that it can not be done. Regarding the book thanks for the link I was using a hard copy of O'Reilly X Window System guides and "Motif Programming The Essentials and More" from Marshall Brain. As Motif resources began to be scarce any book suggestion is welcomed. Online resources began to be offline too (such as Kenton Lee page). – M.E. Apr 08 '21 at 08:22
  • 1
    I'd think it was possible to at least force it to change size as the class does have a `XmNwidth` resource (I think all mappable widgets do), but I did not succeed. Anyway, I have collected a fair amount of those scarce materials and proposed a [tag edit](https://stackoverflow.com/review/suggested-edits/28611667). There I have also added Lee's page thanks to the Web Archive. – Quasímodo Apr 08 '21 at 20:48

0 Answers0