/* ResourceDemo: appearance comes from Xt's resource database. */
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Protocols.h>

static void quit(Widget w, XtPointer client, XtPointer call)
{
    (void)client; (void)call;
    XtAppSetExitFlag(XtWidgetToApplicationContext(w));
}

int main(int argc, char **argv)
{
    XtAppContext app;
    String fallback[] = {
        "ResourceDemo*title: X resources demo",
        "ResourceDemo*fontList: fixed",
        "ResourceDemo*background: #d4d0c8",
        "ResourceDemo*foreground: #202020",
        "ResourceDemo*panel.marginWidth: 20",
        "ResourceDemo*panel.marginHeight: 20",
        "ResourceDemo*panel.spacing: 14",
        "ResourceDemo*heading.labelString: Resources supply this label",
        "ResourceDemo*quit.labelString: Close",
        NULL
    };
    XtSetLanguageProc(NULL, NULL, NULL);
    Widget shell = XtVaAppInitialize(&app, "ResourceDemo", NULL, 0,
                                    &argc, argv, fallback, NULL);
    Widget panel = XtVaCreateManagedWidget("panel", xmRowColumnWidgetClass,
                                          shell, NULL);
    XtVaCreateManagedWidget("heading", xmLabelWidgetClass, panel, NULL);
    Widget button = XtVaCreateManagedWidget("quit", xmPushButtonWidgetClass,
                                           panel, NULL);
    XtAddCallback(button, XmNactivateCallback, quit, NULL);
    Display *display = XtDisplay(shell);
    XtVaSetValues(shell, XmNdeleteResponse, XmDO_NOTHING, NULL);
    XmAddWMProtocolCallback(shell, XInternAtom(display, "WM_DELETE_WINDOW", False),
                            quit, NULL);
    XtRealizeWidget(shell);
    XtVaSetValues(shell, XmNtitle, "X resources demo", NULL);
    XtAppMainLoop(app);
    XtDestroyWidget(shell);
    XtCloseDisplay(display);
    XtDestroyApplicationContext(app);
    return 0;
}
