1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
/*******************************************************************************
* *
* Viewmol *
* *
* M E S S G B . C *
* *
* Copyright (c) Joerg-R. Hill, December 2000 *
* *
********************************************************************************
*
* $Id: messgb.c,v 1.5 2000/12/10 15:11:26 jrh Exp $
* $Log: messgb.c,v $
* Revision 1.5 2000/12/10 15:11:26 jrh
* Release 2.3
*
* Revision 1.4 1999/05/24 01:26:28 jrh
* Release 2.2.1
*
* Revision 1.3 1999/02/07 21:52:26 jrh
* Release 2.2
*
* Revision 1.2 1998/01/26 00:48:34 jrh
* Release 2.1
*
* Revision 1.1 1996/12/10 18:42:04 jrh
* Initial revision
*
*/
#include<X11/Intrinsic.h>
#include<Xm/Xm.h>
#include<Xm/BulletinB.h>
#include<Xm/Form.h>
#include<Xm/Label.h>
#include<Xm/LabelG.h>
#include<Xm/MessageB.h>
#include<Xm/PanedW.h>
#include<Xm/PushB.h>
#include<Xm/PushBG.h>
#include<Xm/RowColumn.h>
#include<Xm/Separator.h>
#include<Xm/Text.h>
#include<Xm/ToggleB.h>
#include<stdio.h>
#include<stdlib.h>
#include "dialog.h"
Widget CreatePushButtonRow(Widget, struct PushButtonRow *, int);
void MapBox(Widget, caddr_t, XmAnyCallbackStruct *);
extern Widget initShell(Widget, char *, Widget *, Widget *);
static Widget dialog;
static int cont, ret;
extern XtAppContext app;
extern Widget topShell;
Widget CreatePushButtonRow(Widget parent, struct PushButtonRow *buttons, int n)
{
Widget row;
Dimension height, h;
register int i;
row=XtVaCreateManagedWidget("row", xmFormWidgetClass, parent,
XmNfractionBase, 20*n-1, NULL);
for (i=0; i<n; i++)
{
buttons[i].widget=XtVaCreateManagedWidget(buttons[i].label, xmPushButtonGadgetClass, row,
XmNleftAttachment, i ? XmATTACH_POSITION : XmATTACH_FORM,
XmNleftPosition, 20*i,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNrightAttachment, i != n-1 ? XmATTACH_POSITION: XmATTACH_FORM,
XmNrightPosition, 20*i+19,
XmNshowAsDefault, i==0,
XmNdefaultButtonShadowThickness, 1,
NULL);
if (buttons[i].callback)
XtAddCallback(buttons[i].widget, XmNactivateCallback,
(XtCallbackProc)buttons[i].callback,
buttons[i].client_data);
if (i==0)
{
XtVaGetValues(row, XmNmarginHeight, &h, NULL);
XtVaGetValues(buttons[i].widget, XmNheight, &height, NULL);
height+=2*h;
XtVaSetValues(row, XmNdefaultButton, buttons[i].widget, XmNpaneMaximum,
height, XmNpaneMinimum, height, NULL);
}
}
return(row);
}
void MapBox(Widget form, caddr_t dummy, XmAnyCallbackStruct *cbs)
{
Display *display;
Window root, child;
int rootX, rootY, windowX, windowY, screen;
unsigned int mask;
Dimension w, h, rootW, rootH;
display=XtDisplay(form);
screen=DefaultScreen(display);
XQueryPointer(display, XtWindow(form), &root, &child, &rootX, &rootY,
&windowX, &windowY, &mask);
XtVaGetValues(form, XmNwidth, &w, XmNheight, &h, NULL);
windowX=rootX-w/2;
windowY=rootY-h/2;
if (windowX < 0) windowX=0;
if (windowY < 0) windowY=0;
rootW=DisplayWidth(display, screen);
rootH=DisplayHeight(display, screen);
if (windowX+w > rootW) windowX=rootW-w;
if (windowY+h > rootH) windowY=rootH-h;
XtVaSetValues(form, XmNx, windowX, XmNy, windowY, XmNminWidth, w,
XmNminHeight, h, NULL);
}
int messgb(Widget parent, int serious, char *str,
struct PushButtonRow *buttons, int n)
{
XEvent event;
static Widget form;
Widget form1, board, sign, label, sep;
Pixmap pixmap;
Pixel fg, bg;
XmString text;
int depth;
#include "messgb.h"
dialog=initShell(parent, "messageForm", &board, &form);
XtAddCallback(dialog, XmNpopupCallback, (XtCallbackProc)MapBox, (XmAnyCallbackStruct *)NULL);
form1=XtVaCreateWidget("form1", xmFormWidgetClass, form, NULL);
sep=XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, form, NULL);
text=XmStringCreateLtoR(str, XmSTRING_DEFAULT_CHARSET);
if (serious != 0)
{
XtVaGetValues(form1, XmNforeground, &fg, XmNbackground, &bg, NULL);
XtVaGetValues(parent, XtNdepth, &depth, NULL);
pixmap=XCreatePixmapFromBitmapData(XtDisplay(form1), RootWindowOfScreen(XtScreen(form1)),
sign_data[serious-1], 64, 64, fg, bg, depth);
sign=XtVaCreateManagedWidget("sign", xmLabelWidgetClass, form1,
XmNlabelType, XmPIXMAP,
XmNlabelPixmap, pixmap,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
label=XtVaCreateManagedWidget("text", xmLabelWidgetClass, form1,
XmNlabelString, text,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, sign,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
}
else
label=XtVaCreateManagedWidget("text", xmLabelWidgetClass, form1,
XmNlabelString, text,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
CreatePushButtonRow(form, buttons, n);
XtManageChild(form1);
XtManageChild(form);
XtManageChild(board);
cont=TRUE;
while (cont)
{
XtAppNextEvent(app, &event);
XtDispatchEvent(&event);
}
return(ret);
}
void GetMessageBoxButton(Widget button, XtPointer which, caddr_t call_data)
{
ret=(int)which;
cont=FALSE;
XtDestroyWidget(dialog);
}
|