Next: Grouping Toggles Up: Toggle Widgets Previous: Toggle Callbacks

The toggle.c program

This program sets up two CheckBox Toggles in a RowColumn Widget. When their Callbacks are activated the state of the Toggle is interrogated and a message is printed to standard output.


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


main(int argc, char **argv)

{
    Widget toplevel, rowcol, toggle1, toggle2;
    XtAppContext app;
    void toggle1_cbk(), toggle2_cbk();

    toplevel = XtVaAppInitialize(&app, "Toggle", NULL, 0,
        &argc, argv, NULL, NULL);

    rowcol = XtVaCreateWidget("rowcol",
        xmRowColumnWidgetClass, toplevel, 
        XmNwidth, 300,
        XmNheight, 200,
        NULL);


    toggle1 = XtVaCreateManagedWidget("Dolby ON/OFF",
        xmToggleButtonWidgetClass, rowcol, NULL);
        
    XtAddCallback(toggle1, XmNvalueChangedCallback, 
                  toggle1_cbk, NULL);
    
    toggle2 = XtVaCreateManagedWidget("Dolby B/C",
            xmToggleButtonWidgetClass, rowcol, NULL);
        
    XtAddCallback(toggle2, XmNvalueChangedCallback, 
                  toggle2_cbk, NULL);
    XtManageChild(rowcol);
    XtRealizeWidget(toplevel);
    XtAppMainLoop(app);
}


void toggle1_cbk(Widget widget, XtPointer client_data,
XmToggleButtonCallbackStruct *state)

{  printf("%s: %s\n", XtName(widget), 
            state->set? "on" : "off");
}


void
toggle2_cbk(Widget widget, XtPointer client_data, 
XmToggleButtonCallbackStruct *state)

{ printf("%s: %s\n", XtName(widget), state->set? "B" : "C");
}


Dave.Marshall@cm.cf.ac.uk
Tue May 24 16:52:56 BST 1994