/* $XConsortium: AsciiSink.c,v 1.62 94/04/17 20:11:41 kaleb Exp $ */
/***********************************************************
Copyright (c) 1987, 1988, 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.
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, 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 name of Digital 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.
******************************************************************/
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "AsciiSinkP.h"
#ifdef GETLASTPOS
#endif
static void Initialize(), Destroy();
static void SetTabs();
};
{
/* core_class fields */
/* class_name */ "AsciiSink",
/* widget_size */ sizeof(AsciiSinkRec),
/* class_initialize */ XawInitializeWidgetSet,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* obj1 */ NULL,
/* obj2 */ NULL,
/* obj3 */ 0,
/* resources */ resources,
/* xrm_class */ NULLQUARK,
/* obj4 */ FALSE,
/* obj5 */ FALSE,
/* obj6 */ FALSE,
/* obj7 */ FALSE,
/* destroy */ Destroy,
/* obj8 */ NULL,
/* obj9 */ NULL,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* obj10 */ NULL,
/* get_values_hook */ NULL,
/* obj11 */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* obj12 */ NULL,
/* obj13 */ NULL,
/* obj14 */ NULL,
/* extension */ NULL
},
/* text_sink_class fields */
{
/* DisplayText */ DisplayText,
/* InsertCursor */ InsertCursor,
/* ClearToBackground */ XtInheritClearToBackground,
/* FindPosition */ FindPosition,
/* FindDistance */ FindDistance,
/* Resolve */ Resolve,
/* MaxLines */ MaxLines,
/* MaxHeight */ MaxHeight,
/* SetTabs */ SetTabs,
/* GetCursorBounds */ GetCursorBounds
},
/* ascii_sink_class fields */
{
/* unused */ 0
}
};
/* Utilities */
static int
CharWidth (w, x, c)
Widget w;
int x;
unsigned char c;
{
if ( c == XawLF ) return(0);
if (c == XawTAB) {
/* Adjust for Left Margin. */
if (x < *tab) {
return *tab - x;
else
return 0;
}
}
return 0;
}
if ( (nonPrinting = (c < (unsigned char) XawSP)) )
c += '@';
else {
c = XawSP;
nonPrinting = False;
}
else
if (nonPrinting)
return width;
}
/* Function Name: PaintText
* Description: Actually paints the text into the windoe.
* Arguments: w - the text widget.
* gc - gc to paint text with.
* x, y - location to paint the text.
* buf, len - buffer and length of text to paint.
* Returns: the width of the text painted, or 0.
*
* NOTE: If this string attempts to paint past the end of the window
* then this function will return zero.
*/
static Dimension
Widget w;
Position x, y;
unsigned char * buf;
int len;
{
if ( ((int) width) <= -x) /* Don't draw if we can't see it. */
return(width);
(unsigned int) width,
return(0);
}
return(width);
}
/* Sink Object Functions */
/*
* This function does not know about drawing more than one line of text.
*/
static void
Widget w;
Position x, y;
{
int j, k;
if (j >= BUFSIZ) { /* buffer full, dump the text. */
j = 0;
}
continue;
else if (buf[j] == '\t') {
return;
x += temp;
invgc, (int) x,
(unsigned int) width,
x += width;
j = -1;
}
else if ( buf[j] < (unsigned char) ' ' ) {
buf[j] = '^';
j++;
}
else
buf[j] = ' ';
}
j++;
}
}
if (j > 0)
}
static Pixmap
Screen *s;
{
}
/* Function Name: GetCursorBounds
* Description: Returns the size and location of the cursor.
* Arguments: w - the text object.
* RETURNED rect - an X rectangle to return the cursor bounds in.
* Returns: none.
*/
static void
Widget w;
XRectangle * rect;
{
}
/*
* The following procedure manages the "insert" cursor.
*/
static void
Widget w;
Position x, y;
{
GetCursorBounds(w, &rect);
}
/*
* Given two positions, find the distance between them.
*/
static void
Widget w;
int fromx; /* Horizontal location of first position. */
int *resWidth; /* Distance between fromPos and resPos. */
int *resHeight; /* Height required. */
{
unsigned char c;
/* we may not need this */
*resWidth = 0;
if (c == XawLF) {
index++;
break;
}
}
}
static void
Widget w;
int fromx; /* Horizontal location of starting position.*/
int width; /* Desired width. */
int stopAtWordBreak; /* Whether the resulting position should be at
a word break. */
int *resWidth; /* Actual width used. */
int *resHeight; /* Height required. */
{
unsigned char c;
*resWidth = 0;
c = 0;
}
if (c == XawLF) {
index++;
break;
}
}
index--;
if (stopAtWordBreak && whiteSpaceSeen) {
}
}
}
static void
Widget w;
{
if (*leftPos > GETLASTPOS)
*leftPos = GETLASTPOS;
}
static void
{
}
/***** Public routines *****/
/* Function Name: Initialize
* Description: Initializes the TextSink Object.
* Arguments: request, new - the requested and new values for the object
* instance.
* Returns: none.
*
*/
/* ARGSUSED */
static void
{
}
/* Function Name: Destroy
* Description: This function cleans up when the object is
* destroyed.
* Arguments: w - the AsciiSink Object.
* Returns: none.
*/
static void
Destroy(w)
Widget w;
{
}
/* Function Name: SetValues
* Description: Sets the values for the AsciiSink
* Arguments: current - current state of the object.
* request - what was requested.
* new - what the object will become.
* Returns: True if redisplay is needed.
*/
/* ARGSUSED */
static Boolean
{
GetGC(w);
} else {
(w->ascii_sink.display_nonprinting !=
}
return False;
}
/* Function Name: MaxLines
* Description: Finds the Maximum number of lines that will fit in
* a given height.
* Arguments: w - the AsciiSink Object.
* height - height to fit lines into.
* Returns: the number of lines that will fit.
*/
/* ARGSUSED */
static int
Widget w;
{
int font_height;
return( ((int) height) / font_height );
}
/* Function Name: MaxHeight
* Description: Finds the Minium height that will contain a given number
* lines.
* Arguments: w - the AsciiSink Object.
* lines - the number of lines.
* Returns: the height.
*/
/* ARGSUSED */
static int
Widget w;
int lines;
{
}
/* Function Name: SetTabs
* Description: Sets the Tab stops.
* Arguments: w - the AsciiSink Object.
* tab_count - the number of tabs in the list.
* tabs - the text positions of the tabs.
* Returns: none
*/
static void
Widget w;
int tab_count;
short *tabs;
{
int i;
unsigned long figure_width = 0;
/*
* Find the figure width of the current font.
*/
if ( (XA_FIGURE_WIDTH != None) &&
(figure_width == 0)) )
else
}
for ( i = 0 ; i < tab_count ; i++ ) {
}
#ifndef NO_TAB_FIX
}
#endif
}