#include <stdio.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/Xutil.h>
#include <X11/Xaw/Cardinals.h>
#include <X11/Xmu/CharSet.h>
#include "editresP.h"
struct ActionValues {
String name;
int type;
};
static struct ActionValues select_values[] = {
{ "widget", (int) SelectWidget },
{ "all", (int) SelectAll },
{ "nothing", (int) SelectNone },
{ "invert", (int) SelectInvert },
{ "children", (int) SelectChildren },
{ "descendants", (int) SelectDescendants },
{ "parent", (int) SelectParent },
{ "ancestors", (int) SelectAncestors }
};
static struct ActionValues label_values[] = {
{ "name", (int) NameLabel },
{ "class", (int) ClassLabel },
{ "id", (int) IDLabel },
{ "window", (int) WindowLabel },
{ "toggle", (int) ToggleLabel }
};
static void EnableGetVal ( Widget w, XEvent *event,
String *params, Cardinal * num_params );
static void SelectAction ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static void RelabelAction ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static void PopdownFileDialogAction ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static void ActionQuit ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static WNode * FindTreeNodeFromWidget ( Widget w );
static Boolean CheckAndFindEntry ( String action_name,
String * params, Cardinal num_params,
struct ActionValues * table,
Cardinal num_table, int * type );
Boolean do_get_values = False;
static void
EnableGetVal(w, event, params, num_params)
Widget w;
XEvent * event;
String * params;
Cardinal * num_params;
{
do_get_values = True;
}
static void
SelectAction(w, event, params, num_params)
Widget w;
XEvent * event;
String * params;
Cardinal * num_params;
{
WNode * node;
int type;
if (!CheckAndFindEntry("Select", params, *num_params,
select_values, XtNumber(select_values), &type))
return;
switch(type) {
case SelectAll:
case SelectNone:
case SelectInvert:
_TreeSelect(global_tree_info, (SelectTypes)type);
break;
case SelectWidget:
_FindWidget(XtParent(w));
break;
default:
node = FindTreeNodeFromWidget(w);
if (node)
_TreeActivateNode(node, (SelectTypes)type);
else
_TreeSelect(global_tree_info, (SelectTypes)type);
break;
}
}
static void
RelabelAction(w, event, params, num_params)
Widget w;
XEvent * event;
String * params;
Cardinal * num_params;
{
WNode * node;
int type;
if (!CheckAndFindEntry("Relabel", params, *num_params,
label_values, XtNumber(label_values), &type))
return;
if ((node = FindTreeNodeFromWidget(w)) == NULL)
_TreeRelabel(global_tree_info, (LabelTypes)type);
else {
PrepareToLayoutTree(global_tree_info->tree_widget);
_TreeRelabelNode(node, (LabelTypes)type, FALSE);
LayoutTree(global_tree_info->tree_widget);
}
}
static void
PopdownFileDialogAction(w, event, params, num_params)
Widget w;
XEvent * event;
String * params;
Cardinal * num_params;
{
char buf[BUFSIZ];
Boolean val;
if (*num_params != 1) {
sprintf(buf, res_labels[2],
"PopdownFileDialog");
SetMessage(global_screen_data.info_label, buf);
return;
}
XmuCopyISOLatin1Lowered(buf, params[0]);
if (streq(buf, "cancel"))
val = FALSE;
else if (streq(buf, "okay"))
val = TRUE;
else {
sprintf(buf, res_labels[1],
"PopdownFileDialog");
SetMessage(global_screen_data.info_label, buf);
return;
}
_PopdownFileDialog(w, (XtPointer)(long) val, NULL);
}
static void
ActionQuit(w, event, params, num_params)
Widget w;
XEvent * event;
String * params;
Cardinal * num_params;
{
if (w==global_toplevel) {
XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
exit(0);
}
else {
if (streq(XtName(w), RESOURCE_BOX))
global_resource_box_up = FALSE;
XtPopdown(w);
XtDestroyWidget(w);
}
}
static XtActionsRec actions[] = {
{"EnableGetVal", EnableGetVal},
{"Select", SelectAction},
{"SVActiveEntry", ModifySVEntry},
{"Relabel", RelabelAction},
{"PopdownFileDialog", PopdownFileDialogAction},
{"quit", ActionQuit}
};
void
SetApplicationActions(app_con)
XtAppContext app_con;
{
XtAppAddActions(app_con, actions, XtNumber(actions));
}
static Boolean
CheckAndFindEntry(action_name, params, num_params, table, num_table, type)
String * params, action_name;
Cardinal num_params, num_table;
struct ActionValues * table;
int * type;
{
char buf[BUFSIZ];
int i;
if (num_params != 1) {
sprintf(buf, res_labels[2],
action_name);
SetMessage(global_screen_data.info_label, buf);
return(FALSE);
}
XmuCopyISOLatin1Lowered(buf, params[0]);
for ( i = 0 ; i < num_table; i++ )
if (streq(buf, table[i].name)) {
*type = table[i].type;
return(TRUE);
}
sprintf(buf,res_labels[3],
action_name);
for (i = 0; i < num_table; ) {
strcat(buf, table[i++].name);
if (i == (num_table - 1))
strcat(buf, ", or ");
else if (i < num_table)
strcat(buf, ", ");
}
SetMessage(global_screen_data.info_label, buf);
return(FALSE);
}
static WNode *
FindTreeNodeFromWidget(w)
Widget w;
{
int ret_val;
XPointer data_return;
ret_val = XFindContext(XtDisplay(w), (Window) w, NODE_INFO, &data_return);
if (ret_val == 0)
return((WNode *) data_return);
return(NULL);
}