AsciiSink.c

Go to the documentation of this file.
00001 /* $XConsortium: AsciiSink.c,v 1.62 94/04/17 20:11:41 kaleb Exp $ */
00002 
00003 /***********************************************************
00004 
00005 Copyright (c) 1987, 1988, 1994  X Consortium
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 
00024 Except as contained in this notice, the name of the X Consortium shall not be
00025 used in advertising or otherwise to promote the sale, use or other dealings
00026 in this Software without prior written authorization from the X Consortium.
00027 
00028 
00029 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
00030 
00031                         All Rights Reserved
00032 
00033 Permission to use, copy, modify, and distribute this software and its 
00034 documentation for any purpose and without fee is hereby granted, 
00035 provided that the above copyright notice appear in all copies and that
00036 both that copyright notice and this permission notice appear in 
00037 supporting documentation, and that the name of Digital not be
00038 used in advertising or publicity pertaining to distribution of the
00039 software without specific, written prior permission.  
00040 
00041 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00042 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00043 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00044 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00045 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00046 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00047 SOFTWARE.
00048 
00049 ******************************************************************/
00050 
00051 #include <stdio.h>
00052 
00053 #include <X11/Xatom.h>
00054 #include <X11/IntrinsicP.h>
00055 #include <X11/StringDefs.h>
00056 #include <X11/Xaw3d/XawInit.h>
00057 #include <X11/Xaw3d/AsciiSinkP.h>
00058 #include <X11/Xaw3d/AsciiSrcP.h>        /* For source function defs. */
00059 #include <X11/Xaw3d/TextP.h>    /* I also reach into the text widget. */
00060 
00061 #ifdef GETLASTPOS
00062 #undef GETLASTPOS               /* We will use our own GETLASTPOS. */
00063 #endif
00064 
00065 #define GETLASTPOS XawTextSourceScan(source, (XawTextPosition) 0, XawstAll, XawsdRight, 1, TRUE)
00066 
00067 static void Initialize(), Destroy();
00068 static Boolean SetValues();
00069 static int MaxLines(), MaxHeight();
00070 static void SetTabs();
00071 
00072 static void DisplayText(), InsertCursor(), FindPosition();
00073 static void FindDistance(), Resolve(), GetCursorBounds();
00074 
00075 #define offset(field) XtOffsetOf(AsciiSinkRec, ascii_sink.field)
00076 
00077 static XtResource resources[] = {
00078     {XtNfont, XtCFont, XtRFontStruct, sizeof (XFontStruct *),
00079         offset(font), XtRString, XtDefaultFont},
00080     {XtNecho, XtCOutput, XtRBoolean, sizeof(Boolean),
00081         offset(echo), XtRImmediate, (XtPointer) True},
00082     {XtNdisplayNonprinting, XtCOutput, XtRBoolean, sizeof(Boolean),
00083         offset(display_nonprinting), XtRImmediate, (XtPointer) True},
00084 };
00085 #undef offset
00086 
00087 #define SuperClass              (&textSinkClassRec)
00088 AsciiSinkClassRec asciiSinkClassRec = {
00089   {
00090 /* core_class fields */ 
00091     /* superclass               */      (WidgetClass) SuperClass,
00092     /* class_name               */      "AsciiSink",
00093     /* widget_size              */      sizeof(AsciiSinkRec),
00094     /* class_initialize         */      XawInitializeWidgetSet,
00095     /* class_part_initialize    */      NULL,
00096     /* class_inited             */      FALSE,
00097     /* initialize               */      Initialize,
00098     /* initialize_hook          */      NULL,
00099     /* obj1                     */      NULL,
00100     /* obj2                     */      NULL,
00101     /* obj3                     */      0,
00102     /* resources                */      resources,
00103     /* num_resources            */      XtNumber(resources),
00104     /* xrm_class                */      NULLQUARK,
00105     /* obj4                     */      FALSE,
00106     /* obj5                     */      FALSE,
00107     /* obj6                     */      FALSE,
00108     /* obj7                     */      FALSE,
00109     /* destroy                  */      Destroy,
00110     /* obj8                     */      NULL,
00111     /* obj9                     */      NULL,
00112     /* set_values               */      SetValues,
00113     /* set_values_hook          */      NULL,
00114     /* obj10                    */      NULL,
00115     /* get_values_hook          */      NULL,
00116     /* obj11                    */      NULL,
00117     /* version                  */      XtVersion,
00118     /* callback_private         */      NULL,
00119     /* obj12                    */      NULL,
00120     /* obj13                    */      NULL,
00121     /* obj14                    */      NULL,
00122     /* extension                */      NULL
00123   },
00124 /* text_sink_class fields */
00125   {
00126     /* DisplayText              */      DisplayText,
00127     /* InsertCursor             */      InsertCursor,
00128     /* ClearToBackground        */      XtInheritClearToBackground,
00129     /* FindPosition             */      FindPosition,
00130     /* FindDistance             */      FindDistance,
00131     /* Resolve                  */      Resolve,
00132     /* MaxLines                 */      MaxLines,
00133     /* MaxHeight                */      MaxHeight,
00134     /* SetTabs                  */      SetTabs,
00135     /* GetCursorBounds          */      GetCursorBounds
00136   },
00137 /* ascii_sink_class fields */
00138   {
00139     /* unused                   */      0
00140   }
00141 };
00142 
00143 WidgetClass asciiSinkObjectClass = (WidgetClass)&asciiSinkClassRec;
00144 
00145 /* Utilities */
00146 
00147 static int 
00148 CharWidth (w, x, c)
00149 Widget w;
00150 int x;
00151 unsigned char c;
00152 {
00153     int    i, width, nonPrinting;
00154     AsciiSinkObject sink = (AsciiSinkObject) w;
00155     XFontStruct *font = sink->ascii_sink.font;
00156     Position *tab;
00157 
00158     if ( c == XawLF ) return(0);
00159 
00160     if (c == XawTAB) {
00161         /* Adjust for Left Margin. */
00162         x -= ((TextWidget) XtParent(w))->text.margin.left;
00163 
00164         if (x >= (int)XtParent(w)->core.width) return 0;
00165         for (i = 0, tab = sink->text_sink.tabs ; 
00166              i < sink->text_sink.tab_count ; i++, tab++) {
00167             if (x < *tab) {
00168                 if (*tab < (int)XtParent(w)->core.width)
00169                     return *tab - x;
00170                 else
00171                     return 0;
00172             }
00173         }
00174         return 0;
00175     }
00176 
00177     if ( (nonPrinting = (c < (unsigned char) XawSP)) )
00178         if (sink->ascii_sink.display_nonprinting)
00179             c += '@';
00180         else {
00181             c = XawSP;
00182             nonPrinting = False;
00183         }
00184 
00185     if (font->per_char &&
00186             (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2))
00187         width = font->per_char[c - font->min_char_or_byte2].width;
00188     else
00189         width = font->min_bounds.width;
00190 
00191     if (nonPrinting)
00192         width += CharWidth(w, x, (unsigned char) '^');
00193 
00194     return width;
00195 }
00196 
00197 /*      Function Name: PaintText
00198  *      Description: Actually paints the text into the windoe.
00199  *      Arguments: w - the text widget.
00200  *                 gc - gc to paint text with.
00201  *                 x, y - location to paint the text.
00202  *                 buf, len - buffer and length of text to paint.
00203  *      Returns: the width of the text painted, or 0.
00204  *
00205  * NOTE:  If this string attempts to paint past the end of the window
00206  *        then this function will return zero.
00207  */
00208 
00209 static Dimension
00210 PaintText(w, gc, x, y, buf, len)
00211 Widget w;
00212 GC gc;
00213 Position x, y;
00214 unsigned char * buf;
00215 int len;
00216 {
00217     AsciiSinkObject sink = (AsciiSinkObject) w;
00218     TextWidget ctx = (TextWidget) XtParent(w);
00219 
00220     Position max_x;
00221     Dimension width = XTextWidth(sink->ascii_sink.font, (char *) buf, len); 
00222     max_x = (Position) ctx->core.width;
00223 
00224     if ( ((int) width) <= -x)              /* Don't draw if we can't see it. */
00225       return(width);
00226 
00227     XDrawImageString(XtDisplay(ctx), XtWindow(ctx), gc, 
00228                      (int) x, (int) y, (char *) buf, len);
00229     if ( (((Position) width + x) > max_x) && (ctx->text.margin.right != 0) ) {
00230         x = ctx->core.width - ctx->text.margin.right;
00231         width = ctx->text.margin.right;
00232         XFillRectangle(XtDisplay((Widget) ctx), XtWindow( (Widget) ctx),
00233                        sink->ascii_sink.normgc, (int) x,
00234                        (int) y - sink->ascii_sink.font->ascent, 
00235                        (unsigned int) width,
00236                        (unsigned int) (sink->ascii_sink.font->ascent +
00237                                        sink->ascii_sink.font->descent));
00238         return(0);
00239     }
00240     return(width);
00241 }
00242 
00243 /* Sink Object Functions */
00244 
00245 /*
00246  * This function does not know about drawing more than one line of text.
00247  */
00248  
00249 static void 
00250 DisplayText(w, x, y, pos1, pos2, highlight)
00251 Widget w;
00252 Position x, y;
00253 Boolean highlight;
00254 XawTextPosition pos1, pos2;
00255 {
00256     AsciiSinkObject sink = (AsciiSinkObject) w;
00257     Widget source = XawTextGetSource(XtParent(w));
00258     unsigned char buf[BUFSIZ];
00259 
00260     int j, k;
00261     XawTextBlock blk;
00262     GC gc = highlight ? sink->ascii_sink.invgc : sink->ascii_sink.normgc;
00263     GC invgc = highlight ? sink->ascii_sink.normgc : sink->ascii_sink.invgc;
00264 
00265     if (!sink->ascii_sink.echo) return;
00266 
00267     y += sink->ascii_sink.font->ascent;
00268     for ( j = 0 ; pos1 < pos2 ; ) {
00269         pos1 = XawTextSourceRead(source, pos1, &blk, (int) pos2 - pos1);
00270         for (k = 0; k < blk.length; k++) {
00271             if (j >= BUFSIZ) {  /* buffer full, dump the text. */
00272                 x += PaintText(w, gc, x, y, buf, j);
00273                 j = 0;
00274             }
00275             buf[j] = blk.ptr[k];
00276             if (buf[j] == XawLF)        /* line feeds ('\n') are not printed. */
00277                 continue;
00278 
00279             else if (buf[j] == '\t') {
00280                 Position temp = 0;
00281                 Dimension width;
00282 
00283                 if ((j != 0) && ((temp = PaintText(w, gc, x, y, buf, j)) == 0))
00284                   return;
00285 
00286                 x += temp;
00287                 width = CharWidth(w, x, (unsigned char) '\t');
00288                 XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
00289                                invgc, (int) x,
00290                                (int) y - sink->ascii_sink.font->ascent,
00291                                (unsigned int) width,
00292                                (unsigned int) (sink->ascii_sink.font->ascent +
00293                                                sink->ascii_sink.font->descent));
00294                 x += width;
00295                 j = -1;
00296             }
00297             else if ( buf[j] < (unsigned char) ' ' ) {
00298                 if (sink->ascii_sink.display_nonprinting) {
00299                     buf[j + 1] = buf[j] + '@';
00300                     buf[j] = '^';
00301                     j++;
00302                 }
00303                 else
00304                     buf[j] = ' ';
00305             }
00306             j++;
00307         }
00308     }
00309     if (j > 0)
00310         (void) PaintText(w, gc, x, y, buf, j);
00311 }
00312 
00313 #define insertCursor_width 6
00314 #define insertCursor_height 3
00315 static char insertCursor_bits[] = {0x0c, 0x1e, 0x33};
00316 
00317 static Pixmap
00318 CreateInsertCursor(s)
00319 Screen *s;
00320 {
00321     return (XCreateBitmapFromData (DisplayOfScreen(s), RootWindowOfScreen(s),
00322                   insertCursor_bits, insertCursor_width, insertCursor_height));
00323 }
00324 
00325 /*      Function Name: GetCursorBounds
00326  *      Description: Returns the size and location of the cursor.
00327  *      Arguments: w - the text object.
00328  * RETURNED        rect - an X rectangle to return the cursor bounds in.
00329  *      Returns: none.
00330  */
00331 
00332 static void
00333 GetCursorBounds(w, rect)
00334 Widget w;
00335 XRectangle * rect;
00336 {
00337     AsciiSinkObject sink = (AsciiSinkObject) w;
00338 
00339     rect->width = (unsigned short) insertCursor_width;
00340     rect->height = (unsigned short) insertCursor_height;
00341     rect->x = sink->ascii_sink.cursor_x - (short) (rect->width / 2);
00342     rect->y = sink->ascii_sink.cursor_y - (short) rect->height;
00343 }
00344 
00345 /*
00346  * The following procedure manages the "insert" cursor.
00347  */
00348 
00349 static void
00350 InsertCursor (w, x, y, state)
00351 Widget w;
00352 Position x, y;
00353 XawTextInsertState state;
00354 {
00355     AsciiSinkObject sink = (AsciiSinkObject) w;
00356     Widget text_widget = XtParent(w);
00357     XRectangle rect;
00358 
00359     sink->ascii_sink.cursor_x = x;
00360     sink->ascii_sink.cursor_y = y;
00361 
00362     GetCursorBounds(w, &rect);
00363     if (state != sink->ascii_sink.laststate && XtIsRealized(text_widget)) 
00364         XCopyPlane(XtDisplay(text_widget),
00365                    sink->ascii_sink.insertCursorOn,
00366                    XtWindow(text_widget), sink->ascii_sink.xorgc,
00367                    0, 0, (unsigned int) rect.width, (unsigned int) rect.height,
00368                    (int) rect.x, (int) rect.y, 1);
00369     sink->ascii_sink.laststate = state;
00370 }
00371 
00372 /*
00373  * Given two positions, find the distance between them.
00374  */
00375 
00376 static void
00377 FindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight)
00378 Widget w;
00379 XawTextPosition fromPos;        /* First position. */
00380 int fromx;                      /* Horizontal location of first position. */
00381 XawTextPosition toPos;          /* Second position. */
00382 int *resWidth;                  /* Distance between fromPos and resPos. */
00383 XawTextPosition *resPos;        /* Actual second position used. */
00384 int *resHeight;                 /* Height required. */
00385 {
00386     AsciiSinkObject sink = (AsciiSinkObject) w;
00387     Widget source = XawTextGetSource(XtParent(w));
00388 
00389     XawTextPosition index, lastPos;
00390     unsigned char c;
00391     XawTextBlock blk;
00392 
00393     /* we may not need this */
00394     lastPos = GETLASTPOS;
00395     XawTextSourceRead(source, fromPos, &blk, (int) toPos - fromPos);
00396     *resWidth = 0;
00397     for (index = fromPos; index != toPos && index < lastPos; index++) {
00398         if (index - blk.firstPos >= blk.length)
00399             XawTextSourceRead(source, index, &blk, (int) toPos - fromPos);
00400         c = blk.ptr[index - blk.firstPos];
00401         *resWidth += CharWidth(w, fromx + *resWidth, c);
00402         if (c == XawLF) {
00403             index++;
00404             break;
00405         }
00406     }
00407     *resPos = index;
00408     *resHeight = sink->ascii_sink.font->ascent +sink->ascii_sink.font->descent;
00409 }
00410 
00411 
00412 static void
00413 FindPosition(w, fromPos, fromx, width, stopAtWordBreak, 
00414                   resPos, resWidth, resHeight)
00415 Widget w;
00416 XawTextPosition fromPos;        /* Starting position. */
00417 int fromx;                      /* Horizontal location of starting position.*/
00418 int width;                      /* Desired width. */
00419 int stopAtWordBreak;            /* Whether the resulting position should be at
00420                                    a word break. */
00421 XawTextPosition *resPos;        /* Resulting position. */
00422 int *resWidth;                  /* Actual width used. */
00423 int *resHeight;                 /* Height required. */
00424 {
00425     AsciiSinkObject sink = (AsciiSinkObject) w;
00426     Widget source = XawTextGetSource(XtParent(w));
00427 
00428     XawTextPosition lastPos, index, whiteSpacePosition = 0;
00429     int     lastWidth = 0, whiteSpaceWidth = 0;
00430     Boolean whiteSpaceSeen;
00431     unsigned char c;
00432     XawTextBlock blk;
00433 
00434     lastPos = GETLASTPOS;
00435 
00436     XawTextSourceRead(source, fromPos, &blk, BUFSIZ);
00437     *resWidth = 0;
00438     whiteSpaceSeen = FALSE;
00439     c = 0;
00440     for (index = fromPos; *resWidth <= width && index < lastPos; index++) {
00441         lastWidth = *resWidth;
00442         if (index - blk.firstPos >= blk.length)
00443             XawTextSourceRead(source, index, &blk, BUFSIZ);
00444         c = blk.ptr[index - blk.firstPos];
00445         *resWidth += CharWidth(w, fromx + *resWidth, c);
00446 
00447         if ((c == XawSP || c == XawTAB) && *resWidth <= width) {
00448             whiteSpaceSeen = TRUE;
00449             whiteSpacePosition = index;
00450             whiteSpaceWidth = *resWidth;
00451         }
00452         if (c == XawLF) {
00453             index++;
00454             break;
00455         }
00456     }
00457     if (*resWidth > width && index > fromPos) {
00458         *resWidth = lastWidth;
00459         index--;
00460         if (stopAtWordBreak && whiteSpaceSeen) {
00461             index = whiteSpacePosition + 1;
00462             *resWidth = whiteSpaceWidth;
00463         }
00464     }
00465     if (index == lastPos && c != XawLF) index = lastPos + 1;
00466     *resPos = index;
00467     *resHeight = sink->ascii_sink.font->ascent +sink->ascii_sink.font->descent;
00468 }
00469 
00470 static void
00471 Resolve (w, pos, fromx, width, leftPos, rightPos)
00472 Widget w;
00473 XawTextPosition pos;
00474 int fromx, width;
00475 XawTextPosition *leftPos, *rightPos;
00476 {
00477     int resWidth, resHeight;
00478     Widget source = XawTextGetSource(XtParent(w));
00479 
00480     FindPosition(w, pos, fromx, width, FALSE, leftPos, &resWidth, &resHeight);
00481     if (*leftPos > GETLASTPOS)
00482       *leftPos = GETLASTPOS;
00483     *rightPos = *leftPos;
00484 }
00485 
00486 static void
00487 GetGC(sink)
00488 AsciiSinkObject sink;
00489 {
00490     XtGCMask valuemask = (GCFont | 
00491                           GCGraphicsExposures | GCForeground | GCBackground );
00492     XGCValues values;
00493 
00494     values.font = sink->ascii_sink.font->fid;
00495     values.graphics_exposures = (Bool) FALSE;
00496     
00497     values.foreground = sink->text_sink.foreground;
00498     values.background = sink->text_sink.background;
00499     sink->ascii_sink.normgc = XtGetGC((Widget)sink, valuemask, &values);
00500     
00501     values.foreground = sink->text_sink.background;
00502     values.background = sink->text_sink.foreground;
00503     sink->ascii_sink.invgc = XtGetGC((Widget)sink, valuemask, &values);
00504     
00505     values.function = GXxor;
00506     values.background = (unsigned long) 0L;     /* (pix ^ 0) = pix */
00507     values.foreground = (sink->text_sink.background ^ 
00508                          sink->text_sink.foreground);
00509     valuemask = GCGraphicsExposures | GCFunction | GCForeground | GCBackground;
00510     
00511     sink->ascii_sink.xorgc = XtGetGC((Widget)sink, valuemask, &values);
00512 }
00513 
00514 
00515 /***** Public routines *****/
00516 
00517 /*      Function Name: Initialize
00518  *      Description: Initializes the TextSink Object.
00519  *      Arguments: request, new - the requested and new values for the object
00520  *                                instance.
00521  *      Returns: none.
00522  *
00523  */
00524 
00525 /* ARGSUSED */
00526 static void
00527 Initialize(request, new, args, num_args)
00528 Widget request, new;
00529 ArgList args;
00530 Cardinal *num_args;
00531 {
00532     AsciiSinkObject sink = (AsciiSinkObject) new;
00533 
00534     GetGC(sink);
00535     
00536     sink->ascii_sink.insertCursorOn= CreateInsertCursor(XtScreenOfObject(new));
00537     sink->ascii_sink.laststate = XawisOff;
00538     sink->ascii_sink.cursor_x = sink->ascii_sink.cursor_y = 0;
00539 }
00540 
00541 /*      Function Name: Destroy
00542  *      Description: This function cleans up when the object is 
00543  *                   destroyed.
00544  *      Arguments: w - the AsciiSink Object.
00545  *      Returns: none.
00546  */
00547 
00548 static void
00549 Destroy(w)
00550 Widget w;
00551 {
00552    AsciiSinkObject sink = (AsciiSinkObject) w;
00553 
00554    XtReleaseGC(w, sink->ascii_sink.normgc);
00555    XtReleaseGC(w, sink->ascii_sink.invgc);
00556    XtReleaseGC(w, sink->ascii_sink.xorgc);
00557    XFreePixmap(XtDisplayOfObject(w), sink->ascii_sink.insertCursorOn);
00558 }
00559 
00560 /*      Function Name: SetValues
00561  *      Description: Sets the values for the AsciiSink
00562  *      Arguments: current - current state of the object.
00563  *                 request - what was requested.
00564  *                 new - what the object will become.
00565  *      Returns: True if redisplay is needed.
00566  */
00567 
00568 /* ARGSUSED */
00569 static Boolean
00570 SetValues(current, request, new, args, num_args)
00571 Widget current, request, new;
00572 ArgList args;
00573 Cardinal *num_args;
00574 {
00575     AsciiSinkObject w = (AsciiSinkObject) new;
00576     AsciiSinkObject old_w = (AsciiSinkObject) current;
00577 
00578     if (w->ascii_sink.font != old_w->ascii_sink.font
00579         || w->text_sink.background != old_w->text_sink.background
00580         || w->text_sink.foreground != old_w->text_sink.foreground) {
00581         XtReleaseGC((Widget)w, w->ascii_sink.normgc);
00582         XtReleaseGC((Widget)w, w->ascii_sink.invgc);
00583         XtReleaseGC((Widget)w, w->ascii_sink.xorgc);
00584         GetGC(w);
00585         ((TextWidget)XtParent(new))->text.redisplay_needed = True;
00586     } else {
00587         if ( (w->ascii_sink.echo != old_w->ascii_sink.echo) ||
00588              (w->ascii_sink.display_nonprinting != 
00589                                      old_w->ascii_sink.display_nonprinting) )
00590             ((TextWidget)XtParent(new))->text.redisplay_needed = True;
00591     }
00592     
00593     return False;
00594 }
00595 
00596 /*      Function Name: MaxLines
00597  *      Description: Finds the Maximum number of lines that will fit in
00598  *                   a given height.
00599  *      Arguments: w - the AsciiSink Object.
00600  *                 height - height to fit lines into.
00601  *      Returns: the number of lines that will fit.
00602  */
00603 
00604 /* ARGSUSED */
00605 static int
00606 MaxLines(w, height)
00607 Widget w;
00608 Dimension height;
00609 {
00610   AsciiSinkObject sink = (AsciiSinkObject) w;
00611   int font_height;
00612 
00613   font_height = sink->ascii_sink.font->ascent + sink->ascii_sink.font->descent;
00614   return( ((int) height) / font_height );
00615 }
00616 
00617 /*      Function Name: MaxHeight
00618  *      Description: Finds the Minium height that will contain a given number 
00619  *                   lines.
00620  *      Arguments: w - the AsciiSink Object.
00621  *                 lines - the number of lines.
00622  *      Returns: the height.
00623  */
00624 
00625 /* ARGSUSED */
00626 static int
00627 MaxHeight(w, lines)
00628 Widget w;
00629 int lines;
00630 {
00631   AsciiSinkObject sink = (AsciiSinkObject) w;
00632 
00633   return(lines * (sink->ascii_sink.font->ascent + 
00634                   sink->ascii_sink.font->descent));
00635 }
00636 
00637 /*      Function Name: SetTabs
00638  *      Description: Sets the Tab stops.
00639  *      Arguments: w - the AsciiSink Object.
00640  *                 tab_count - the number of tabs in the list.
00641  *                 tabs - the text positions of the tabs.
00642  *      Returns: none
00643  */
00644 
00645 static void
00646 SetTabs(w, tab_count, tabs)
00647 Widget w;
00648 int tab_count;
00649 short *tabs;
00650 {
00651   AsciiSinkObject sink = (AsciiSinkObject) w;
00652   int i;
00653   Atom XA_FIGURE_WIDTH;
00654   unsigned long figure_width = 0;
00655   XFontStruct *font = sink->ascii_sink.font;
00656 
00657 /*
00658  * Find the figure width of the current font.
00659  */
00660 
00661   XA_FIGURE_WIDTH = XInternAtom(XtDisplayOfObject(w), "FIGURE_WIDTH", FALSE);
00662   if ( (XA_FIGURE_WIDTH != None) && 
00663        ( (!XGetFontProperty(font, XA_FIGURE_WIDTH, &figure_width)) ||
00664          (figure_width == 0)) ) 
00665     if (font->per_char && font->min_char_or_byte2 <= '$' &&
00666         font->max_char_or_byte2 >= '$')
00667       figure_width = font->per_char['$' - font->min_char_or_byte2].width;
00668     else
00669       figure_width = font->max_bounds.width;
00670 
00671   if (tab_count > sink->text_sink.tab_count) {
00672     sink->text_sink.tabs = (Position *)
00673         XtRealloc((char *) sink->text_sink.tabs,
00674                   (Cardinal) (tab_count * sizeof(Position)));
00675     sink->text_sink.char_tabs = (short *)
00676         XtRealloc((char *) sink->text_sink.char_tabs,
00677                   (Cardinal) (tab_count * sizeof(short)));
00678   }
00679 
00680   for ( i = 0 ; i < tab_count ; i++ ) {
00681     sink->text_sink.tabs[i] = tabs[i] * figure_width;
00682     sink->text_sink.char_tabs[i] = tabs[i];
00683   }
00684     
00685   sink->text_sink.tab_count = tab_count;
00686 
00687 #ifndef NO_TAB_FIX
00688   {  TextWidget ctx = (TextWidget)XtParent(w);
00689       ctx->text.redisplay_needed = True;
00690       _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
00691   }
00692 #endif
00693 }

Generated on Sun Mar 4 15:03:55 2007 for Scilab [trunk] by  doxygen 1.5.1