xenocara/app/editres/svpopup.c

322 lines
8.9 KiB
C
Raw 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.
*
* Author: Chris D. Peterson, MIT X Consortium
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h> /* Get standard string definations. */
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/Shell.h>
#include <X11/Xaw/AsciiText.h>
2018-05-21 09:15:36 -06:00
#include <X11/Xaw/Cardinals.h>
#include <X11/Xaw/Command.h>
2006-11-25 13:07:29 -07:00
#include <X11/Xaw/Form.h>
2018-05-21 09:15:36 -06:00
#include <X11/Xaw/Label.h>
2006-11-25 13:07:29 -07:00
#include <stdio.h>
#ifdef XKB
#include <X11/extensions/XKBbells.h>
#endif
#include "editresP.h"
static void _SetField ( Widget new, Widget old );
static void CreateSetValuesPopup ( Widget parent, ScreenData * scr_data );
static void DoSetValues ( Widget w, XtPointer junk, XtPointer garbage );
static void CancelSetValues ( Widget w, XtPointer junk, XtPointer garbage );
/* Function Name: PopupSetValues
* Description: This function pops up the setvalues dialog
* Arguments: parent - the parent of the setvalues popup.
* event - the event that caused this popup, or NULL.
* Returns: none
*/
/* ARGSUSED */
void
2010-05-31 13:33:38 -06:00
PopupSetValues(Widget parent, XEvent *event)
2006-11-25 13:07:29 -07:00
{
Arg args[1];
if (global_tree_info == NULL) {
SetMessage(global_screen_data.info_label,
res_labels[17]);
return;
}
2018-05-21 09:15:36 -06:00
/*
2006-11-25 13:07:29 -07:00
* Check and possibly create the popup.
*/
if (global_screen_data.set_values_popup == NULL)
CreateSetValuesPopup(parent, &global_screen_data);
/*
* Clear out the old strings, and set the active widget to the name widget.
*/
XtSetArg(args[0], XtNstring, "");
XtSetValues(global_screen_data.res_text, args, ONE);
XtSetValues(global_screen_data.val_text, args, ONE);
_SetField(global_screen_data.res_text, global_screen_data.val_text);
/*
* Pop it up.
*/
PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
}
/* Function Name: ModifySVEntry
2018-05-21 09:15:36 -06:00
* Description: Action routine that can be bound to the set values
* dialog box's Text Widget that will send input to the
2006-11-25 13:07:29 -07:00
* field specified.
2018-05-21 09:15:36 -06:00
* Arguments: (Standard Action Routine args)
2006-11-25 13:07:29 -07:00
* Returns: none.
*/
/* ARGSUSED */
2018-05-21 09:15:36 -06:00
void
2010-05-31 13:33:38 -06:00
ModifySVEntry(Widget w, XEvent *event, String *params, Cardinal *num_params)
2006-11-25 13:07:29 -07:00
{
Widget new, old;
char msg[BUFSIZ];
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
if (*num_params != 1) {
2018-05-21 09:15:36 -06:00
strcpy(msg,
2006-11-25 13:07:29 -07:00
res_labels[21]);
SetMessage(global_screen_data.info_label, msg);
return;
}
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
switch (params[0][0]) {
case 'r':
case 'R':
new = global_screen_data.res_text;
old = global_screen_data.val_text;
break;
case 'v':
case 'V':
new = global_screen_data.val_text;
old = global_screen_data.res_text;
break;
default:
2018-05-21 09:15:36 -06:00
snprintf(msg, sizeof(msg), res_labels[22]);
2006-11-25 13:07:29 -07:00
SetMessage(global_screen_data.info_label, msg);
return;
}
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
_SetField(new, old);
}
/************************************************************
*
* Private Functions
*
************************************************************/
/* Function Name: _SetField
* Description: Sets the current text entry field.
* Arguments: new, old - new and old text fields.
* Returns: none
*/
static void
2010-05-31 13:33:38 -06:00
_SetField(Widget new, Widget old)
2006-11-25 13:07:29 -07:00
{
Arg args[2];
Pixel new_border, old_border, old_bg;
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
if (!XtIsSensitive(new)) {
#ifdef XKB
/* Don't set field to an inactive Widget. */
2018-05-21 09:15:36 -06:00
XkbStdBell(XtDisplay(old), XtWindow(new), 0, XkbBI_InvalidLocation);
2006-11-25 13:07:29 -07:00
#else
XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
#endif
return;
}
2018-05-21 09:15:36 -06:00
XtSetKeyboardFocus(XtParent(new), new);
2006-11-25 13:07:29 -07:00
XtSetArg(args[0], XtNborderColor, &old_border);
XtSetArg(args[1], XtNbackground, &old_bg);
XtGetValues(new, args, TWO);
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
XtSetArg(args[0], XtNborderColor, &new_border);
XtGetValues(old, args, ONE);
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
if (old_border != old_bg) /* Colors are already correct, return. */
return;
XtSetArg(args[0], XtNborderColor, old_border);
XtSetValues(old, args, ONE);
XtSetArg(args[0], XtNborderColor, new_border);
XtSetValues(new, args, ONE);
}
/* Function Name: CreateSetValuesPopup
* Description: Creates the setvalues popup.
* Arguments: parent - the parent of the popup.
* scr_data - the data about this screen.
* Returns: the set values popup.
*/
static void
2010-05-31 13:33:38 -06:00
CreateSetValuesPopup(Widget parent, ScreenData *scr_data)
2006-11-25 13:07:29 -07:00
{
Widget form, cancel, do_it, label;
Widget res_label;
Arg args[10];
Cardinal num_args;
2018-05-21 09:15:36 -06:00
scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup",
transientShellWidgetClass,
2006-11-25 13:07:29 -07:00
parent, NULL, ZERO);
2018-05-21 09:15:36 -06:00
form = XtCreateManagedWidget("form", formWidgetClass,
2006-11-25 13:07:29 -07:00
scr_data->set_values_popup, NULL, ZERO);
num_args = 0;
label = XtCreateManagedWidget("label", labelWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNfromVert, label); num_args++;
res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNfromVert, label); num_args++;
XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
2018-05-21 09:15:36 -06:00
scr_data->res_text = XtCreateManagedWidget("resourceText",
2006-11-25 13:07:29 -07:00
asciiTextWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
(void) XtCreateManagedWidget("valueLabel", labelWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
2018-05-21 09:15:36 -06:00
scr_data->val_text = XtCreateManagedWidget("valueText",
2006-11-25 13:07:29 -07:00
asciiTextWidgetClass,
form, args, num_args);
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
num_args = 0;
XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
2018-05-21 09:15:36 -06:00
do_it = XtCreateManagedWidget("setValues", commandWidgetClass,
2006-11-25 13:07:29 -07:00
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
XtSetArg(args[num_args], XtNfromHoriz, do_it); num_args++;
cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
form, args, num_args);
XtAddCallback(do_it, XtNcallback, DoSetValues, NULL);
XtAddCallback(cancel, XtNcallback, CancelSetValues, NULL);
/*
* Initialize the text entry fields.
*/
{
Pixel color;
num_args = 0;
XtSetArg(args[num_args], XtNbackground, &color); num_args++;
XtGetValues(scr_data->val_text, args, num_args);
num_args = 0;
XtSetArg(args[num_args], XtNborderColor, color); num_args++;
XtSetValues(scr_data->val_text, args, num_args);
XtSetKeyboardFocus(form, scr_data->res_text);
}
}
/* Function Name: DoSetValues
* Description: Performs a SetValues.
* Arguments: w - the widget that called this.
* junk, garbage - ** UNUSED **.
* Returns: none.
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
DoSetValues(Widget w, XtPointer junk, XtPointer garbage)
2006-11-25 13:07:29 -07:00
{
ProtocolStream * stream = &(global_client.stream);
char *res_name, *res_value;
Arg args[1];
Cardinal i;
if (global_tree_info->num_nodes == 0) {
SetMessage(global_screen_data.info_label,
res_labels[23]);
return;
}
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
XtSetArg(args[0], XtNstring, &res_name);
XtGetValues(global_screen_data.res_text, args, ONE);
XtSetArg(args[0], XtNstring, &res_value);
XtGetValues(global_screen_data.val_text, args, ONE);
2018-05-21 09:15:36 -06:00
2006-11-25 13:07:29 -07:00
_XEditResResetStream(stream);
_XEditResPutString8(stream, res_name);
_XEditResPutString8(stream, XtRString);
_XEditResPutString8(stream, res_value);
_XEditResPut16(stream, global_tree_info->num_nodes);
2018-05-21 09:15:36 -06:00
for (i = 0; i < global_tree_info->num_nodes; i++)
2006-11-25 13:07:29 -07:00
InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
SetCommand(w, LocalSetValues, NULL);
}
/* Function Name: CancelSetValues
* Description: Pops down the setvalues popup.
* Arguments: w - any grandchild of the popup.
* junk, garbage - ** UNUSED **.
* Returns: none.
*/
/* ARGSUSED */
static void
2010-05-31 13:33:38 -06:00
CancelSetValues(Widget w, XtPointer junk, XtPointer garbage)
2006-11-25 13:07:29 -07:00
{
2018-05-21 09:15:36 -06:00
XtPopdown(XtParent(XtParent(w)));
2006-11-25 13:07:29 -07:00
}