749N/A#if ( !defined(lint) && !defined(SABER) )
749N/Astatic char Xrcsid[] = "$XConsortium: TextSrc.c,v 1.4 89/10/31 17:12:19 kit Exp $";
749N/A#endif
749N/A
749N/A/*
749N/A * Copyright 1989 Massachusetts Institute of Technology
749N/A *
749N/A * Permission to use, copy, modify, distribute, and sell this software and its
749N/A * documentation for any purpose is hereby granted without fee, provided that
749N/A * the above copyright notice appear in all copies and that both that
749N/A * copyright notice and this permission notice appear in supporting
749N/A * documentation, and that the name of M.I.T. not be used in advertising or
749N/A * publicity pertaining to distribution of the software without specific,
749N/A * written prior permission. M.I.T. makes no representations about the
749N/A * suitability of this software for any purpose. It is provided "as is"
749N/A * without express or implied warranty.
749N/A *
749N/A * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
749N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
749N/A * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
749N/A * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
749N/A * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
749N/A * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
749N/A *
749N/A * Author: Chris Peterson, MIT X Consortium.
749N/A *
749N/A * Much code taken from X11R3 String and Disk Sources.
749N/A */
749N/A
749N/A/*
749N/A * TextSrc.c - TextSrc object. (For use with the text widget).
749N/A *
749N/A */
749N/A
749N/A#include <stdio.h>
749N/A#include <ctype.h>
749N/A#include <X11/IntrinsicP.h>
749N/A#include <X11/StringDefs.h>
749N/A#include <./Xaw3_1XawInit.h>
749N/A#include <./Xaw3_1TextSrcP.h>
749N/A
749N/A/****************************************************************
749N/A *
749N/A * Full class record constant
749N/A *
749N/A ****************************************************************/
749N/A
749N/A/* Private Data */
749N/A
749N/A#define offset(field) XtOffset(TextSrcObject, textSrc.field)
749N/Astatic XtResource resources[] = {
749N/A {XtNeditType, XtCEditType, XtREditMode, sizeof(XawTextEditType),
749N/A offset(edit_mode), XtRString, "read"},
749N/A};
749N/A
749N/Astatic void ClassPartInitialize(), SetSelection();
749N/Astatic Boolean ConvertSelection();
749N/Astatic XawTextPosition Search(), Scan(), Read();
749N/Astatic int Replace();
749N/A
749N/A#define SuperClass (&objectClassRec)
749N/ATextSrcClassRec textSrcClassRec = {
749N/A {
749N/A/* core_class fields */
749N/A /* superclass */ (WidgetClass) SuperClass,
749N/A /* class_name */ "TextSrc",
749N/A /* widget_size */ sizeof(TextSrcRec),
749N/A /* class_initialize */ XawInitializeWidgetSet,
749N/A /* class_part_initialize */ ClassPartInitialize,
749N/A /* class_inited */ FALSE,
749N/A /* initialize */ NULL,
749N/A /* initialize_hook */ NULL,
749N/A /* realize */ NULL,
749N/A /* actions */ NULL,
749N/A /* num_actions */ 0,
749N/A /* resources */ resources,
749N/A /* num_resources */ XtNumber(resources),
749N/A /* xrm_class */ NULLQUARK,
749N/A /* compress_motion */ FALSE,
749N/A /* compress_exposure */ FALSE,
749N/A /* compress_enterleave */ FALSE,
749N/A /* visible_interest */ FALSE,
749N/A /* destroy */ NULL,
749N/A /* resize */ NULL,
749N/A /* expose */ NULL,
749N/A /* set_values */ NULL,
749N/A /* set_values_hook */ NULL,
749N/A /* set_values_almost */ NULL,
749N/A /* get_values_hook */ NULL,
749N/A /* accept_focus */ NULL,
749N/A /* version */ XtVersion,
749N/A /* callback_private */ NULL,
749N/A /* tm_table */ NULL,
749N/A /* query_geometry */ NULL,
749N/A /* display_accelerator */ NULL,
749N/A /* extension */ NULL
749N/A },
749N/A/* textSrc_class fields */
749N/A {
749N/A /* Read */ Read,
749N/A /* Replace */ Replace,
749N/A /* Scan */ Scan,
749N/A /* Search */ Search,
749N/A /* SetSelection */ SetSelection,
749N/A /* ConvertSelection */ ConvertSelection
749N/A }
749N/A};
749N/A
749N/AWidgetClass textSrcObjectClass = (WidgetClass)&textSrcClassRec;
749N/A
749N/Astatic void
749N/AClassPartInitialize(wc)
749N/AWidgetClass wc;
749N/A{
749N/A register TextSrcObjectClass t_src, superC;
749N/A
749N/A t_src = (TextSrcObjectClass) wc;
749N/A superC = (TextSrcObjectClass) t_src->object_class.superclass;
749N/A
749N/A/*
749N/A * We don't need to check for null super since we'll get to TextSrc
749N/A * eventually.
749N/A */
749N/A
749N/A if (t_src->textSrc_class.Read == XtInheritRead)
749N/A t_src->textSrc_class.Read = superC->textSrc_class.Read;
749N/A
749N/A if (t_src->textSrc_class.Replace == XtInheritReplace)
749N/A t_src->textSrc_class.Replace = superC->textSrc_class.Replace;
749N/A
749N/A if (t_src->textSrc_class.Scan == XtInheritScan)
749N/A t_src->textSrc_class.Scan = superC->textSrc_class.Scan;
749N/A
749N/A if (t_src->textSrc_class.Search == XtInheritSearch)
749N/A t_src->textSrc_class.Search = superC->textSrc_class.Search;
749N/A
749N/A if (t_src->textSrc_class.SetSelection == XtInheritSetSelection)
749N/A t_src->textSrc_class.SetSelection = superC->textSrc_class.SetSelection;
749N/A
749N/A if (t_src->textSrc_class.ConvertSelection == XtInheritConvertSelection)
749N/A t_src->textSrc_class.ConvertSelection =
749N/A superC->textSrc_class.ConvertSelection;
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Class specific methods.
749N/A *
749N/A ************************************************************/
749N/A
749N/A/* Function Name: Read
749N/A * Description: This function reads the source.
749N/A * Arguments: w - the TextSrc Object.
749N/A * pos - position of the text to retreive.
749N/A * RETURNED text - text block that will contain returned text.
749N/A * length - maximum number of characters to read.
749N/A * Returns: The number of characters read into the buffer.
749N/A */
749N/A
749N/A/* ARGSUSED */
749N/Astatic XawTextPosition
749N/ARead(w, pos, text, length)
749N/AWidget w;
749N/AXawTextPosition pos;
749N/AXawTextBlock *text;
749N/Aint length;
749N/A{
749N/A XtAppError(XtWidgetToApplicationContext(w),
749N/A "TextSrc Object: No read function is defined.");
749N/A}
749N/A
749N/A/* Function Name: Replace.
749N/A * Description: Replaces a block of text with new text.
749N/A * Arguments: src - the Text Source Object.
749N/A * startPos, endPos - ends of text that will be removed.
749N/A * text - new text to be inserted into buffer at startPos.
749N/A * Returns: XawEditError.
749N/A */
749N/A
749N/A/*ARGSUSED*/
749N/Astatic int
749N/AReplace (w, startPos, endPos, text)
749N/AWidget w;
749N/AXawTextPosition startPos, endPos;
749N/AXawTextBlock *text;
749N/A{
749N/A return(XawEditError);
749N/A}
749N/A
749N/A/* Function Name: Scan
749N/A * Description: Scans the text source for the number and type
749N/A * of item specified.
749N/A * Arguments: w - the TextSrc Object.
749N/A * position - the position to start scanning.
749N/A * type - type of thing to scan for.
749N/A * dir - direction to scan.
749N/A * count - which occurance if this thing to search for.
749N/A * include - whether or not to include the character found in
749N/A * the position that is returned.
749N/A * Returns: EXITS WITH AN ERROR MESSAGE.
749N/A *
749N/A */
749N/A
749N/A/* ARGSUSED */
749N/Astatic
749N/AXawTextPosition
749N/AScan (w, position, type, dir, count, include)
749N/AWidget w;
749N/AXawTextPosition position;
749N/AXawTextScanType type;
749N/AXawTextScanDirection dir;
749N/Aint count;
749N/ABoolean include;
749N/A{
749N/A XtAppError(XtWidgetToApplicationContext(w),
749N/A "TextSrc Object: No SCAN function is defined.");
749N/A}
749N/A
749N/A/* Function Name: Search
749N/A * Description: Searchs the text source for the text block passed
749N/A * Arguments: w - the TextSource Object.
749N/A * position - the position to start scanning.
749N/A * dir - direction to scan.
749N/A * text - the text block to search for.
749N/A * Returns: XawTextSearchError.
749N/A */
749N/A
749N/A/* ARGSUSED */
749N/Astatic XawTextPosition
749N/ASearch(w, position, dir, text)
749N/AWidget w;
749N/AXawTextPosition position;
749N/AXawTextScanDirection dir;
749N/AXawTextBlock * text;
749N/A{
749N/A return(XawTextSearchError);
749N/A}
749N/A
749N/A/* Function Name: ConvertSelection
749N/A * Description: Dummy selection converter.
749N/A * Arguments: w - the TextSrc object.
749N/A * selection - the current selection atom.
749N/A * target - the current target atom.
749N/A * type - the type to conver the selection to.
749N/A * RETURNED value, length - the return value that has been converted.
749N/A * RETURNED format - the format of the returned value.
749N/A * Returns: TRUE if the selection has been converted.
749N/A *
749N/A */
749N/A
749N/A/* ARGSUSED */
749N/Astatic Boolean
749N/AConvertSelection(w, selection, target, type, value, length, format)
749N/AWidget w;
749N/AAtom * selection, * target, * type;
749N/Acaddr_t * value;
749N/Aunsigned long * length;
749N/Aint * format;
749N/A{
749N/A return(FALSE);
749N/A}
749N/A
749N/A/* Function Name: SetSelection
749N/A * Description: allows special setting of the selection.
749N/A * Arguments: w - the TextSrc object.
749N/A * left, right - bounds of the selection.
749N/A * selection - the selection atom.
749N/A * Returns: none
749N/A */
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/ASetSelection(w, left, right, selection)
749N/AWidget w;
749N/AXawTextPosition left, right;
749N/AAtom selection;
749N/A{
749N/A /* This space intentionally left blank. */
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Public Functions.
749N/A *
749N/A ************************************************************/
749N/A
749N/A/* Function Name: XawTextSourceRead
749N/A * Description: This function reads the source.
749N/A * Arguments: w - the TextSrc Object.
749N/A * pos - position of the text to retreive.
749N/A * RETURNED text - text block that will contain returned text.
749N/A * length - maximum number of characters to read.
749N/A * Returns: The number of characters read into the buffer.
749N/A */
749N/A
749N/AXawTextPosition
749N/AXawTextSourceRead(w, pos, text, length)
749N/AWidget w;
749N/AXawTextPosition pos;
749N/AXawTextBlock *text;
749N/Aint length;
749N/A{
749N/A TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
749N/A
749N/A return((*class->textSrc_class.Read)(w, pos, text, length));
749N/A}
749N/A
749N/A/* Function Name: XawTextSourceReplace.
749N/A * Description: Replaces a block of text with new text.
749N/A * Arguments: src - the Text Source Object.
749N/A * startPos, endPos - ends of text that will be removed.
749N/A * text - new text to be inserted into buffer at startPos.
749N/A * Returns: XawEditError or XawEditDone.
749N/A */
749N/A
749N/A/*ARGSUSED*/
749N/Aint
749N/AXawTextSourceReplace (w, startPos, endPos, text)
749N/AWidget w;
749N/AXawTextPosition startPos, endPos;
749N/AXawTextBlock *text;
749N/A{
749N/A TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
749N/A
749N/A return((*class->textSrc_class.Replace)(w, startPos, endPos, text));
749N/A}
749N/A
749N/A/* Function Name: XawTextSourceScan
749N/A * Description: Scans the text source for the number and type
749N/A * of item specified.
749N/A * Arguments: w - the TextSrc Object.
749N/A * position - the position to start scanning.
749N/A * type - type of thing to scan for.
749N/A * dir - direction to scan.
749N/A * count - which occurance if this thing to search for.
749N/A * include - whether or not to include the character found in
749N/A * the position that is returned.
749N/A * Returns: The position of the text.
749N/A *
749N/A */
749N/A
749N/AXawTextPosition
749N/AXawTextSourceScan(w, position, type, dir, count, include)
749N/AWidget w;
749N/AXawTextPosition position;
749N/AXawTextScanType type;
749N/AXawTextScanDirection dir;
749N/Aint count;
749N/ABoolean include;
749N/A{
749N/A TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
749N/A
749N/A return((*class->textSrc_class.Scan)(w, position, type, dir, count, include));
749N/A}
749N/A
749N/A/* Function Name: XawTextSourceSearch
749N/A * Description: Searchs the text source for the text block passed
749N/A * Arguments: w - the TextSource Object.
749N/A * position - the position to start scanning.
749N/A * dir - direction to scan.
749N/A * text - the text block to search for.
749N/A * Returns: The position of the text we are searching for or
749N/A * XawTextSearchError.
749N/A */
749N/A
749N/AXawTextPosition
749N/AXawTextSourceSearch(w, position, dir, text)
749N/AWidget w;
749N/AXawTextPosition position;
749N/AXawTextScanDirection dir;
749N/AXawTextBlock * text;
749N/A{
749N/A TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
749N/A
749N/A return((*class->textSrc_class.Search)(w, position, dir, text));
749N/A}
749N/A
749N/A/* Function Name: XawTextSourceConvertSelection
749N/A * Description: Dummy selection converter.
749N/A * Arguments: w - the TextSrc object.
749N/A * selection - the current selection atom.
749N/A * target - the current target atom.
749N/A * type - the type to conver the selection to.
749N/A * RETURNED value, length - the return value that has been converted.
749N/A * RETURNED format - the format of the returned value.
749N/A * Returns: TRUE if the selection has been converted.
749N/A *
749N/A */
749N/A
749N/ABoolean
749N/AXawTextSourceConvertSelection(w, selection,
749N/A target, type, value, length, format)
749N/AWidget w;
749N/AAtom * selection, * target, * type;
749N/Acaddr_t * value;
749N/Aunsigned long * length;
749N/Aint * format;
749N/A{
749N/A TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
749N/A
749N/A return((*class->textSrc_class.ConvertSelection)(w, selection, target, type,
749N/A value, length, format));
749N/A}
749N/A
749N/A/* Function Name: XawTextSourceSetSelection
749N/A * Description: allows special setting of the selection.
749N/A * Arguments: w - the TextSrc object.
749N/A * left, right - bounds of the selection.
749N/A * selection - the selection atom.
749N/A * Returns: none
749N/A */
749N/A
749N/Avoid
749N/AXawTextSourceSetSelection(w, left, right, selection)
749N/AWidget w;
749N/AXawTextPosition left, right;
749N/AAtom selection;
749N/A{
749N/A TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
749N/A
749N/A (*class->textSrc_class.SetSelection)(w, left, right, selection);
749N/A}