1

I have a compiling and working program, but I can't figure out how to place the buttons anywhere other than the top left.

Do I need to specify the location in rowcol (like I am now), or do I specify the position of each button when I assign them using XtCreateManagedWidget?

Note that I have callbacks declared, but I'm not including them as they are working.

#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/ToggleB.h>
#include <Xm/RowColumn.h>

int main(int argc, char **argv)
{
  Widget shell, rowcol, toggle1, toggle2;
  XtAppContext app;

  //Set the window's size at 300x300
  shell = XtVaAppInitialize(&app, "Radio", NULL, 0, &argc, argv, NULL, 
            XmNwidth, 300, XmNheight, 300, NULL);

  //I want the buttons to start at 100x100
  rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, shell, 
            XmNx, 100, XmNy, 100, NULL);

  XtManageChild(rowcol);

  //Add the buttons & callbacks
  toggle1 = XtCreateManagedWidget("Switch1", xmToggleButtonWidgetClass, rowcol, NULL, 0);
  XtAddCallback(toggle1, XmNvalueChangedCallback, toggle1_cbk, NULL);

  toggle2 = XtCreateManagedWidget("Switch2", xmToggleButtonWidgetClass, rowcol, NULL, 0);
  XtAddCallback(toggle2, XmNvalueChangedCallback, toggle2_cbk, NULL);

  //Starts everything up
  XtRealizeWidget(shell);
  XtMainAppLoop(app);

  return 0;
}

1 Answers1

0

Put your widget in a BulletinBoard.

frame = XtVaCreateWidget("frame", xmBulletinBoardWidgetClass, shell, 
                         XmNwidth, 300, XmNheight, 300, NULL);

rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, frame,
                          XmNx, 100, XmNy, 100, NULL);

XtManageChild(frame);
XtManageChild(rowcol);

The immediate child of the shell is special. Setting its X and Y doesn't position the child within the shell, but rather the shell itself. In addition, many widgets ignore X and Y positions of their children. But BulletinBoard does not.

From the Motif manual:

BulletinBoard is a general-purpose manager that allows children to be placed at arbitrary x, y positions.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • I made the updates, but now I get "Error: XtMakeGeometryRequest - parent has no geometry manager" on runtime. – user3704313 Aug 21 '14 at 19:50
  • [This](http://pastebin.com/wxTg5ptP) is the complete program I have tested. No such error is reported. – n. m. could be an AI Aug 21 '14 at 19:51
  • I just tried copy/pasting the code from your pastebin and I'm still getting the error. I'm running on an old Solaris machine, if that changes anything? – user3704313 Aug 21 '14 at 20:20
  • Perhaps your Motif or Xt version is older than mine. Maybe your composite widget class implementation has no geometry manager (a different Xt implementation). Try to use `xmBulletinBoardWidgetClass` instead of `compositeWidgetClass` (header file is `Xm/BulletinB.h`). This is a Motif widget made just for such cases. If it works for you I will update the answer. It does work for me [here](http://pastebin.com/zmp6YNwW). – n. m. could be an AI Aug 21 '14 at 20:50
  • That fixed it! Looks like I have an older version after all. – user3704313 Aug 21 '14 at 20:52