In C/Motif, how can I control button spaces/sizes in a custom dialog?

Posted on 2004-11-01
Last Modified: 2012-06-27
I've created a custom dialog so that I can include two buttons (yes/no) as well as a toggle box which allows the user to specify not to popup the dialog and instead select yes as the answer every time.  My problem is 1) there's a lot of space between each button causing the overall dialog to be large, and 2) part of the text for the toggleButton is obscured.  What arguments can correct this?

void restart_message (char *question)
  Widget dialog,form,label,pane,yes_button,no_button,always_restart_check;

  if (debug) printf ("Start of restart_message\n");

  dialog = XtVaCreatePopupShell ("Restart",
                         xmDialogShellWidgetClass, GetTopShell (main_window),
                         XmNdeleteResponse, XmDESTROY,
  pane = XtVaCreateWidget ("restart_pane", xmPanedWindowWidgetClass, dialog,
                     XmNsashWidth,  1,
                     XmNsashHeight, 1,
  form = XtVaCreateWidget ("restart_form", xmFormWidgetClass, pane, NULL);
  label = XtVaCreateManagedWidget (question, xmLabelGadgetClass, form,
                           XmNleftAttachment,   XmATTACH_FORM,
                           XmNtopAttachment,    XmATTACH_FORM,
                           XmNrightAttachment, XmATTACH_FORM,
  XtManageChild (form);
  form = XtVaCreateWidget ("action_area", xmFormWidgetClass, pane,
                     XmNwidth,         700,
                     XmNheight,         50,
                     XmNfractionBase,    7,
  yes_button = XtVaCreateManagedWidget ("Yes",
                              xmPushButtonGadgetClass, form,
                              XmNtopAttachment,        XmATTACH_FORM,
                              XmNbottomAttachment,     XmATTACH_FORM,
                              XmNleftAttachment,       XmATTACH_POSITION,
                              XmNleftPosition,         1,
                              XmNrightAttachment,      XmATTACH_POSITION,
                              XmNrightPosition,        2,
                              XmNshowAsDefault,        True,
                              XmNdefaultButtonShadowThickness, 1,
  XtAddCallback (yes_button, XmNactivateCallback, restart_cb, dialog);
  no_button = XtVaCreateManagedWidget ("No",
                               xmPushButtonGadgetClass, form,
                               XmNtopAttachment,        XmATTACH_FORM,
                               XmNbottomAttachment,     XmATTACH_FORM,
                               XmNleftAttachment,       XmATTACH_POSITION,
                               XmNleftPosition,         3,
                               XmNrightAttachment,      XmATTACH_POSITION,
                               XmNrightPosition,        4,
                               XmNshowAsDefault,        False,
                               XmNdefaultButtonShadowThickness, 1,
  XtAddCallback (no_button, XmNactivateCallback, no_restart_cb, dialog);
  always_restart_check = XtVaCreateManagedWidget ("Don't ask, always\nrestart after make",
                                      xmToggleButtonGadgetClass, form,
                                      XmNtopAttachment,        XmATTACH_FORM,
                                      XmNbottomAttachment,     XmATTACH_FORM,
                                      XmNleftAttachment,       XmATTACH_POSITION,
                                      XmNleftPosition,         5,
                                      XmNrightAttachment,      XmATTACH_POSITION,
                                      XmNrightPosition,        6,
                                      XmNshowAsDefault,        False,
                                      XmNdefaultButtonShadowThickness, 1,
  XtAddCallback (always_restart_check,XmNvalueChangedCallback, always_restart_cb, dialog);
  XtManageChild (form);
  XtManageChild (pane);
  XtPopup (dialog, XtGrabNone);
Question by:jimdgar
    LVL 1

    Accepted Solution

    I have found that typically using a form in Motif for things that you desire to be constant in size is generally a bad idea.

    My suggestion would be to place a bulletin-board in the second portion of the frame and lay out the buttons exactly as you want them.

    However, to be completely honest you may be better off tayloring a message box widget because it'll handle the button layout itself and should allow you to add a toggle button to it.  It also aids in enforcing the Motif style guidelines on your application.
    LVL 11

    Assisted Solution

    Try using PushButtonWidgets instead of PushButtonGadgets.  It adds extra windows and increases the size of the program marginally but that may be all you need to get the exact sizes.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now