cunixx11motif

Why am I getting uneven vertical padding in a Motif Widget List?


I am using a Motif Widget Scrolledlist. The list is created as follows:

/* COMMAND GROUP LIST */
ac = 0;
XtSetArg(al[ac], XmNselectionPolicy, XmSINGLE_SELECT); ac++;
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
XtSetArg(al[ac], XmNtopWidget, printer_menu_button); ac++;
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
XtSetArg(al[ac], XmNbottomPosition, 50); ac++;
command_group_list = XmCreateScrolledList(form, "command_group_list", al, ac);
XtManageChild(command_group_list);

the items are added by a callback function when the printer is selected. from the routine adding the items the only relevant Motif-related commands are:

XmListDeleteAllItems(command_group_list);
...
str = XmStringCreateLocalized(command_group_line);
XmListAddItem(command_group_list, str, 0); 
XmStringFree(str);

However, when I display the list I get a weird bottom padding, seems like the height of each individual item of the list is larger than the height of the text. This can be seen in this image:

Motif Widget List

While in the documentation (for example O'Reilly Volume Six A) the list's items appear to have a "normal" height. I do not know what there could be missing. I have reviewed if the sample code in 6A apply more resources to the list but I can not find anything.

For example, this list screenshot, extracted from 6A shows how the height is what you would normally expect in a list:

enter image description here

I am using FreeBSD and OpenMotif 2.3.8_1.

Could it be a font issue?

UPDATE: this is the whole routine that adds the items, as stated above, the only Motif/X11 code are the Xm functions deleting all items and adding individual items in a for loop.

This is the routine which populates the items (note that mostly is C code non-related to the actual Motif issue):

/* THIS FUNCTION READS COMMAND GROUPS USED BY THIS PRINTER */
void read_command_group(char *printer_name) {

    /* BUILD FILE PATH */
    char filepath[256];
    strcpy(filepath, "/etc/xcmdprinter/");
    strcat(filepath, printer_name);

    /* OPEN AND READ FILE */
    char line[256];
    FILE *fp = fopen(filepath, "r");
    while(fgets(line, sizeof(line), fp)) {
        if(line[0]=='G') {
            XmString str;
            char command_group_line[256];
            int i=2;
            while(line[i]!='\0') {
                command_group_line[i-2] = line[i];
                i++;
            }
            command_group_line[i-2] = '\0';
            str = XmStringCreateLocalized(command_group_line);
            XmListAddItem(command_group_list, str, 0); 
            XmStringFree(str);
        }
    }
    fclose(fp);

}

/* CALLBACK FUNCTION FOR PRINTER SELECTION */
void select_printer(Widget w, XtPointer client_data, XtPointer call_data) {

    XmListDeleteAllItems(command_group_list);
    read_command_group((char *)client_data);
}

Solution

  • Each item contains a newline character; remove it.

    I am also wondering why the focus is displayed with such a strong dotted line.

    That is set by the list widget's resource XmNhighlightThickness, whose default value is 2.