/* Generated by wbuild from "Alert.w"
** (generator version $Revision: 1.17 $ of $Date: 92/12/07 19:32:00 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 279 "Alert.w"
#include <stdlib.h>
#line 280 "Alert.w"
#include <Xfwf/Icon.h>
#line 281 "Alert.w"
#include <Xfwf/Label.h>
#line 282 "Alert.w"
#include <Xfwf/Board.h>
#line 283 "Alert.w"
#include <Xfwf/Button.h>
#include <Xfwf/AlertP.h>
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 246 "Alert.w"
static void class_initialize(
#if NeedFunctionPrototypes
void
#endif
);
#line 256 "Alert.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 269 "Alert.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 148 "Alert.w"
#define ALLOC 1024 


#line 149 "Alert.w"
#define myrealloc(p, size) (void *)XtRealloc ((void *)p ,(size +ALLOC -1 )/ALLOC *ALLOC )


#line 151 "Alert.w"
#define mymalloc(size) (void *)XtMalloc (size )


#line 152 "Alert.w"
#define myfree(p) XtFree ((void *)p )


#line 159 "Alert.w"
static void button_pressed(
#if NeedFunctionPrototypes
Widget ,XtPointer ,XtPointer 
#endif
);
#line 168 "Alert.w"
static void click(
#if NeedFunctionPrototypes
Widget ,XtPointer ,XtPointer 
#endif
);
#line 180 "Alert.w"
static void create_children(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 159 "Alert.w"
/*ARGSUSED*/static void button_pressed(w,client_data,call_data)Widget  w;XtPointer  client_data;XtPointer  call_data;
{
    XtPopdown(w);
    *((int*) client_data) = (int) call_data;
}
#line 168 "Alert.w"
/*ARGSUSED*/static void click(w,client_data,call_data)Widget  w;XtPointer  client_data;XtPointer  call_data;
{
    Widget self = XtParent(XtParent(w));

    ((XfwfAlertWidget)self)->xfwfAlert.lastChoice = (int) client_data;
    XtCallCallbackList(self, ((XfwfAlertWidget)self)->xfwfAlert.callback, (XtPointer) ((XfwfAlertWidget)self)->xfwfAlert.lastChoice);
}
#line 180 "Alert.w"
/*ARGSUSED*/static void create_children(self)Widget self;
{
    int i;
    Dimension iconwd, iconht, labelwd, labelht, sumwd, wd, h, buttonht, ht;
    Dimension bframe, boffset, bw, bh;
    Position bx, by;
    String p;
    Widget board;
    char name[20];

    if (((XfwfAlertWidget)self)->xfwfAlert.iconw) XtDestroyWidget(((XfwfAlertWidget)self)->xfwfAlert.iconw);
    if (((XfwfAlertWidget)self)->xfwfAlert.labelw) XtDestroyWidget(((XfwfAlertWidget)self)->xfwfAlert.labelw);
    for (i = 0; i < ((XfwfAlertWidget)self)->xfwfAlert.num_buttons; i++) XtDestroyWidget(((XfwfAlertWidget)self)->xfwfAlert.buttonw[i]);
    ((XfwfAlertWidget)self)->xfwfAlert.iconw = XtVaCreateManagedWidget
	("_icon", xfwfIconWidgetClass, ((XfwfAlertWidget)self)->xfwfAlert.boardw, XtNx, 0, XtNy, 0,
	 XtNimage, ((XfwfAlertWidget)self)->xfwfAlert.icon, XtNtraversalOn, False, NULL);
    XtVaGetValues(((XfwfAlertWidget)self)->xfwfAlert.iconw, XtNwidth, &iconwd, XtNheight, &iconht, NULL);
    ((XfwfAlertWidget)self)->xfwfAlert.labelw = XtVaCreateManagedWidget
	("_message", xfwfLabelWidgetClass, ((XfwfAlertWidget)self)->xfwfAlert.boardw, XtNx, iconwd,
	 XtNy, 0, XtNshrinkToFit, True, XtNlabel, ((XfwfAlertWidget)self)->xfwfAlert.message, NULL);
    XtVaGetValues(((XfwfAlertWidget)self)->xfwfAlert.labelw, XtNwidth, &labelwd, XtNheight, &labelht, NULL);
    h = max(iconht, labelht);
    sumwd = iconwd;
    if (((XfwfAlertWidget)self)->xfwfAlert.buttons) {
	i = 0;
	buttonht = 0;
	p = strtok(((XfwfAlertWidget)self)->xfwfAlert.buttons, "|");
	while (p) {
	    ((XfwfAlertWidget)self)->xfwfAlert.buttonw = myrealloc(((XfwfAlertWidget)self)->xfwfAlert.buttonw, (i+1)*sizeof(*((XfwfAlertWidget)self)->xfwfAlert.buttonw));
	    sprintf(name, "%d", i);
	    ((XfwfAlertWidget)self)->xfwfAlert.buttonw[i] = XtVaCreateManagedWidget
		(name, xfwfButtonWidgetClass,
		 ((XfwfAlertWidget)self)->xfwfAlert.boardw, XtNx, sumwd, XtNy, h, XtNshrinkToFit,
		 True, XtNlabel, p, NULL);
	    XtVaGetValues(((XfwfAlertWidget)self)->xfwfAlert.buttonw[i], XtNwidth, &wd, XtNheight, &ht, NULL);
	    XtAddCallback
		(((XfwfAlertWidget)self)->xfwfAlert.buttonw[i], XtNactivate, click, (XtPointer) i);
	    sumwd += wd;
	    buttonht = max(buttonht, ht);
	    i++;
	    p = strtok(NULL, "|");
	}
	((XfwfAlertWidget)self)->xfwfAlert.num_buttons = i;
    } else {
	((XfwfAlertWidget)self)->xfwfAlert.buttonw = mymalloc(2*sizeof(*((XfwfAlertWidget)self)->xfwfAlert.buttonw));
	((XfwfAlertWidget)self)->xfwfAlert.num_buttons = 1;
	((XfwfAlertWidget)self)->xfwfAlert.buttonw[0] = XtVaCreateManagedWidget
	    ("0", xfwfButtonWidgetClass, ((XfwfAlertWidget)self)->xfwfAlert.boardw, XtNx, sumwd, XtNy, h,
	     XtNshrinkToFit, True, XtNlabel, " OK ", NULL);
	XtAddCallback(((XfwfAlertWidget)self)->xfwfAlert.buttonw[0], XtNactivate, click, 0);
	XtVaGetValues
	    (((XfwfAlertWidget)self)->xfwfAlert.buttonw[0], XtNwidth, &sumwd, XtNheight, &buttonht, NULL);
    }
    board = ((XfwfAlertWidget)self)->xfwfAlert.boardw;
    XfwfCallComputeInside(board, &bx, &by, &bw, &bh);
    wd = max(sumwd, iconwd + labelwd) + ((XfwfAlertWidget)board)->core.width - bw;
    ht = h + buttonht + ((XfwfAlertWidget)board)->core.height - bh;
    XtVaSetValues(board, XtNwidth, wd,  XtNheight, ht, NULL);
}

static XtResource resources[] = {
#line 34 "Alert.w"
{XtNicon,XtCIcon,XtRIcon,sizeof(((XfwfAlertRec*)NULL)->xfwfAlert.icon),XtOffsetOf(XfwfAlertRec,xfwfAlert.icon),XtRString,(XtPointer)"NONE"},
#line 38 "Alert.w"
{XtNmessage,XtCMessage,XtRString,sizeof(((XfwfAlertRec*)NULL)->xfwfAlert.message),XtOffsetOf(XfwfAlertRec,xfwfAlert.message),XtRImmediate,(XtPointer)NULL },
#line 45 "Alert.w"
{XtNbuttons,XtCButtons,XtRString,sizeof(((XfwfAlertRec*)NULL)->xfwfAlert.buttons),XtOffsetOf(XfwfAlertRec,xfwfAlert.buttons),XtRImmediate,(XtPointer)NULL },
#line 52 "Alert.w"
{XtNlastChoice,XtCLastChoice,XtRInt,sizeof(((XfwfAlertRec*)NULL)->xfwfAlert.lastChoice),XtOffsetOf(XfwfAlertRec,xfwfAlert.lastChoice),XtRImmediate,(XtPointer)0 },
#line 59 "Alert.w"
{XtNcallback,XtCCallback,XtRCallback,sizeof(((XfwfAlertRec*)NULL)->xfwfAlert.callback),XtOffsetOf(XfwfAlertRec,xfwfAlert.callback),XtRImmediate,(XtPointer)NULL },
};

XfwfAlertClassRec xfwfAlertClassRec = {
{ /* core_class part */
(WidgetClass) &transientShellClassRec,
"XfwfAlert",
sizeof(XfwfAlertRec),
class_initialize,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
NULL,
0,
resources,
5,
NULLQUARK,
False ,
FALSE ,
False ,
False ,
NULL,
XtInheritResize,
XtInheritExpose,
set_values,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
NULL,
XtInheritQueryGeometry,
XtInheritDisplayAccelerator,
NULL 
},
{ /* composite_class part */
XtInheritGeometryManager,
XtInheritChangeManaged,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* Shell_class part */
0
},
{ /* WMShell_class part */
0
},
{ /* VendorShell_class part */
0
},
{ /* TransientShell_class part */
0
},
{ /* XfwfAlert_class part */
0
},
};
WidgetClass xfwfAlertWidgetClass = (WidgetClass) &xfwfAlertClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfAlertWidgetClass c = (XfwfAlertWidgetClass) class;
  XfwfAlertWidgetClass super;
  if (class == xfwfAlertWidgetClass) return;
  super = (XfwfAlertWidgetClass) c->core_class.superclass;
}
#line 246 "Alert.w"
/*ARGSUSED*/static void class_initialize()
{
    XtSetTypeConverter(XtRString, "Icon", cvtStringToIcon,
		       NULL, 0, XtCacheNone, NULL);
}
#line 256 "Alert.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    ((XfwfAlertWidget)self)->xfwfAlert.iconw = NULL;
    ((XfwfAlertWidget)self)->xfwfAlert.labelw = NULL;
    ((XfwfAlertWidget)self)->xfwfAlert.buttonw = NULL;
    ((XfwfAlertWidget)self)->xfwfAlert.num_buttons = NULL;
    ((XfwfAlertWidget)self)->xfwfAlert.boardw = XtVaCreateManagedWidget("board", xfwfBoardWidgetClass, self, NULL);
    create_children(self);
}
#line 269 "Alert.w"
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    if (((XfwfAlertWidget)old)->xfwfAlert.icon != ((XfwfAlertWidget)self)->xfwfAlert.icon || ((XfwfAlertWidget)old)->xfwfAlert.message != ((XfwfAlertWidget)self)->xfwfAlert.message
	|| ((XfwfAlertWidget)old)->xfwfAlert.buttons != ((XfwfAlertWidget)self)->xfwfAlert.buttons)
	create_children(self);
    return False;
}
#line 117 "Alert.w"
#line 118 "Alert.w"
#line 120 "Alert.w"
/*ARGSUSED*/int  XfwfDialog(toplevel,icon,message,buttons)Widget  toplevel;String  icon;String  message;String  buttons;
{
    Widget alert;
    int choice = -1;
    XEvent event;
    Position x, y;
    Dimension wd, ht;

    XtVaGetValues
	(toplevel, XtNx, &x, XtNy, &y, XtNwidth, &wd, XtNheight, &ht, NULL);
    x = max(0, x + wd/2 - 120); y = max(0, y + ht/2 - 120);
    alert = XtVaCreatePopupShell
	("alert", xfwfAlertWidgetClass, toplevel, XtVaTypedArg,
	 XtNicon, XtRString, icon, strlen(icon) + 1, XtNmessage,
	 message, XtNbuttons, buttons, XtNx, x, XtNy, y, NULL);
    XtAddCallback(alert, XtNcallback, button_pressed, &choice);
    XtPopup(alert, XtGrabExclusive);
    while (choice == -1) {
	XtAppNextEvent(XtWidgetToApplicationContext(toplevel), &event);
	XtDispatchEvent(&event);
    }
    XtDestroyWidget(alert);
    return choice;
}
