xenocara/app/editres/actions.c

335 lines
9.2 KiB
C
Raw Permalink Normal View History

2006-11-25 13:07:29 -07:00
/*
*
Copyright 1989, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#include <stdio.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/Xutil.h>
2018-05-21 09:15:36 -06:00
#include <X11/Xaw/Cardinals.h>
2006-11-25 13:07:29 -07:00
#include <X11/Xmu/CharSet.h>
#include "editresP.h"
/*
* Private data.
*/
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 }
};
2018-05-21 09:15:36 -06:00
static void EnableGetVal ( Widget w, XEvent *event,
2006-11-25 13:07:29 -07:00
String *params, Cardinal * num_params );
2018-05-21 09:15:36 -06:00
static void SelectAction ( Widget w, XEvent *event,
2006-11-25 13:07:29 -07:00
String *params, Cardinal *num_params );
2018-05-21 09:15:36 -06:00
static void RelabelAction ( Widget w, XEvent *event,
2006-11-25 13:07:29 -07:00
String *params, Cardinal *num_params );
2018-05-21 09:15:36 -06:00
static void PopdownFileDialogAction ( Widget w, XEvent *event,
2006-11-25 13:07:29 -07:00
String *params, Cardinal *num_params );
2018-05-21 09:15:36 -06:00
static void ActionQuit ( Widget w, XEvent *event,
2006-11-25 13:07:29 -07:00
String *params, Cardinal *num_params );
static WNode * FindTreeNodeFromWidget ( Widget w );
2018-05-21 09:15:36 -06:00
static Boolean CheckAndFindEntry ( String action_name,
String * params, Cardinal num_params,
struct ActionValues * table,
2006-11-25 13:07:29 -07:00
Cardinal num_table, int * type );
/* Function Name: EnableGetVal
* Description: sets a global variable to notify the Notify action
* for the resource list widet to do GetValues.
* Arguments: w - any widget in the widget tree.
* event - NOT USED.
* params, num_params - the parameters paseed to the action
2018-05-21 09:15:36 -06:00
* routine.
2006-11-25 13:07:29 -07:00
*
*/
Boolean do_get_values = False;
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
EnableGetVal(Widget w, XEvent *event, String *params, Cardinal *num_params)
2006-11-25 13:07:29 -07:00
{
do_get_values = True;
}
/* Function Name: SelectAction
2018-05-21 09:15:36 -06:00
* Description:
2006-11-25 13:07:29 -07:00
* Arguments: w - any widget in the widget tree.
* event - NOT USED.
* params, num_params - the parameters paseed to the action
2018-05-21 09:15:36 -06:00
* routine.
2006-11-25 13:07:29 -07:00
*
* params[0] - One of "nothing", "parent", "children", "ancestors",
* "descendants", "invert", "all"
* num_params - must be one.
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
SelectAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
2006-11-25 13:07:29 -07:00
{
WNode * node;
int type;
2018-05-21 09:15:36 -06:00
if (!CheckAndFindEntry("Select", params, *num_params,
2006-11-25 13:07:29 -07:00
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)
2018-05-21 09:15:36 -06:00
_TreeActivateNode(node, (SelectTypes)type);
2006-11-25 13:07:29 -07:00
else
_TreeSelect(global_tree_info, (SelectTypes)type);
break;
}
}
/* Function Name: RelabelAction
2018-05-21 09:15:36 -06:00
* Description:
2006-11-25 13:07:29 -07:00
* Arguments: w - any widget in the widget tree.
* event - NOT USED.
* params, num_params - the parameters paseed to the action
2018-05-21 09:15:36 -06:00
* routine.
2006-11-25 13:07:29 -07:00
*
* params[0] - One of "name", "class", "id"
* num_params - must be one.
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
RelabelAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
2006-11-25 13:07:29 -07:00
{
WNode * node;
int type;
2018-05-21 09:15:36 -06:00
if (!CheckAndFindEntry("Relabel", params, *num_params,
2006-11-25 13:07:29 -07:00
label_values, XtNumber(label_values), &type))
return;
2018-05-21 09:15:36 -06:00
if ((node = FindTreeNodeFromWidget(w)) == NULL)
2006-11-25 13:07:29 -07:00
_TreeRelabel(global_tree_info, (LabelTypes)type);
else {
2018-05-21 09:15:36 -06:00
PrepareToLayoutTree(global_tree_info->tree_widget);
2006-11-25 13:07:29 -07:00
_TreeRelabelNode(node, (LabelTypes)type, FALSE);
2018-05-21 09:15:36 -06:00
LayoutTree(global_tree_info->tree_widget);
2006-11-25 13:07:29 -07:00
}
}
/* Function Name: PopdownFileDialogAction
* Description: Pops down the file dialog widget.
* and calls the approipriate handler.
* Arguments: w - any child of the dialog widget.
* event - the event that caused this action.
* params, num_params - params passed to the action routine.
* RETURNED none.
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
PopdownFileDialogAction(Widget w, XEvent *event,
String *params, Cardinal *num_params)
2006-11-25 13:07:29 -07:00
{
char buf[BUFSIZ];
Boolean val;
if (*num_params != 1) {
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf), res_labels[2], "PopdownFileDialog");
2006-11-25 13:07:29 -07:00
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 {
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf), res_labels[1], "PopdownFileDialog");
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, buf);
return;
}
_PopdownFileDialog(w, (XtPointer)(long) val, NULL);
}
/* Function Name: ActionQuit
* Description: This function prints a message to stdout.
* Arguments: w - ** UNUSED **
* call_data - ** UNUSED **
* client_data - ** UNUSED **
* Returns: none
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
ActionQuit(Widget w, XEvent *event, String *params, Cardinal *num_params)
2006-11-25 13:07:29 -07:00
{
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);
}
}
/* Function Name: SetApplicationActions
* Description: Sets my application actions.
* Arguments: app_con - the application context.
* Returns: none.
*/
static XtActionsRec actions[] = {
{"EnableGetVal", EnableGetVal},
{"Select", SelectAction},
{"SVActiveEntry", ModifySVEntry},
2018-05-21 09:15:36 -06:00
{"Relabel", RelabelAction},
2006-11-25 13:07:29 -07:00
{"PopdownFileDialog", PopdownFileDialogAction},
{"quit", ActionQuit}
};
void
2010-05-31 13:33:38 -06:00
SetApplicationActions(XtAppContext app_con)
2006-11-25 13:07:29 -07:00
{
XtAppAddActions(app_con, actions, XtNumber(actions));
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
}
/************************************************************
*
2018-05-21 09:15:36 -06:00
* Private functions
2006-11-25 13:07:29 -07:00
*
************************************************************/
/* Function Name: CheckAndFindEntry
* Description: Checks the args to make sure they are valid,
* then parses the arg list to find the correct action
* to take.
* Arguments: action_name - name of the action (for error messages).
* params, num_params - params passed to the action routine.
* table, num_table - table to check the parameters against.
* RETURNED type - info about the action to take.
* Returns: TRUE if the arguments are okay.
*/
static Boolean
2010-05-31 13:33:38 -06:00
CheckAndFindEntry(String action_name, String *params, Cardinal num_params,
struct ActionValues *table, Cardinal num_table, int *type)
2006-11-25 13:07:29 -07:00
{
char buf[BUFSIZ];
2018-05-21 09:15:36 -06:00
Cardinal i;
2006-11-25 13:07:29 -07:00
if (num_params != 1) {
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf), res_labels[2], action_name);
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, buf);
return(FALSE);
}
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
XmuCopyISOLatin1Lowered(buf, params[0]);
2018-05-21 09:15:36 -06:00
for ( i = 0 ; i < num_table; i++ )
2006-11-25 13:07:29 -07:00
if (streq(buf, table[i].name)) {
*type = table[i].type;
return(TRUE);
}
2018-05-21 09:15:36 -06:00
snprintf(buf, sizeof(buf), res_labels[3], action_name);
2006-11-25 13:07:29 -07:00
for (i = 0; i < num_table; ) {
strcat(buf, table[i++].name);
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
if (i == (num_table - 1))
strcat(buf, ", or ");
else if (i < num_table)
strcat(buf, ", ");
}
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, buf);
return(FALSE);
}
/* Function Name: FindTreeNodeFromWidget
* Description: finds the tree node associated with a widget.
* Arguments: w - widget to check.
* Returns: the node associated with this widget, or NULL.
*/
static WNode *
2010-05-31 13:33:38 -06:00
FindTreeNodeFromWidget(Widget w)
2006-11-25 13:07:29 -07:00
{
int ret_val;
XPointer data_return;
/*
* Yes, I really am casting a widget to a window ** TRUST ME ***
*/
ret_val = XFindContext(XtDisplay(w), (Window) w, NODE_INFO, &data_return);
2018-05-21 09:15:36 -06:00
if (ret_val == 0)
2006-11-25 13:07:29 -07:00
return((WNode *) data_return);
return(NULL);
}