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  * Author:  Chris D. Peterson, MIT X Consortium
     26  */
     27 
     28 #ifdef HAVE_CONFIG_H
     29 # include "config.h"
     30 #endif
     31 
     32 #include <X11/Intrinsic.h>
     33 #include <X11/StringDefs.h>	/* Get standard string definitions. */
     34 #include <X11/Xatom.h>
     35 #include <X11/cursorfont.h>
     36 #include <X11/Shell.h>
     37 
     38 #include <X11/Xaw/AsciiText.h>
     39 #include <X11/Xaw/Cardinals.h>
     40 #include <X11/Xaw/Command.h>
     41 #include <X11/Xaw/Form.h>
     42 #include <X11/Xaw/Label.h>
     43 
     44 #include <stdio.h>
     45 
     46 #ifdef XKB
     47 #include <X11/extensions/XKBbells.h>
     48 #endif
     49 
     50 #include "editresP.h"
     51 
     52 static void _SetField ( Widget new, Widget old );
     53 static void CreateSetValuesPopup ( Widget parent, ScreenData * scr_data );
     54 static void DoSetValues ( Widget w, XtPointer junk, XtPointer garbage );
     55 static void CancelSetValues ( Widget w, XtPointer junk, XtPointer garbage );
     56 
     57 /*	Function Name: PopupSetValues
     58  *	Description: This function pops up the setvalues dialog
     59  *	Arguments: parent - the parent of the setvalues popup.
     60  *                 event - the event that caused this popup, or NULL.
     61  *	Returns: none
     62  */
     63 
     64 /* ARGSUSED */
     65 void
     66 PopupSetValues(Widget parent, XEvent *event)
     67 {
     68     Arg args[1];
     69 
     70     if (global_tree_info == NULL) {
     71 	SetMessage(global_screen_data.info_label,
     72 		   res_labels[17]);
     73 	return;
     74     }
     75 
     76 /*
     77  * Check and possibly create the popup.
     78  */
     79 
     80     if (global_screen_data.set_values_popup == NULL)
     81 	CreateSetValuesPopup(parent, &global_screen_data);
     82 
     83 /*
     84  * Clear out the old strings, and set the active widget to the name widget.
     85  */
     86 
     87     XtSetArg(args[0], (String)XtNstring, "");
     88     XtSetValues(global_screen_data.res_text, args, ONE);
     89     XtSetValues(global_screen_data.val_text, args, ONE);
     90 
     91     _SetField(global_screen_data.res_text, global_screen_data.val_text);
     92 
     93 /*
     94  * Pop it up.
     95  */
     96 
     97     PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
     98 }
     99 
    100 /*	Function Name: ModifySVEntry
    101  *	Description: Action routine that can be bound to the set values
    102  *                   dialog box's Text Widget that will send input to the
    103  *                   field specified.
    104  *	Arguments:   (Standard Action Routine args)
    105  *	Returns:     none.
    106  */
    107 
    108 /* ARGSUSED */
    109 void
    110 ModifySVEntry(Widget w, XEvent *event, String *params, Cardinal *num_params)
    111 {
    112     Widget new, old;
    113     char msg[BUFSIZ];
    114 
    115     if (*num_params != 1) {
    116 	strcpy(msg,
    117 	       res_labels[21]);
    118 	SetMessage(global_screen_data.info_label, msg);
    119 	return;
    120     }
    121 
    122     switch (params[0][0]) {
    123     case 'r':
    124     case 'R':
    125 	new = global_screen_data.res_text;
    126 	old = global_screen_data.val_text;
    127 	break;
    128     case 'v':
    129     case 'V':
    130 	new = global_screen_data.val_text;
    131 	old = global_screen_data.res_text;
    132 	break;
    133     default:
    134 	snprintf(msg, sizeof(msg), res_labels[22]);
    135 	SetMessage(global_screen_data.info_label, msg);
    136 	return;
    137     }
    138 
    139     _SetField(new, old);
    140 }
    141 
    142 /************************************************************
    143  *
    144  * Private Functions
    145  *
    146  ************************************************************/
    147 
    148 /*	Function Name: _SetField
    149  *	Description: Sets the current text entry field.
    150  *	Arguments: new, old - new and old text fields.
    151  *	Returns: none
    152  */
    153 
    154 static void
    155 _SetField(Widget new, Widget old)
    156 {
    157     Arg args[2];
    158     Pixel new_border, old_border, old_bg;
    159 
    160     if (!XtIsSensitive(new)) {
    161 #ifdef XKB
    162 	/* Don't set field to an inactive Widget. */
    163 	XkbStdBell(XtDisplay(old), XtWindow(new), 0, XkbBI_InvalidLocation);
    164 #else
    165 	XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
    166 #endif
    167 	return;
    168     }
    169 
    170     XtSetKeyboardFocus(XtParent(new), new);
    171 
    172     XtSetArg(args[0], (String)XtNborderColor, &old_border);
    173     XtSetArg(args[1], (String)XtNbackground, &old_bg);
    174     XtGetValues(new, args, TWO);
    175 
    176     XtSetArg(args[0], (String)XtNborderColor, &new_border);
    177     XtGetValues(old, args, ONE);
    178 
    179     if (old_border != old_bg)	/* Colors are already correct, return. */
    180 	return;
    181 
    182     XtSetArg(args[0], (String)XtNborderColor, old_border);
    183     XtSetValues(old, args, ONE);
    184 
    185     XtSetArg(args[0], (String)XtNborderColor, new_border);
    186     XtSetValues(new, args, ONE);
    187 }
    188 
    189 /*	Function Name: CreateSetValuesPopup
    190  *	Description: Creates the setvalues popup.
    191  *	Arguments: parent - the parent of the popup.
    192  *                 scr_data - the data about this screen.
    193  *	Returns: the set values popup.
    194  */
    195 
    196 static void
    197 CreateSetValuesPopup(Widget parent, ScreenData *scr_data)
    198 {
    199     Widget form, cancel, do_it, label;
    200     Widget res_label;
    201     Arg args[10];
    202     Cardinal num_args;
    203 
    204     scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup",
    205 						    transientShellWidgetClass,
    206 						    parent, NULL, ZERO);
    207 
    208     form = XtCreateManagedWidget("form", formWidgetClass,
    209 				 scr_data->set_values_popup, NULL, ZERO);
    210 
    211     num_args = 0;
    212     label = XtCreateManagedWidget("label", labelWidgetClass,
    213 				  form, args, num_args);
    214 
    215 
    216     num_args = 0;
    217     XtSetArg(args[num_args], (String)XtNfromVert, label); num_args++;
    218     res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
    219 				  form, args, num_args);
    220 
    221     num_args = 0;
    222     XtSetArg(args[num_args], (String)XtNfromVert, label); num_args++;
    223     XtSetArg(args[num_args], (String)XtNfromHoriz, res_label); num_args++;
    224     scr_data->res_text = XtCreateManagedWidget("resourceText",
    225 						  asciiTextWidgetClass,
    226 						  form, args, num_args);
    227 
    228     num_args = 0;
    229     XtSetArg(args[num_args], (String)XtNfromVert, scr_data->res_text); num_args++;
    230     (void)  XtCreateManagedWidget("valueLabel", labelWidgetClass,
    231 				  form, args, num_args);
    232 
    233     num_args = 0;
    234     XtSetArg(args[num_args], (String)XtNfromHoriz, res_label); num_args++;
    235     XtSetArg(args[num_args], (String)XtNfromVert, scr_data->res_text); num_args++;
    236     scr_data->val_text = XtCreateManagedWidget("valueText",
    237 						  asciiTextWidgetClass,
    238 						  form, args, num_args);
    239 
    240     num_args = 0;
    241     XtSetArg(args[num_args], (String)XtNfromVert, scr_data->val_text); num_args++;
    242     do_it = XtCreateManagedWidget("setValues", commandWidgetClass,
    243 					  form, args, num_args);
    244 
    245     num_args = 0;
    246     XtSetArg(args[num_args], (String)XtNfromVert, scr_data->val_text); num_args++;
    247     XtSetArg(args[num_args], (String)XtNfromHoriz, do_it); num_args++;
    248     cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
    249 				   form, args, num_args);
    250 
    251     XtAddCallback(do_it, (String)XtNcallback, DoSetValues, NULL);
    252     XtAddCallback(cancel, (String)XtNcallback, CancelSetValues, NULL);
    253 
    254 /*
    255  * Initialize the text entry fields.
    256  */
    257 
    258     {
    259 	Pixel color;
    260 
    261 	num_args = 0;
    262 	XtSetArg(args[num_args], (String)XtNbackground, &color); num_args++;
    263 	XtGetValues(scr_data->val_text, args, num_args);
    264 
    265 	num_args = 0;
    266 	XtSetArg(args[num_args], (String)XtNborderColor, color); num_args++;
    267 	XtSetValues(scr_data->val_text, args, num_args);
    268 
    269 	XtSetKeyboardFocus(form, scr_data->res_text);
    270     }
    271 }
    272 
    273 /*	Function Name: DoSetValues
    274  *	Description: Performs a SetValues.
    275  *	Arguments: w - the widget that called this.
    276  *                 junk, garbage - ** UNUSED **.
    277  *	Returns: none.
    278  */
    279 
    280 /* ARGSUSED */
    281 static void
    282 DoSetValues(Widget w, XtPointer junk, XtPointer garbage)
    283 {
    284     ProtocolStream * stream = &(global_client.stream);
    285     char *res_name, *res_value;
    286     Arg args[1];
    287     Cardinal i;
    288 
    289     if (global_tree_info->num_nodes == 0) {
    290 	SetMessage(global_screen_data.info_label,
    291 		   res_labels[23]);
    292 	return;
    293     }
    294 
    295     XtSetArg(args[0], (String)XtNstring, &res_name);
    296     XtGetValues(global_screen_data.res_text, args, ONE);
    297 
    298     XtSetArg(args[0], (String)XtNstring, &res_value);
    299     XtGetValues(global_screen_data.val_text, args, ONE);
    300 
    301     _XEditResResetStream(stream);
    302     _XEditResPutString8(stream, res_name);
    303     _XEditResPutString8(stream, XtRString);
    304     _XEditResPutString8(stream, res_value);
    305     _XEditResPut16(stream, global_tree_info->num_nodes);
    306 
    307     for (i = 0; i < global_tree_info->num_nodes; i++)
    308 	InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
    309 
    310     SetCommand(w, LocalSetValues, NULL);
    311 }
    312 
    313 /*	Function Name: CancelSetValues
    314  *	Description: Pops down the setvalues popup.
    315  *	Arguments: w - any grandchild of the popup.
    316  *                 junk, garbage - ** UNUSED **.
    317  *	Returns: none.
    318  */
    319 
    320 /* ARGSUSED */
    321 static void
    322 CancelSetValues(Widget w, XtPointer junk, XtPointer garbage)
    323 {
    324     XtPopdown(XtParent(XtParent(w)));
    325 }
    326