Home | History | Annotate | Line # | Download | only in dist
      1 /*
      2  *
      3 Copyright 1989, 1998  The Open Group
      4 
      5 Permission to use, copy, modify, distribute, and sell this software and its
      6 documentation for any purpose is hereby granted without fee, provided that
      7 the above copyright notice appear in all copies and that both that
      8 copyright notice and this permission notice appear in supporting
      9 documentation.
     10 
     11 The above copyright notice and this permission notice shall be included in
     12 all copies or substantial portions of the Software.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     20 
     21 Except as contained in this notice, the name of The Open Group shall not be
     22 used in advertising or otherwise to promote the sale, use or other dealings
     23 in this Software without prior written authorization from The Open Group.
     24  */
     25 
     26 #ifdef HAVE_CONFIG_H
     27 # include "config.h"
     28 #endif
     29 
     30 #include <stdio.h>
     31 #include <stdlib.h>
     32 #include <X11/Intrinsic.h>
     33 #include <X11/Xutil.h>
     34 
     35 #include <X11/Xaw/Cardinals.h>
     36 #include <X11/Xmu/CharSet.h>
     37 
     38 #include "editresP.h"
     39 
     40 /*
     41  * Private data.
     42  */
     43 
     44 //struct ActionValues {
     45 //    String name;
     46 //    int type;
     47 //};
     48 
     49 struct ActionValues {
     50 	const char * name;
     51         int  type;
     52 };
     53 
     54 
     55 static struct ActionValues select_values[] = {
     56     { "widget", (int) SelectWidget },
     57     { "all", (int) SelectAll },
     58     { "nothing", (int) SelectNone },
     59     { "invert", (int) SelectInvert },
     60     { "children", (int) SelectChildren },
     61     { "descendants", (int) SelectDescendants },
     62     { "parent", (int) SelectParent },
     63     { "ancestors", (int) SelectAncestors }
     64 };
     65 
     66 static struct  ActionValues label_values[] = {
     67     { "name", (int) NameLabel },
     68     { "class", (int) ClassLabel },
     69     { "id", (int) IDLabel },
     70     { "window", (int) WindowLabel },
     71     { "toggle", (int) ToggleLabel }
     72 };
     73 
     74 static void EnableGetVal ( Widget w, XEvent *event,
     75 			   String *params, Cardinal * num_params );
     76 static void SelectAction ( Widget w, XEvent *event,
     77 			   String *params, Cardinal *num_params );
     78 static void RelabelAction ( Widget w, XEvent *event,
     79 			    String *params, Cardinal *num_params );
     80 static void PopdownFileDialogAction ( Widget w, XEvent *event,
     81 				      String *params, Cardinal *num_params );
     82 static void ActionQuit ( Widget w, XEvent *event,
     83 			 String *params, Cardinal *num_params );
     84 static WNode * FindTreeNodeFromWidget ( Widget w );
     85 static Boolean CheckAndFindEntry (  const char *action_name,
     86 				   String * params, Cardinal num_params,
     87 				   struct ActionValues * table,
     88 				   Cardinal num_table, int * type );
     89 
     90 /*	Function Name: EnableGetVal
     91  *	Description: sets a global variable to notify the Notify action
     92  *                   for the resource list widet to do GetValues.
     93  *      Arguments: w - any widget in the widget tree.
     94  *                 event - NOT USED.
     95  *                 params, num_params - the parameters paseed to the action
     96  *                                      routine.
     97  *
     98  */
     99 
    100 Boolean do_get_values = False;
    101 
    102 /* ARGSUSED */
    103 static void
    104 EnableGetVal(Widget w, XEvent *event, String *params, Cardinal *num_params)
    105 {
    106   do_get_values = True;
    107 }
    108 
    109 /*	Function Name: SelectAction
    110  *	Description:
    111  *      Arguments: w - any widget in the widget tree.
    112  *                 event - NOT USED.
    113  *                 params, num_params - the parameters paseed to the action
    114  *                                      routine.
    115  *
    116  * params[0] - One of "nothing", "parent", "children", "ancestors",
    117  *                    "descendants", "invert", "all"
    118  * num_params - must be one.
    119  */
    120 
    121 /* ARGSUSED */
    122 static void
    123 SelectAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
    124 {
    125     WNode * node;
    126     int type;
    127 
    128     if (!CheckAndFindEntry("Select", params, *num_params,
    129 			   select_values, XtNumber(select_values), &type))
    130 	return;
    131 
    132     switch(type) {
    133     case SelectAll:
    134     case SelectNone:
    135     case SelectInvert:
    136 	_TreeSelect(global_tree_info, (SelectTypes)type);
    137 	break;
    138     case SelectWidget:
    139 	_FindWidget(XtParent(w));
    140 	break;
    141     default:
    142 	node = FindTreeNodeFromWidget(w);
    143 	if (node)
    144 	    _TreeActivateNode(node, (SelectTypes)type);
    145 	else
    146 	    _TreeSelect(global_tree_info, (SelectTypes)type);
    147 	break;
    148     }
    149 }
    150 
    151 /*	Function Name: RelabelAction
    152  *	Description:
    153  *      Arguments: w - any widget in the widget tree.
    154  *                 event - NOT USED.
    155  *                 params, num_params - the parameters paseed to the action
    156  *                                      routine.
    157  *
    158  * params[0] - One of "name", "class", "id"
    159  * num_params - must be one.
    160  */
    161 
    162 /* ARGSUSED */
    163 static void
    164 RelabelAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
    165 {
    166     WNode * node;
    167     int type;
    168 
    169     if (!CheckAndFindEntry("Relabel", params, *num_params,
    170 			   label_values, XtNumber(label_values), &type))
    171 	return;
    172 
    173     if ((node = FindTreeNodeFromWidget(w)) == NULL)
    174 	_TreeRelabel(global_tree_info, (LabelTypes)type);
    175     else {
    176 	PrepareToLayoutTree(global_tree_info->tree_widget);
    177 	_TreeRelabelNode(node, (LabelTypes)type, FALSE);
    178 	LayoutTree(global_tree_info->tree_widget);
    179     }
    180 }
    181 
    182 /*	Function Name: PopdownFileDialogAction
    183  *	Description: Pops down the file dialog widget.
    184  *                   and calls the approipriate handler.
    185  *	Arguments: w - any child of the dialog widget.
    186  *                 event - the event that caused this action.
    187  *                 params, num_params - params passed to the action routine.
    188  * RETURNED        none.
    189  */
    190 
    191 /* ARGSUSED */
    192 
    193 static void
    194 PopdownFileDialogAction(Widget w, XEvent *event,
    195 			String *params, Cardinal *num_params)
    196 {
    197     char buf[BUFSIZ];
    198     Boolean val;
    199 
    200     if (*num_params != 1) {
    201 	snprintf(buf, sizeof(buf), res_labels[2], "PopdownFileDialog");
    202 
    203 	SetMessage(global_screen_data.info_label, buf);
    204 	return;
    205     }
    206 
    207     XmuCopyISOLatin1Lowered(buf, params[0]);
    208 
    209     if (streq(buf, "cancel"))
    210 	val = FALSE;
    211     else if (streq(buf, "okay"))
    212 	val = TRUE;
    213     else {
    214 	snprintf(buf, sizeof(buf), res_labels[1], "PopdownFileDialog");
    215 
    216 	SetMessage(global_screen_data.info_label, buf);
    217 	return;
    218     }
    219 
    220     _PopdownFileDialog(w, (XtPointer)(long) val, NULL);
    221 }
    222 
    223 /*	Function Name: ActionQuit
    224  *	Description: This function prints a message to stdout.
    225  *	Arguments: w - ** UNUSED **
    226  *                 call_data - ** UNUSED **
    227  *                 client_data - ** UNUSED **
    228  *	Returns: none
    229  */
    230 
    231 /* ARGSUSED */
    232 static void
    233 ActionQuit(Widget w, XEvent *event, String *params, Cardinal *num_params)
    234 {
    235   if (w==global_toplevel) {
    236     XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
    237     exit(0);
    238   }
    239   else  {
    240     if (streq(XtName(w), RESOURCE_BOX))
    241       global_resource_box_up = FALSE;
    242     XtPopdown(w);
    243     XtDestroyWidget(w);
    244   }
    245 }
    246 
    247 /*	Function Name: SetApplicationActions
    248  *	Description: Sets my application actions.
    249  *	Arguments: app_con - the application context.
    250  *	Returns: none.
    251  */
    252 
    253 static XtActionsRec actions[] = {
    254   {(String)"EnableGetVal",      EnableGetVal},
    255   {(String)"Select",            SelectAction},
    256   {(String)"SVActiveEntry",     ModifySVEntry},
    257   {(String)"Relabel",      	RelabelAction},
    258   {(String)"PopdownFileDialog", PopdownFileDialogAction},
    259   {(String)"quit",              ActionQuit}
    260 };
    261 
    262 void
    263 SetApplicationActions(XtAppContext app_con)
    264 {
    265     XtAppAddActions(app_con, actions, XtNumber(actions));
    266 
    267 }
    268 
    269 
    270 /************************************************************
    271  *
    272  * Private functions
    273  *
    274  ************************************************************/
    275 
    276 /*	Function Name: CheckAndFindEntry
    277  *	Description: Checks the args to make sure they are valid,
    278  *                   then parses the arg list to find the correct action
    279  *                   to take.
    280  *	Arguments: action_name - name of the action (for error messages).
    281  *                 params, num_params - params passed to the action routine.
    282  *                 table, num_table - table to check the parameters against.
    283  * RETURNED        type - info about the action to take.
    284  *	Returns: TRUE if the arguments are okay.
    285  */
    286 
    287 static Boolean
    288 CheckAndFindEntry(const char *action_name, String *params, Cardinal num_params,
    289 		  struct ActionValues *table, Cardinal num_table, int *type)
    290 {
    291     char buf[BUFSIZ];
    292     Cardinal i;
    293 
    294     if (num_params != 1) {
    295 	snprintf(buf, sizeof(buf), res_labels[2], action_name);
    296 	SetMessage(global_screen_data.info_label, buf);
    297 	return(FALSE);
    298     }
    299 
    300     XmuCopyISOLatin1Lowered(buf, params[0]);
    301     for ( i = 0 ; i < num_table; i++ )
    302 	if (streq(buf, table[i].name)) {
    303 	    *type = table[i].type;
    304 	    return(TRUE);
    305 	}
    306 
    307     snprintf(buf, sizeof(buf), res_labels[3], action_name);
    308 
    309     for (i = 0; i < num_table; ) {
    310 	strcat(buf, table[i++].name);
    311 
    312 	if (i == (num_table - 1))
    313 	    strcat(buf, ", or ");
    314 	else if (i < num_table)
    315 	    strcat(buf, ", ");
    316     }
    317 
    318     SetMessage(global_screen_data.info_label, buf);
    319     return(FALSE);
    320 }
    321 
    322 /*	Function Name: FindTreeNodeFromWidget
    323  *	Description: finds the tree node associated with a widget.
    324  *	Arguments: w - widget to check.
    325  *	Returns: the node associated with this widget, or NULL.
    326  */
    327 
    328 static WNode *
    329 FindTreeNodeFromWidget(Widget w)
    330 {
    331     int ret_val;
    332     XPointer data_return;
    333 
    334     /*
    335      * Yes, I really am casting a widget to a window  ** TRUST ME ***
    336      */
    337 
    338     ret_val = XFindContext(XtDisplay(w), (Window) w, NODE_INFO, &data_return);
    339 
    340     if (ret_val == 0)
    341 	return((WNode *) data_return);
    342     return(NULL);
    343 }
    344 
    345