This is controlpanel.c in view mode; [Download] [Up]
/* -*-C-*-
********************************************************************************
*
* File: controlpanel.c
* RCS: $Header: /home/everest1/cattelan/work/xwebster.motif/RCS/controlpanel.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $
* Description: Control Panel for Webster
* Author: Niels Mayer, HPLabs
* Created: Wed Aug 31 21:40:58 1988
* Modified: Mon Mar 6 16:08:53 1989 (Niels Mayer) mayer@hplnpm
* Language: C
* Package: N/A
* Status: G-Job
*
* xwebster - dictionary browser
*
* Copyright 1988 Hewlett-Packard Company
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of HP not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. HP makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* Please send any improvements, bug fixes, useful modifications, and comments
* to mayer@hplabs.hp.com.
********************************************************************************
*/
static char rcs_identity[] = "@(#)$Header: /home/everest1/cattelan/work/xwebster.motif/RCS/controlpanel.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $";
#include "xwebster.h"
#include "user_prefs.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/Form.h>
#include <Xm/LabelG.h>
/*
#include <Xw/PButton.h>
#include <Xw/SText.h>
#include <Xw/TextEdit.h>
#include <Xw/TitleBar.h>
*/
static Widget control_panel_Wgt = NULL;
static Widget word_input_Wgt = NULL;
static Widget define_button_Wgt = NULL;
#ifdef DEFINE_FULL
static Widget define_full_button_Wgt = NULL;
#endif /* define full */
static Widget complete_button_Wgt = NULL;
static Widget endings_button_Wgt = NULL;
static Widget thesaurus_button_Wgt = NULL;
static Widget labelbar_Wgt = NULL;
static Widget formbar_Wgt = NULL;
static Widget quit_button_Wgt = NULL;
static Widget help_button_Wgt = NULL;
static int controlpanel_active = TRUE;
static int cur_word_is_from_textedit = TRUE;
extern int Webster_Send(/* char* buf */); /* from xwebster.c */
extern XtAppContext webster_app;
int moo; /* temp variable */
/******************************************************************************
* note that this callback is used for 3 different callbacks:
* 1) called from the controlpanel define_button_Wgt with client_data==NULL,
* this proc. assumes that word to be defined is in the word_input_Wgt.
* 2) called from Controlpanel_Define_Action (which is a actionproc that is
* called from the word_input_Wgt) with client_data==NULL, this proc.
* again assumes that word to be defined is in the word_input_Wgt.
* 3) called from a callback on a wordbutton_Wgt in module Wordlist,
* client_data is set to the word to be defined. In this case,
* subsequent calls to Controlpanel_Cur_Word_Is_From_TextEdit()
* will return false.
******************************************************************************/
XtCallbackProc
Controlpanel_Define_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
char buf[BUFSIZ];
extern Display* display;
if (!controlpanel_active) {
XBell(display, 100);
return(NULL);
}
Display_Def_Text_Reset(); /* clear the def buffer to show text is coming */
XtVaSetValues(define_button_Wgt,
XmNset, TRUE,
NULL); /*-action resulted in the callback*/
Controlpanel_Deactivate(); /* disallow further input till ready. */
if (client_data == NULL) { /* IF not called from Wordlist word button */
char* word; /* THEN get the word from word_input_Wgt */
word = (char *)XmTextFieldGetString(word_input_Wgt);
sscanf(word, "%[^\n]", temptext); /* get only one word, no newlines */
XtFree(word);
sprintf(buf, "DEFINE %s\r\n", temptext);
cur_word_is_from_textedit = TRUE;
}
else { /* ELSE get the word from the callback data */
sprintf(buf, "DEFINE %s\r\n", (char*)client_data);
Controlpanel_Set_Input_Word((char*)client_data);
cur_word_is_from_textedit = FALSE;
}
if (!Webster_Send(buf))
Controlpanel_Reactivate();
}
static void
Controlpanel_Define_Action(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Controlpanel_Define_Callback(w, NULL, NULL);
}
XtCallbackProc
Controlpanel_Define_button_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
char buf[BUFSIZ];
if (!strcmp(user_prefs.dictionary_source,"next")){
sprintf(buf,"INDEX dictionary\r\n");
if (!Webster_Send(buf))
Controlpanel_Reactivate();
};
Controlpanel_Define_Callback(widget, client_data, call_data);
}
/******************************************************************************
*
******************************************************************************/
XtCallbackProc
Controlpanel_Thesaurus_button_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
char buf[BUFSIZ];
sprintf(buf,"INDEX thesaurus\r\n");
if (!Webster_Send(buf))
Controlpanel_Reactivate();
Controlpanel_Define_Callback(widget, client_data, call_data);
}
static void
Controlpanel_Thesaurus_Action(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Controlpanel_Thesaurus_button_Callback(w, NULL, NULL);
}
/******************************************************************************
*
******************************************************************************/
#ifdef DEFINE_FULL
XtCallbackuser_prefsProc
Controlpanel_Define_full_button_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
char buf[BUFSIZ];
sprintf(buf,"INDEX dictionary-full\r\n");
if (!Webster_Send(buf))
Controlpanel_Reactivate();
Controlpanel_Define_Callback(widget, client_data, call_data);
}
/******************************************************************************
*
******************************************************************************/
static void
Controlpanel_Define_full_Action(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Controlpanel_Define_full_button_Callback(w, NULL, NULL);
}
/******************************************************************************
*
******************************************************************************/
#endif /* Define Full */
static XtCallbackProc
Controlpanel_Complete_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
char buf[BUFSIZ];
char* word;
extern Display* display;
if (!controlpanel_active) {
XBell(display, 100);
return(NULL);
}
/* show em which button they hit even if a key-*/
XtVaSetValues(complete_button_Wgt,
XmNset, TRUE,
NULL); /*-action resulted in the callback*/
Controlpanel_Deactivate(); /* disallow further input till ready. */
word = (char *)XmTextFieldGetString(word_input_Wgt);
sscanf(word, "%[^\n]", temptext); /* don't get newlines */
XtFree(word);
sprintf(buf, "COMPLETE %s\r\n", temptext);
cur_word_is_from_textedit = TRUE;
if (!Webster_Send(buf))
Controlpanel_Reactivate();
}
/******************************************************************************
*
******************************************************************************/
static void
Controlpanel_Complete_Action(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Controlpanel_Complete_Callback(w, NULL, NULL);
}
/******************************************************************************
*
******************************************************************************/
static XtCallbackProc
Controlpanel_Endings_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
char buf[BUFSIZ];
char* word;
extern Display* display;
if (!controlpanel_active) {
XBell(display, 100);
return(NULL);
}
XtVaSetValues(endings_button_Wgt,
XmNset, TRUE,
NULL); /*-action resulted in the callback*/
Controlpanel_Deactivate(); /* disallow further input till ready. */
word = (char *)XmTextFieldGetString(word_input_Wgt);
sscanf(word, "%[^\n]", temptext); /* get only one word, no newlines */
XtFree(word);
sprintf(buf, "ENDINGS %s\r\n", temptext);
cur_word_is_from_textedit = TRUE;
if (!Webster_Send(buf))
Controlpanel_Reactivate();
}
/******************************************************************************
*
******************************************************************************/
static void
Controlpanel_Endings_Action(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Controlpanel_Endings_Callback(w, NULL, NULL);
}
/******************************************************************************
*
******************************************************************************/
static XtCallbackProc
Controlpanel_Quit_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
/*
* note that the quit button is the only one that remains active all the time.
* That's becauese it's ok to quit xwebster anytime even when it hasn't
* completed it's transaction with the webster server.
*/
extern int webster_Socket; /* in main.c */
close(webster_Socket);
exit(0);
}
/******************************************************************************
*
******************************************************************************/
static XtCallbackProc
Controlpanel_Help_Callback(widget, client_data, call_data)
Widget widget;
caddr_t client_data;
caddr_t call_data;
{
extern Display* display;
if (!controlpanel_active) {
XBell(display, 100);
return(NULL);
}
Display_Def_Show_Help();
}
/******************************************************************************
*
******************************************************************************/
static void
Controlpanel_Noop_Action(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
extern Display* display;
XBell(display, 100);
}
XtActionsRec word_input_Wgt_actions_table [] = {
{"webster-define-word", Controlpanel_Define_Action},
{"webster-complete-word", Controlpanel_Complete_Action},
{"webster-list-endings", Controlpanel_Endings_Action},
{"webster-thesaurus-word", Controlpanel_Thesaurus_Action},
{"webster-no-op", Controlpanel_Noop_Action},
};
/******************************************************************************
*
******************************************************************************/
void
Controlpanel_Init(w)
Widget w;
{
control_panel_Wgt = XtVaCreateManagedWidget("control_panel",
xmFormWidgetClass,
w,
NULL);
word_input_Wgt = XtVaCreateManagedWidget("word_input",
xmTextFieldWidgetClass,
control_panel_Wgt,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
/*
XtAddCallback(word_input_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Define_Callback,
NULL);
*/
XtAppAddActions(webster_app,
word_input_Wgt_actions_table,
XtNumber(word_input_Wgt_actions_table));
define_button_Wgt = XtVaCreateManagedWidget("define",
xmPushButtonWidgetClass,
control_panel_Wgt,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget, word_input_Wgt,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(define_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Define_button_Callback,
NULL);
#ifdef DEFINE_FULL
define_full_button_Wgt = XtVaCreateManagedWidget("define_full",
xmPushButtonWidgetClass,
control_panel_Wgt,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget, define_button_Wgt,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(define_full_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Define_full_button_Callback,
NULL);
#endif /* Define full */
complete_button_Wgt = XtVaCreateManagedWidget("complete",
xmPushButtonWidgetClass,
control_panel_Wgt,
XmNleftAttachment,XmATTACH_WIDGET,
#ifdef DEFINE_FULL
XmNleftWidget,define_full_button_Wgt,
#else
XmNleftWidget,define_button_Wgt,
#endif /* Define full */
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(complete_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Complete_Callback,
NULL);
endings_button_Wgt = XtVaCreateManagedWidget("endings",
xmPushButtonWidgetClass,
control_panel_Wgt,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,complete_button_Wgt,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(endings_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Endings_Callback,
NULL);
thesaurus_button_Wgt = XtVaCreateWidget("thesaurus",
xmPushButtonWidgetClass,
control_panel_Wgt,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget, endings_button_Wgt ,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
if (!strcmp(user_prefs.dictionary_source,"next"))
XtManageChild(thesaurus_button_Wgt);
XtAddCallback(thesaurus_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Thesaurus_button_Callback,
NULL);
{/*
* force the controlpanel to have no sash's -- do this by setting XtNmin
* and XtNmax constraint resources to the same values -- the height of the
* widget. See XWVPANED(3x) for details.
*/
Dimension height;
XtVaGetValues(control_panel_Wgt,
XmNheight, &height,
NULL);
XtVaSetValues(control_panel_Wgt,
XmNminHeight, height,
XmNmaxHeight, height,
NULL);
}
}
/******************************************************************************
*
******************************************************************************/
void
Controlpanel_Titlebar_Init(parent_Wgt)
Widget parent_Wgt;
{
extern char xwebster_version[];
XmString label = XmStringCreateSimple(xwebster_version);
formbar_Wgt = XtVaCreateManagedWidget("titlebar",
xmFormWidgetClass,
parent_Wgt,
NULL);
quit_button_Wgt = XtVaCreateManagedWidget("quit",
xmPushButtonWidgetClass,
formbar_Wgt,
XmNleftAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(quit_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Quit_Callback,
NULL);
help_button_Wgt = XtVaCreateManagedWidget("help",
xmPushButtonWidgetClass,
formbar_Wgt,
XmNrightAttachment,XmATTACH_FORM,
NULL);
XtAddCallback(help_button_Wgt,
XmNactivateCallback,
(XtCallbackProc)Controlpanel_Help_Callback,
NULL);
labelbar_Wgt = XtVaCreateManagedWidget("labelbar",
xmLabelWidgetClass,
formbar_Wgt,
XmNlabelString, label,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, quit_button_Wgt,
XmNalignment, XmALIGNMENT_CENTER,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, help_button_Wgt,
NULL);
XmStringFree(label);
{/*
* force the titlebar to have no sash's -- do this by setting XtNmin
* and XtNmax constraint resources to the same values -- the height of the
* widget. See XWVPANED(3x) for details.
*/
Dimension height;
XtVaGetValues(formbar_Wgt,
XmNheight, &height,
NULL);
XtVaSetValues(formbar_Wgt,
XmNminHeight, height,
XmNmaxHeight, height,
NULL);
}
}
/******************************************************************************
*
******************************************************************************/
Controlpanel_Titlebar_Set_Label(str)
char* str;
{
XmString label = XmStringCreateSimple(str);
XtVaSetValues(labelbar_Wgt,
XmNlabelString, label,
NULL);
XmStringFree(label);
}
/******************************************************************************
*
******************************************************************************/
Controlpanel_Deactivate()
{
controlpanel_active = FALSE;
#ifndef SLOW_X_SERVER
XtSetSensitive(define_button_Wgt, FALSE);
#ifdef DEFINE_FULL
XtSetSensitive(define_full_button_Wgt, FALSE);
#endif /* Define full */
XtSetSensitive(complete_button_Wgt, FALSE);
XtSetSensitive(endings_button_Wgt, FALSE);
XtSetSensitive(thesaurus_button_Wgt, FALSE);
/* XtSetSensitive(quit_button_Wgt, FALSE); --> allow quit while server busy*/
XtSetSensitive(help_button_Wgt, FALSE);
Wordlist_Deactivate();
#endif
}
/******************************************************************************
*
******************************************************************************/
Controlpanel_Reactivate()
{
controlpanel_active = TRUE;
#ifndef SLOW_X_SERVER
XtSetSensitive(define_button_Wgt, TRUE);
#ifdef DEFINE_FULL
XtSetSensitive(define_full_button_Wgt, TRUE);
#endif /* Define Full */
XtSetSensitive(complete_button_Wgt, TRUE);
XtSetSensitive(endings_button_Wgt, TRUE);
XtSetSensitive(thesaurus_button_Wgt, TRUE);
/* XtSetSensitive(quit_button_Wgt, TRUE); */
XtSetSensitive(help_button_Wgt, TRUE);
Wordlist_Reactivate();
#endif
/*
* the following is a lamo hack to fix a "feature" of PushButtons -- when they're
* pressed, they invert colors. if the push callback then insensitizes them,
* upon resensitizing they'll not invert back to the "off" color. So force them
* off here.
*/
XtVaSetValues(define_button_Wgt,
XmNset, FALSE,
NULL);
#ifdef DEFINE_FULL
XtVaSetValues(define_full_button_Wgt,
XmNset, FALSE,
NULL);
#endif /* Define full */
XtVaSetValues(complete_button_Wgt,
XmNset, FALSE,
NULL);
XtVaSetValues(endings_button_Wgt,
XmNset, FALSE,
NULL);
XtVaSetValues(thesaurus_button_Wgt,
XmNset, FALSE,
NULL);
XtVaSetValues(quit_button_Wgt,
XmNset, FALSE,
NULL);
XtVaSetValues(help_button_Wgt,
XmNset, FALSE,
NULL);
}
/******************************************************************************
*
******************************************************************************/
Controlpanel_Set_Input_Word(word)
char* word;
{
XmTextFieldSetString(word_input_Wgt,word);
XmTextFieldSetInsertionPosition(word_input_Wgt, XmTextGetLastPosition(word_input_Wgt));
}
/******************************************************************************
*
******************************************************************************/
int Controlpanel_Cur_Word_Is_From_TextEdit()
{
return(cur_word_is_from_textedit);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.