TextPop.c revision 749
/* $XConsortium: TextPop.c,v 1.32 95/01/16 20:10:20 kaleb Exp $ */
/*
Copyright (c) 1989, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
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
X CONSORTIUM 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 X Consortium 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 X Consortium.
*/
/************************************************************
*
* 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 <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "XawI18n.h"
#include <stdio.h>
#include <errno.h>
#ifdef _LP64
extern int errno;
#else /* _LP64 */
#ifdef X_NOT_STDC_ENV
extern int errno;
#endif
#endif /* _LP64 */
static char* INSERT_FILE = "Enter Filename:";
static char* SEARCH_LABEL_1 = "Use <Tab> to change fields.";
static char* SEARCH_LABEL_2 = "Use ^q<Tab> for <Tab>.";
static char* DISMISS_NAME = "cancel";
#define DISMISS_NAME_LEN 6
static char* FORM_NAME = "form";
static char* LABEL_NAME = "label";
static char* TEXT_NAME = "text";
#define R_OFFSET 1
static void DoReplaceOne(), DoReplaceAll();
static void SetWMProtocolTranslations();
static String GetStringRaw();
static void AddInsertFileChildren();
static Boolean InsertFileNamed();
static void AddSearchChildren();
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;
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. */
{
"*** 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;
{
return(FALSE);
/* DELETE if (text.format == XawFmtWide) {
wchar_t* _XawTextMBToWC();
wchar_t* wstr;
wstr = _XawTextMBToWC(XtDisplay(tw), text.ptr, &(text.length));
wstr[text.length] = NULL;
XtFree(text.ptr);
text.ptr = (char *)wstr;
} else {
(text.ptr)[text.length] = '\0';
}*/
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.
*/
#define SEARCH_HEADER ("Text Widget - Search():")
void
Widget w;
{
#ifdef notdef
return;
}
#endif
"This action must have only",
"one or two parameters");
return;
}
if (*num_params == 2 )
else
/*This just does the equivalent of ptr = ""L, a waste because params[1] isnt W aligned.*/
} else
ptr = "";
switch(params[0][0]) {
case 'b': /* Left. */
case 'B':
break;
case 'f': /* Right. */
case 'F':
dir = XawsdRight;
break;
default:
"The first parameter must be",
"Either 'backward' or 'forward'");
return;
}
}
else if (*num_params > 1) {
}
}
/* 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;
{
else
R_OFFSET);
/* The Raw string in find.ptr may be WC I can't use here, so I re - call
GetString to get a tame version. */
if (pos == XawTextSearchError) {
char* msg;
char* fmt = "Could not find string \"%s\"";
} else
return FALSE;
}
if (dir == XawsdRight)
else
return TRUE;
}
/************************************************************
*
* 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;
else
else
R_OFFSET);
/* CONSTCOND */
while (TRUE) {
if (count != 0) {
if ( (new_pos == XawTextSearchError) ) {
if (count == 0) {
char* msg;
int len;
char* fmt = "*** Error: Could not find string \"%s\" ***";
} else
return(FALSE);
}
else
break;
}
}
else {
if (search->selection_changed) {
"", TRUE);
return(FALSE);
}
return(FALSE);
}
char* msg;
int len;
char* fmt = "'%s' with '%s'. ***";
} else
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;
{
struct SearchAndReplace * search;
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
{
char* bufp;
}
return ret;
}
/* 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{Raw}
* Description: Gets the value for the string in the popup.
* Arguments: text - the text widget whose string we will get.
*
* GetString returns the string as a MB.
* GetStringRaw returns the exact buffer contents suitable for a search.
*
*/
static String
{
return(string);
}
static String
{
char *_XawTextGetText();
}
/* 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);
}
/* Function Name: GetShell
* Description: Walks up the widget hierarchy to find the
* nearest shell widget.
* Arguments: w - the widget whose parent shell should be returned.
* Returns: The shell widget among the ancestors of w that is the
* fewest levels up in the widget hierarchy.
*/
static Widget
GetShell(w)
Widget w;
{
w = XtParent(w);
return (w);
}
String *p;
Cardinal n;
{
int i;
for (i=0; i < n; p++, i++)
return False;
}
static char *WM_DELETE_WINDOW = "WM_DELETE_WINDOW";
Widget w; /* popup shell */
{
/* Respond to a recognized WM protocol request iff
* event type is ClientMessage and no parameters are passed, or
* event type is ClientMessage and event data is matched to parameters, or
* event type isn't ClientMessage and parameters make a request.
*/
(*num_params == 0 || DO_DELETE_WINDOW))
||
}
}
static void SetWMProtocolTranslations(w)
Widget w; /* realized popup shell */
{
int i;
/* parse translation table once */
("<Message>WM_PROTOCOLS: XawWMProtocols()\n");
/* add actions once per application context */
if (i == list_size) {
list_size++;
app_context_list[i] = app_context;
}
/* establish communication between the window manager and each shell */
}