#include "xmh.h"
#include "bboxint.h"
static XtTranslations RadioButtonTranslations = NULL;
void BBoxInit(void)
{
RadioButtonTranslations =
XtParseTranslationTable("<Btn1Down>,<Btn1Up>:set()\n");
}
ButtonBox BBoxCreate(
Scrn scrn,
char *name)
{
Cardinal n;
ButtonBox buttonbox = XtNew(ButtonBoxRec);
Arg args[5];
n = 0;
XtSetArg(args[n], XtNallowVert, True); n++;
XtSetArg(args[n], XtNskipAdjust, True); n++;
buttonbox->outer =
XtCreateManagedWidget(name, viewportWidgetClass, scrn->widget,
args, n);
buttonbox->inner =
XtCreateManagedWidget(name, boxWidgetClass, buttonbox->outer,
args, (Cardinal) 0);
buttonbox->numbuttons = 0;
buttonbox->button = (Button *) NULL;
buttonbox->scrn = scrn;
return buttonbox;
}
ButtonBox RadioBBoxCreate(
Scrn scrn,
char *name)
{
return BBoxCreate(scrn, name);
}
static void bboxAddButton(
ButtonBox buttonbox,
char *name,
WidgetClass kind,
Boolean enabled,
Boolean radio)
{
Button button;
Cardinal i;
Widget radio_group;
Arg args[5];
buttonbox->numbuttons++;
buttonbox->button = (Button *)
XtRealloc((char *) buttonbox->button,
(unsigned) buttonbox->numbuttons * sizeof(Button));
button = buttonbox->button[buttonbox->numbuttons - 1] = XtNew(ButtonRec);
button->buttonbox = buttonbox;
button->name = XtNewString(name);
button->menu = (Widget) NULL;
i = 0;
if (!enabled) {
XtSetArg(args[i], XtNsensitive, False); i++;
}
if (radio && kind == toggleWidgetClass) {
if (buttonbox->numbuttons > 1)
radio_group = (button == buttonbox->button[0])
? (buttonbox->button[1]->widget)
: (buttonbox->button[0]->widget);
else radio_group = NULL;
XtSetArg(args[i], XtNradioGroup, radio_group); i++;
XtSetArg(args[i], XtNradioData, button->name); i++;
}
if (buttonbox == buttonbox->scrn->folderbuttons) {
XtSetArg(args[i], XtNlabel, button->name); i++;
}
button->widget =
XtCreateManagedWidget(name, kind, buttonbox->inner, args, i);
if (radio)
XtOverrideTranslations(button->widget, RadioButtonTranslations);
}
void BBoxAddButton(
ButtonBox buttonbox,
char *name,
WidgetClass kind,
Boolean enabled)
{
bboxAddButton(buttonbox, name, kind, enabled, False);
}
void RadioBBoxAddButton(
ButtonBox buttonbox,
char *name,
Boolean enabled)
{
bboxAddButton(buttonbox, name, toggleWidgetClass, enabled, True);
}
void RadioBBoxSet(
Button button)
{
XawToggleSetCurrent(button->widget, button->name);
}
char *RadioBBoxGetCurrent(
ButtonBox buttonbox)
{
return ((char *) XawToggleGetCurrent(buttonbox->button[0]->widget));
}
void BBoxDeleteButton(
Button button)
{
ButtonBox buttonbox;
int i, found;
if (button == NULL) return;
buttonbox = button->buttonbox;
found = False;
for (i=0 ; i<buttonbox->numbuttons; i++) {
if (found)
buttonbox->button[i-1] = buttonbox->button[i];
else if (buttonbox->button[i] == button) {
found = True;
if (button->menu != NULL && button->menu != NoMenuForButton)
XtDestroyWidget(button->menu);
XtDestroyWidget(button->widget);
XtFree(button->name);
XtFree((char *) button);
}
}
if (found)
buttonbox->numbuttons--;
}
void RadioBBoxDeleteButton(
Button button)
{
ButtonBox buttonbox;
Boolean reradio = False;
char * current;
if (button == NULL) return;
buttonbox = button->buttonbox;
current = RadioBBoxGetCurrent(buttonbox);
if (current) reradio = ! strcmp(current, button->name);
BBoxDeleteButton(button);
if (reradio && BBoxNumButtons(buttonbox))
RadioBBoxSet(buttonbox->button[0]);
}
static void SendEnableMsg(
Widget widget,
int value)
{
static Arg arglist[] = {{XtNsensitive, (XtArgVal)False}};
arglist[0].value = (XtArgVal) value;
XtSetValues(widget, arglist, XtNumber(arglist));
}
void BBoxEnable(
Button button)
{
SendEnableMsg(button->widget, True);
}
void BBoxDisable(
Button button)
{
SendEnableMsg(button->widget, False);
}
Button BBoxFindButtonNamed(
ButtonBox buttonbox,
char *name)
{
register int i;
for (i=0 ; i<buttonbox->numbuttons; i++)
if (strcmp(name, buttonbox->button[i]->name) == 0)
return buttonbox->button[i];
return (Button) NULL;
}
Button BBoxFindButton(
ButtonBox buttonbox,
Widget w)
{
register int i;
for (i=0; i < buttonbox->numbuttons; i++)
if (buttonbox->button[i]->widget == w)
return buttonbox->button[i];
return (Button) NULL;
}
Button BBoxButtonNumber(
ButtonBox buttonbox,
int n)
{
return buttonbox->button[n];
}
int BBoxNumButtons(
ButtonBox buttonbox)
{
return buttonbox->numbuttons;
}
char *BBoxNameOfButton(
Button button)
{
return button->name;
}
Widget BBoxMenuOfButton(
Button button)
{
return button->menu;
}
void BBoxLockSize(
ButtonBox buttonbox)
{
Dimension maxheight;
Arg args[1];
if (buttonbox == NULL) return;
maxheight = (Dimension) GetHeight(buttonbox->inner);
XtSetArg(args[0], XtNmax, maxheight);
XtSetValues(buttonbox->outer, args, (Cardinal) 1);
}
Boolean BBoxIsGrandparent(
ButtonBox buttonbox,
Widget widget)
{
return (XtParent(XtParent(widget)) == buttonbox->inner);
}
void BBoxMailFlag(
ButtonBox buttonbox,
char* name,
int up)
{
Arg args[1];
Pixel flag;
Button button = BBoxFindButtonNamed(buttonbox, name);
if (button) {
XtSetArg(args[0], XtNleftBitmap, &flag);
XtGetValues(button->widget, args, (Cardinal)1);
if (up && flag != app_resources.flag_up) {
XtSetArg(args[0], XtNleftBitmap, app_resources.flag_up);
XtSetValues(button->widget, args, (Cardinal)1);
}
else if (!up && flag != app_resources.flag_down) {
XtSetArg(args[0], XtNleftBitmap, app_resources.flag_down);
XtSetValues(button->widget, args, (Cardinal)1);
}
}
}