#endif /* lint && SABER */
/***********************************************************
Copyright 1989 by the Massachusetts Institute of Technology,
Cambridge, Massachusetts.
All Rights Reserved
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 names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
/************************************************************
*
* This file is broken up into three sections one dealing with
* each of the three popups created here:
*
* FileInsert, Search, and Replace.
*
* There is also a section at the end for utility functions
* used by all more than one of these dialogs.
*
* The following functions are the only non-static ones defined
* in this module. They are located at the begining of the
* section that contains this dialog box that uses them.
*
* void _XawTextInsertFileAction(w, event, params, num_params);
* void _XawTextDoSearchAction(w, event, params, num_params);
* void _XawTextDoReplaceAction(w, event, params, num_params);
* void _XawTextInsertFile(w, event, params, num_params);
*
*************************************************************/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <X11/StringDefs.h>
#include <X11/IntrinsicP.h>
#include <./Xaw3_1TextP.h>
#include <./Xaw3_1AsciiText.h>
#include <./Xaw3_1Cardinals.h>
#include <./Xaw3_1Command.h>
#include <./Xaw3_1Form.h>
#include <./Xaw3_1Toggle.h>
extern char* sys_errlist[];
static void DoReplaceOne(), DoReplaceAll();
static Widget CreateDialog();
static char radio_trans_string[] =
"<Btn1Down>,<Btn1Up>: set() notify()";
static char search_text_trans[] =
"~Shift<Key>Return: DoSearchAction(Popdown) \n\
Shift<Key>Return: DoSearchAction() SetField(Replace) \n\
Ctrl<Key>q,<Key>Tab: insert-char() \n\
Ctrl<Key>c: PopdownSearchAction() \n\
<Btn1Down>: select-start() SetField(Search) \n\
<Key>Tab: DoSearchAction() SetField(Replace)";
static char rep_text_trans[] =
"~Shift<Key>Return: DoReplaceAction(Popdown) \n\
Shift<Key>Return: SetField(Search) \n\
Ctrl<Key>q,<Key>Tab: insert-char() \n\
Ctrl<Key>c: PopdownSearchAction() \n\
<Btn1Down>: select-start() DoSearchAction() SetField(Replace)\n\
<Key>Tab: SetField(Search)";
/************************************************************
*
* This section of the file contains all the functions that
* the file insert dialog box uses.
*
************************************************************/
/* Function Name: _XawTextInsertFileAction
* Description: Action routine that can be bound to dialog box's
* Text Widget that will insert a file into the main
* Text Widget.
* Arguments: (Standard Action Routine args)
* Returns: none.
*/
/* ARGSUSED */
void
Widget w;
{
}
/* Function Name: _XawTextInsertFile
* Description: Action routine that can be bound to the text widget
* it will popup the insert file dialog box.
* Arguments: w - the text widget.
* event - X Event (used to get x and y location).
* params, num_params - the parameter list.
* Returns: none.
*
* NOTE:
*
* The parameter list may contain one entry.
*
* Entry: This entry is optional and contains the value of the default
* file to insert.
*/
void
Widget w;
{
char * ptr;
static void AddInsertFileChildren();
if (edit_mode != XawtextEdit) {
return;
}
if (*num_params == 0)
ptr = "";
else
}
}
/* Function Name: PopdownFileInsert
* Description: Pops down the file insert button.
* Arguments: w - the widget that caused this action.
* closure - a pointer to the main text widget that
* popped up this dialog.
* call_data - *** NOT USED ***.
* Returns: none.
*/
/* ARGSUSED */
static void
Widget w; /* The Dialog Button Pressed. */
{
}
/* Function Name: DoInsert
* Description: Actually insert the file named in the text widget
* of the file dialog.
* Arguments: w - the widget that activated this callback.
* closure - a pointer to the text widget to insert the
* file into.
* Returns: none.
*/
/* ARGSUSED */
static void
Widget w; /* The Dialog Button Pressed. */
{
static Boolean InsertFileNamed();
"*** Error: Could not get text widget from file insert popup");
}
else
return;
}
else
}
/* Function Name: InsertFileNamed
* Description: Inserts a file into the text widget.
* Arguments: tw - The text widget to insert this file into.
* str - name of the file to insert.
* Returns: TRUE if the insert was sucessful, FALSE otherwise.
*/
static Boolean
char *str;
{
int fid;
return(FALSE);
/*
* If the replace failed then remove what we have
* replaced so far, and return an error.
*/
return(FALSE);
}
}
return(TRUE);
}
/* Function Name: AddInsertFileChildren
* Description: Adds all children to the InsertFile dialog widget.
* Arguments: form - the form widget for the insert dialog widget.
* ptr - a pointer to the initial string for the Text Widget.
* tw - the main text widget.
* Returns: none
*/
static void
char * ptr;
{
num_args = 0;
num_args = 0;
num_args = 0;
num_args = 0;
/*
* Bind <CR> to insert file.
*/
}
/************************************************************
*
* This section of the file contains all the functions that
* the search dialog box uses.
*
************************************************************/
/* Function Name: _XawTextDoSearchAction
* Description: Action routine that can be bound to dialog box's
* Text Widget that will search for a string in the main
* Text Widget.
* Arguments: (Standard Action Routine args)
* Returns: none.
*
* Note:
*
* If the search was sucessful and the argument popdown is passed to
* this action routine then the widget will automatically popdown the
* search widget.
*/
/* ARGSUSED */
void
Widget w;
{
if ( (*num_params == 1) &&
}
/* Function Name: _XawTextPopdownSearchAction
* Description: Action routine that can be bound to dialog box's
* Text Widget that will popdown the search widget.
* Arguments: (Standard Action Routine args)
* Returns: none.
*/
/* ARGSUSED */
void
Widget w;
{
}
/* Function Name: PopdownSeach
* Description: Pops down the search widget and resets it.
* Arguments: w - *** NOT USED ***.
* closure - a pointer to the search structure.
* call_data - *** NOT USED ***.
* Returns: none
*/
/* ARGSUSED */
static void
Widget w;
{
}
/* Function Name: SearchButton
* Description: Performs a search when the button is clicked.
* Arguments: w - *** NOT USED **.
* closure - a pointer to the search info.
* call_data - *** NOT USED ***.
* Returns:
*/
/* ARGSUSED */
static void
Widget w;
{
}
/* Function Name: _XawTextSearch
* Description: Action routine that can be bound to the text widget
* it will popup the search dialog box.
* Arguments: w - the text widget.
* event - X Event (used to get x and y location).
* params, num_params - the parameter list.
* Returns: none.
*
* NOTE:
*
* The parameter list contains one or two entries that may be the following.
*
* First Entry: The first entry is the direction to search by default.
* This arguement must be specified and may have a value of
* "left" or "right".
*
* Second Entry: This entry is optional and contains the value of the default
* string to search for.
*/
void
Widget w;
{
static void AddSearchChildren();
#ifdef notdef
return;
}
#endif
"one or two parameters");
return;
}
else if (*num_params == 1)
ptr = "";
else
switch(params[0][0]) {
case 'b': /* Left. */
case 'B':
break;
case 'f': /* Right. */
case 'F':
dir = XawsdRight;
break;
default:
"Either 'backward' or 'forward'");
return;
}
}
}
/* Function Name: InitializeSearchWidget
* Description: This function initializes the search widget and
* is called each time the search widget is poped up.
* Arguments: search - the search widget structure.
* dir - direction to search.
* replace_active - state of the sensitivity for the
* replace button.
* Returns: none.
*/
static void
struct SearchAndReplace * search;
{
switch (dir) {
case XawsdLeft:
break;
case XawsdRight:
break;
default:
break;
}
}
/* Function Name: AddSearchChildren
* Description: Adds all children to the Search Dialog Widget.
* Arguments: form - the form widget for the search widget.
* ptr - a pointer to the initial string for the Text Widget.
* tw - the main text widget.
* Returns: none.
*/
static void
char * ptr;
{
num_args = 0;
num_args = 0;
/*
* We need to add R_OFFSET to the radio_data, because the value zero (0)
* has special meaning.
*/
num_args = 0;
num_args++;
num_args = 0;
num_args++;
{
}
num_args = 0;
num_args = 0;
num_args = 0;
num_args = 0;
num_args = 0;
num_args = 0;
num_args = 0;
num_args = 0;
/*
* Initialize the text entry fields.
*/
{
num_args = 0;
num_args = 0;
}
/*
* Bind Extra translations.
*/
}
/* Function Name: DoSearch
* Description: Performs a search.
* Arguments: search - the serach structure.
* Returns: TRUE if sucessful.
*/
/* ARGSUSED */
static Boolean
struct SearchAndReplace * search;
{
R_OFFSET);
if (pos == XawTextSearchError)
else {
if (dir == XawsdRight)
else
return(TRUE);
}
return(FALSE);
}
/************************************************************
*
* This section of the file contains all the functions that
* the replace dialog box uses.
*
************************************************************/
/* Function Name: _XawTextDoReplaceAction
* Description: Action routine that can be bound to dialog box's
* Text Widget that will replace a string in the main
* Text Widget.
* Arguments: (Standard Action Routine args)
* Returns: none.
*/
/* ARGSUSED */
void
Widget w;
{
if ( (*num_params == 1) &&
}
/* Function Name: DoReplaceOne
* Description: Replaces the first instance of the string
* in the search dialog's text widget
* with the one in the replace dialog's text widget.
* Arguments: w - *** Not Used ***.
* closure - a pointer to the search structure.
* call_data - *** Not Used ***.
* Returns: none.
*/
/* ARGSUSED */
static void
Widget w; /* The Button Pressed. */
{
}
/* Function Name: DoReplaceOne
* Description: Replaces every instance of the string
* in the search dialog's text widget
* with the one in the replace dialog's text widget.
* Arguments: w - *** Not Used ***.
* closure - a pointer to the search structure.
* call_data - *** Not Used ***.
* Returns: none.
*/
/* ARGSUSED */
static void
Widget w; /* The Button Pressed. */
{
}
/* Function Name: Replace
* Description: This is the function that does the real work of
* replacing strings in the main text widget.
* Arguments: tw - the Text Widget to replce the string in.
* once_only - If TRUE then only replace the first one found.
* other replace all of them.
* show_current - If true then leave the selection on the
* string that was just replaced, otherwise
* move it onto the next one.
* Returns: none.
*/
static Boolean
struct SearchAndReplace * search;
{
int count = 0;
R_OFFSET);
while (TRUE) {
if (count != 0) {
if ( (new_pos == XawTextSearchError) ) {
if (count == 0) {
return(FALSE);
}
else
break;
}
}
else {
if (search->selection_changed) {
"", TRUE);
return(FALSE);
}
return(FALSE);
}
return(FALSE);
}
if (dir == XawsdRight)
else
if (once_only)
if (show_current)
break;
else {
return(TRUE);
}
count++;
}
else
return(TRUE);
}
/* Function Name: SetSearchLabels
* Description: Sets both the search labels, and also rings the bell
* Arguments: search - the search structure.
* msg1, msg2 - message to put in each search label.
* bell - if TRUE then ring bell.
* Returns: none.
*/
static void
struct SearchAndReplace * search;
{
if (bell)
}
/************************************************************
*
* This section of the file contains utility routines used by
* other functions in this file.
*
************************************************************/
/* Function Name: _XawTextSetField
* Description: Action routine that can be bound to dialog box's
* Text Widget that will send input to the field specified.
* Arguments: (Standard Action Routine args)
* Returns: none.
*/
/* ARGSUSED */
void
Widget w;
{
if (*num_params != 1) {
"exactly one argument. ***", TRUE);
return;
}
switch (params[0][0]) {
case 's':
case 'S':
break;
case 'r':
case 'R':
break;
default:
"be either 'Search' or 'Replace'. ***", TRUE);
return;
}
}
/* Function Name: SetField
* Description: Sets the current text field.
* Arguments: new, old - new and old text fields.
* Returns: none
*/
static void
{
if (!XtIsSensitive(new)) {
return;
}
return;
}
/* Function Name: SetResourceByName
* Description: Sets a resource in any of the dialog children given
* name of the child and the shell widget of the dialog.
* Arguments: shell - shell widget of the popup.
* name - name of the child.
* res_name - name of the resource.
* value - the value of the resource.
* Returns: TRUE if sucessful.
*/
static Boolean
{
return(TRUE);
}
return(FALSE);
}
/* Function Name: SetResource
* Description: Sets a resource in a widget
* Arguments: w - the widget.
* res_name - name of the resource.
* value - the value of the resource.
* Returns: none.
*/
static void
Widget w;
char * res_name;
{
}
/* Function Name: GetString
* Description: Gets the value for the string in the popup.
* Arguments: text - the text widget whose string we will get.
* Returns: the string.
*/
static String
{
return(string);
}
/* Function Name: CenterWidgetOnPoint.
* Description: Centers a shell widget on a point relative to
* the root window.
* Arguments: w - the shell widget.
* event - event containing the location of the point
* Returns: none.
*
* NOTE: The widget is not allowed to go off the screen.
*/
static void
Widget w;
{
case ButtonPress:
case ButtonRelease:
break;
case KeyPress:
case KeyRelease:
break;
default:
return;
}
}
num_args = 0;
if (x < 0) x = 0;
if (y < 0) y = 0;
num_args = 0;
}
/* Function Name: CreateDialog
* Description: Actually creates a dialog.
* Arguments: parent - the parent of the dialog - the main text widget.
* ptr - initial_string for the dialog.
* name - name of the dialog.
* func - function to create the children of the dialog.
* Returns: the popup shell of the dialog.
*
* NOTE:
*
* The function argument is passed the following arguements.
*
* form - the from widget that is the dialog.
* ptr - the initial string for the dialog's text widget.
* parent - the parent of the dialog - the main text widget.
*/
static Widget
void (*func)();
{
num_args = 0;
return(popup);
}