/* Motif Tutorial - Arrange */ #include #include #include #include #define BUTTONS 5 #define BUTTON_NAME_MAX 20 /** Button push callback * * Called when the user pushes * any of the buttons. * */ void button_pushed(Widget widget, XtPointer data, XmPushButtonCallbackStruct * cbs) { printf("Pushed %s\n", XtName(widget)); } /** Main * * Creates the application window * with a single button and starts * Motif event loop. * */ int main(int argc, char * argv[]) { Widget window; /* Widgets */ Widget rowcol; Widget buttons[BUTTONS]; /* Buttons */ String button_names[BUTTONS]; /* Button names */ XtAppContext app; /* Application */ int i; /* Create application window */ window = XtVaAppInitialize(&app, "Application", NULL, 0, &argc, argv, NULL, NULL); /* Create managed container of widgets */ rowcol = XtVaCreateManagedWidget("Container", xmRowColumnWidgetClass, window, NULL); /* Create several buttons as children of the container and set their callbacks */ for (i = 0; i < BUTTONS; i++) { /* Create button label */ button_names[i] = (String) calloc(BUTTON_NAME_MAX, sizeof(char)); snprintf(button_names[i], BUTTON_NAME_MAX, "Button%d", i); button_names[i][BUTTON_NAME_MAX - 1] = 0; /* Create button */ buttons[i] = XtVaCreateManagedWidget(button_names[i], xmPushButtonWidgetClass, rowcol, NULL); /* Set callback on push event */ XtAddCallback(buttons[i], XmNactivateCallback, (XtCallbackProc) button_pushed, NULL); } /* Display the main window */ XtRealizeWidget(window); /* Motif event loop */ XtAppMainLoop(app); /* Cleanup */ for (i = 0; i < BUTTONS; i++) free(button_names[i]); }