home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xaw / TextSink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-27  |  23.1 KB  |  811 lines

  1. /* $XConsortium: TextSink.c,v 1.16 91/05/28 10:50:01 converse Exp $ */
  2.  
  3. /*
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Chris Peterson, MIT X Consortium.
  24.  *
  25.  * Much code taken from X11R3 AsciiSink.
  26.  */
  27.  
  28. /*
  29.  * TextSink.c - TextSink object. (For use with the text widget).
  30.  *
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include <ctype.h>
  35. #include <X11/IntrinsicP.h>
  36. #include <X11/StringDefs.h>
  37. #include <X11/Xaw/XawInit.h>
  38. #include <X11/Xaw/TextSinkP.h>
  39. #include <X11/Xaw/TextP.h>
  40.  
  41. /****************************************************************
  42.  *
  43.  * Full class record constant
  44.  *
  45.  ****************************************************************/
  46.  
  47. static void ClassPartInitialize(), Initialize(), Destroy();
  48. static Boolean SetValues();
  49.  
  50. static int MaxHeight(), MaxLines();
  51. static void DisplayText(), InsertCursor(), ClearToBackground(), FindPosition();
  52. static void FindDistance(), Resolve(), SetTabs(), GetCursorBounds();
  53.  
  54. #define offset(field) XtOffsetOf(TextSinkRec, text_sink.field)
  55. static XtResource resources[] = {
  56.   {XtNfont, XtCFont, XtRFontStruct, sizeof (XFontStruct *),
  57.      offset(font), XtRString, XtDefaultFont},
  58.   {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
  59.      offset(foreground), XtRString, XtDefaultForeground}, 
  60.   {XtNbackground, XtCBackground, XtRPixel, sizeof (Pixel),
  61.      offset(background), XtRString, XtDefaultBackground}, 
  62. };
  63. #undef offset
  64.  
  65. #define SuperClass        (&objectClassRec)
  66. TextSinkClassRec textSinkClassRec = {
  67.   {
  68. /* core_class fields */    
  69.     /* superclass          */    (WidgetClass) SuperClass,
  70.     /* class_name          */    "TextSink",
  71.     /* widget_size          */    sizeof(TextSinkRec),
  72.     /* class_initialize       */    XawInitializeWidgetSet,
  73.     /* class_part_initialize    */    ClassPartInitialize,
  74.     /* class_inited           */    FALSE,
  75.     /* initialize          */    Initialize,
  76.     /* initialize_hook        */    NULL,
  77.     /* obj1              */    NULL,
  78.     /* obj2              */    NULL,
  79.     /* obj3              */    0,
  80.     /* resources          */    resources,
  81.     /* num_resources          */    XtNumber(resources),
  82.     /* xrm_class          */    NULLQUARK,
  83.     /* obj4              */    FALSE,
  84.     /* obj5              */    FALSE,
  85.     /* obj6            */    FALSE,
  86.     /* obj7                */    FALSE,
  87.     /* destroy              */    Destroy,
  88.     /* obj8              */    NULL,
  89.     /* obj9              */    NULL,
  90.     /* set_values          */    SetValues,
  91.     /* set_values_hook        */    NULL,
  92.     /* obj10            */    NULL,
  93.     /* get_values_hook        */    NULL,
  94.     /* obj11             */    NULL,
  95.     /* version            */    XtVersion,
  96.     /* callback_private       */    NULL,
  97.     /* obj12               */    NULL,
  98.     /* obj13            */    NULL,
  99.     /* obj14            */    NULL,
  100.     /* extension        */    NULL
  101.   },
  102. /* textSink_class fields */
  103.   {
  104.     /* DisplayText              */      DisplayText,
  105.     /* InsertCursor             */      InsertCursor,
  106.     /* ClearToBackground        */      ClearToBackground,
  107.     /* FindPosition             */      FindPosition,
  108.     /* FindDistance             */      FindDistance,
  109.     /* Resolve                  */      Resolve,
  110.     /* MaxLines                 */      MaxLines,
  111.     /* MaxHeight                */      MaxHeight,
  112.     /* SetTabs                  */      SetTabs,
  113.     /* GetCursorBounds          */      GetCursorBounds,
  114.   }
  115. };
  116.  
  117. WidgetClass textSinkObjectClass = (WidgetClass)&textSinkClassRec;
  118.  
  119. static void
  120. ClassPartInitialize(wc)
  121. WidgetClass wc;
  122. {
  123.   register TextSinkObjectClass t_src, superC;
  124.  
  125.   t_src = (TextSinkObjectClass) wc;
  126.   superC = (TextSinkObjectClass) t_src->object_class.superclass;
  127.  
  128. /* 
  129.  * We don't need to check for null super since we'll get to TextSink
  130.  * eventually.
  131.  */
  132.  
  133.     if (t_src->text_sink_class.DisplayText == XtInheritDisplayText) 
  134.       t_src->text_sink_class.DisplayText = superC->text_sink_class.DisplayText;
  135.  
  136.     if (t_src->text_sink_class.InsertCursor == XtInheritInsertCursor) 
  137.       t_src->text_sink_class.InsertCursor =
  138.                                         superC->text_sink_class.InsertCursor;
  139.  
  140.     if (t_src->text_sink_class.ClearToBackground== XtInheritClearToBackground) 
  141.       t_src->text_sink_class.ClearToBackground = 
  142.                                  superC->text_sink_class.ClearToBackground;
  143.  
  144.     if (t_src->text_sink_class.FindPosition == XtInheritFindPosition) 
  145.       t_src->text_sink_class.FindPosition = 
  146.                                       superC->text_sink_class.FindPosition;
  147.  
  148.     if (t_src->text_sink_class.FindDistance == XtInheritFindDistance) 
  149.       t_src->text_sink_class.FindDistance = 
  150.                                      superC->text_sink_class.FindDistance;
  151.  
  152.     if (t_src->text_sink_class.Resolve == XtInheritResolve) 
  153.       t_src->text_sink_class.Resolve = superC->text_sink_class.Resolve;
  154.  
  155.     if (t_src->text_sink_class.MaxLines == XtInheritMaxLines) 
  156.       t_src->text_sink_class.MaxLines = superC->text_sink_class.MaxLines;
  157.  
  158.     if (t_src->text_sink_class.MaxHeight == XtInheritMaxHeight) 
  159.       t_src->text_sink_class.MaxHeight = superC->text_sink_class.MaxHeight;
  160.  
  161.     if (t_src->text_sink_class.SetTabs == XtInheritSetTabs) 
  162.       t_src->text_sink_class.SetTabs = superC->text_sink_class.SetTabs;
  163.  
  164.     if (t_src->text_sink_class.GetCursorBounds == XtInheritGetCursorBounds) 
  165.       t_src->text_sink_class.GetCursorBounds = 
  166.                                        superC->text_sink_class.GetCursorBounds;
  167. }
  168.  
  169. /*    Function Name: Initialize
  170.  *    Description: Initializes the TextSink Object.
  171.  *    Arguments: request, new - the requested and new values for the object
  172.  *                                instance.
  173.  *    Returns: none.
  174.  *
  175.  */
  176.  
  177. /* ARGSUSED */
  178. static void
  179. Initialize(request, new)
  180. Widget request, new;
  181. {
  182.   TextSinkObject sink = (TextSinkObject) new;
  183.  
  184.   sink->text_sink.tab_count = 0; /* Initialize the tab stops. */
  185.   sink->text_sink.tabs = NULL;
  186.   sink->text_sink.char_tabs = NULL;
  187. }
  188.  
  189. /*    Function Name: Destroy
  190.  *    Description: This function cleans up when the object is 
  191.  *                   destroyed.
  192.  *    Arguments: w - the TextSink Object.
  193.  *    Returns: none.
  194.  */
  195.  
  196. static void
  197. Destroy(w)
  198. {
  199.   TextSinkObject sink = (TextSinkObject) w;
  200.  
  201.   XtFree((char *) sink->text_sink.tabs);
  202.   XtFree((char *) sink->text_sink.char_tabs);
  203. }
  204.  
  205. /*    Function Name: SetValues
  206.  *    Description: Sets the values for the TextSink
  207.  *    Arguments: current - current state of the object.
  208.  *                 request - what was requested.
  209.  *                 new - what the object will become.
  210.  *    Returns: True if redisplay is needed.
  211.  */
  212.  
  213. /* ARGSUSED */
  214. static Boolean
  215. SetValues(current, request, new)
  216. Widget current, request, new;
  217. {
  218.   TextSinkObject w = (TextSinkObject) new;
  219.   TextSinkObject old_w = (TextSinkObject) current;
  220.   TextSinkObjectClass class = (TextSinkObjectClass) w->object.widget_class;
  221.  
  222.   if (w->text_sink.font != old_w->text_sink.font) {
  223.     (*class->text_sink_class.SetTabs)(new, w->text_sink.tab_count, 
  224.                       w->text_sink.char_tabs);
  225.     ((TextWidget)XtParent(new))->text.redisplay_needed = True;
  226.   } else {
  227.       if (w->text_sink.foreground != old_w->text_sink.foreground)
  228.       ((TextWidget)XtParent(new))->text.redisplay_needed = True;
  229.   }
  230.  
  231.   return FALSE;
  232. }
  233.  
  234. /************************************************************
  235.  *
  236.  * Class specific methods.
  237.  *
  238.  ************************************************************/
  239.  
  240. /*    Function Name: DisplayText
  241.  *    Description: Stub function that in subclasses will display text. 
  242.  *    Arguments: w - the TextSink Object.
  243.  *                 x, y - location to start drawing text.
  244.  *                 pos1, pos2 - location of starting and ending points
  245.  *                              in the text buffer.
  246.  *                 highlight - hightlight this text?
  247.  *    Returns: none.
  248.  *
  249.  * This function doesn't actually display anything, it is only a place
  250.  * holder.
  251.  */
  252.  
  253. /* ARGSUSED */
  254. static void
  255. DisplayText(w, x, y, pos1, pos2, highlight)
  256. Widget w;
  257. Position x, y;
  258. Boolean highlight;
  259. XawTextPosition pos1, pos2;
  260. {
  261.   return;
  262. }
  263.  
  264. /*    Function Name: InsertCursor
  265.  *    Description: Places the InsertCursor.
  266.  *    Arguments: w - the TextSink Object.
  267.  *                 x, y - location for the cursor.
  268.  *                 staye - whether to turn the cursor on, or off.
  269.  *    Returns: none.
  270.  *
  271.  * This function doesn't actually display anything, it is only a place
  272.  * holder.
  273.  */
  274.  
  275. /* ARGSUSED */
  276. static void
  277. InsertCursor(w, x, y, state)
  278. Widget w;
  279. Position x, y;
  280. XawTextInsertState state;
  281. {
  282.   return;
  283. }
  284.  
  285. /*    Function Name: ClearToBackground
  286.  *    Description: Clears a region of the sink to the background color.
  287.  *    Arguments: w - the TextSink Object.
  288.  *                 x, y  - location of area to clear.
  289.  *                 width, height - size of area to clear
  290.  *    Returns: void.
  291.  *
  292.  */
  293.  
  294. /* ARGSUSED */
  295. static void
  296. ClearToBackground (w, x, y, width, height)
  297. Widget w;
  298. Position x, y;
  299. Dimension width, height;
  300. {
  301. /* 
  302.  * Don't clear in height or width are zero.
  303.  * XClearArea() has special semantic for these values.
  304.  */
  305.  
  306.     if ( (height == 0) || (width == 0) ) return;
  307.     XClearArea(XtDisplayOfObject(w), XtWindowOfObject(w),
  308.            x, y, width, height, False);
  309. }
  310.  
  311. /*    Function Name: FindPosition
  312.  *    Description: Finds a position in the text.
  313.  *    Arguments: w - the TextSink Object.
  314.  *                 fromPos - reference position.
  315.  *                 fromX   - reference location.
  316.  *                 width,  - width of section to paint text.
  317.  *                 stopAtWordBreak - returned position is a word break?
  318.  *                 resPos - Position to return.      *** RETURNED ***
  319.  *                 resWidth - Width actually used.   *** RETURNED ***
  320.  *                 resHeight - Height actually used. *** RETURNED ***
  321.  *    Returns: none (see above).
  322.  */
  323.  
  324. /* ARGSUSED */
  325. static void
  326. FindPosition(w, fromPos, fromx, width, stopAtWordBreak, 
  327.          resPos, resWidth, resHeight)
  328. Widget w;
  329. XawTextPosition fromPos; 
  330. int fromx, width;            
  331. Boolean stopAtWordBreak;        
  332. XawTextPosition *resPos;    
  333. int *resWidth, *resHeight;        
  334. {
  335.   *resPos = fromPos;
  336.   *resHeight = *resWidth = 0;
  337. }
  338.  
  339. /*    Function Name: FindDistance
  340.  *    Description: Find the Pixel Distance between two text Positions.
  341.  *    Arguments: w - the TextSink Object.
  342.  *                 fromPos - starting Position.
  343.  *                 fromX   - x location of starting Position.
  344.  *                 toPos   - end Position.
  345.  *                 resWidth - Distance between fromPos and toPos.
  346.  *                 resPos   - Acutal toPos used.
  347.  *                 resHeight - Height required by this text.
  348.  *    Returns: none.
  349.  */
  350.  
  351. /* ARGSUSED */
  352. static void
  353. FindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight)
  354. Widget w;
  355. XawTextPosition fromPos;
  356. int fromx;
  357. XawTextPosition toPos;
  358. int *resWidth;
  359. XawTextPosition *resPos;
  360. int *resHeight;
  361. {
  362.   *resWidth = *resHeight = 0;
  363.   *resPos = fromPos;
  364. }
  365.  
  366. /*    Function Name: Resolve
  367.  *    Description: Resloves a location to a position.
  368.  *    Arguments: w - the TextSink Object.
  369.  *                 pos - a reference Position.
  370.  *                 fromx - a reference Location.
  371.  *                 width - width to move.
  372.  *                 resPos - the resulting position.
  373.  *    Returns: none
  374.  */
  375.  
  376. /* ARGSUSED */
  377. static void
  378. Resolve (w, pos, fromx, width, resPos)
  379. Widget w;
  380. XawTextPosition pos;
  381. int fromx, width;
  382. XawTextPosition *resPos;
  383. {
  384.   *resPos = pos;
  385. }
  386.  
  387. /*    Function Name: MaxLines
  388.  *    Description: Finds the Maximum number of lines that will fit in
  389.  *                   a given height.
  390.  *    Arguments: w - the TextSink Object.
  391.  *                 height - height to fit lines into.
  392.  *    Returns: the number of lines that will fit.
  393.  */
  394.  
  395. /* ARGSUSED */
  396. static int
  397. MaxLines(w, height)
  398. Widget w;
  399. Dimension height;
  400. {
  401.   TextSinkObject sink = (TextSinkObject) w;
  402.   int font_height;
  403.  
  404.   font_height = sink->text_sink.font->ascent + sink->text_sink.font->descent;
  405.   return( ((int) height) / font_height );
  406. }
  407.  
  408. /*    Function Name: MaxHeight
  409.  *    Description: Finds the Minium height that will contain a given number 
  410.  *                   lines.
  411.  *    Arguments: w - the TextSink Object.
  412.  *                 lines - the number of lines.
  413.  *    Returns: the height.
  414.  */
  415.  
  416. /* ARGSUSED */
  417. static int
  418. MaxHeight(w, lines)
  419. Widget w;
  420. int lines;
  421. {
  422.   TextSinkObject sink = (TextSinkObject) w;
  423.  
  424.   return(lines * (sink->text_sink.font->ascent + 
  425.           sink->text_sink.font->descent));
  426. }
  427.  
  428. /*    Function Name: SetTabs
  429.  *    Description: Sets the Tab stops.
  430.  *    Arguments: w - the TextSink Object.
  431.  *                 tab_count - the number of tabs in the list.
  432.  *                 tabs - the text positions of the tabs.
  433.  *    Returns: none
  434.  */
  435.  
  436. static void
  437. SetTabs(w, tab_count, tabs)
  438. Widget w;
  439. int tab_count;
  440. short *tabs;
  441. {
  442.   TextSinkObject sink = (TextSinkObject) w;
  443.   int i;
  444.   Atom XA_FIGURE_WIDTH;
  445.   unsigned long figure_width = 0;
  446.   XFontStruct *font = sink->text_sink.font;
  447.  
  448. /*
  449.  * Find the figure width of the current font.
  450.  */
  451.  
  452.   XA_FIGURE_WIDTH = XInternAtom(XtDisplayOfObject(w), "FIGURE_WIDTH", FALSE);
  453.   if ( XA_FIGURE_WIDTH != None && 
  454.        ( (!XGetFontProperty(font, XA_FIGURE_WIDTH, &figure_width)) ||
  455.      (figure_width == 0)) ) 
  456.     if (font->per_char && font->min_char_or_byte2 <= '$' &&
  457.     font->max_char_or_byte2 >= '$')
  458.       figure_width = font->per_char['$' - font->min_char_or_byte2].width;
  459.     else
  460.       figure_width = font->max_bounds.width;
  461.  
  462.   if (tab_count > sink->text_sink.tab_count) {
  463.     sink->text_sink.tabs = (Position *)
  464.     XtRealloc((char *) sink->text_sink.tabs,
  465.           (Cardinal) (tab_count * sizeof(Position)));
  466.     sink->text_sink.char_tabs = (short *)
  467.     XtRealloc((char *) sink->text_sink.char_tabs,
  468.           (Cardinal) (tab_count * sizeof(short)));
  469.   }
  470.  
  471.   for ( i = 0 ; i < tab_count ; i++ ) {
  472.     sink->text_sink.tabs[i] = tabs[i] * figure_width;
  473.     sink->text_sink.char_tabs[i] = tabs[i];
  474.   }
  475.     
  476.   sink->text_sink.tab_count = tab_count;
  477. }
  478.  
  479. /*    Function Name: GetCursorBounds
  480.  *    Description: Finds the bounding box for the insert curor (caret).
  481.  *    Arguments: w - the TextSinkObject.
  482.  *                 rect - an X rectance containing the cursor bounds.
  483.  *    Returns: none (fills in rect).
  484.  */
  485.  
  486. /* ARGSUSED */
  487. static void
  488. GetCursorBounds(w, rect)
  489. Widget w;
  490. XRectangle * rect;
  491. {
  492.   rect->x = rect->y = rect->width = rect->height = 0;
  493. }
  494. /************************************************************
  495.  *
  496.  * Public Functions.
  497.  *
  498.  ************************************************************/
  499.  
  500.  
  501. /*    Function Name: XawTextSinkDisplayText
  502.  *    Description: Stub function that in subclasses will display text. 
  503.  *    Arguments: w - the TextSink Object.
  504.  *                 x, y - location to start drawing text.
  505.  *                 pos1, pos2 - location of starting and ending points
  506.  *                              in the text buffer.
  507.  *                 highlight - hightlight this text?
  508.  *    Returns: none.
  509.  *
  510.  * This function doesn't actually display anything, it is only a place
  511.  * holder.
  512.  */
  513.  
  514. /* ARGSUSED */
  515. void
  516. #if NeedFunctionPrototypes
  517. XawTextSinkDisplayText(Widget w,
  518. #if NeedWidePrototypes
  519.                /* Position */ int x, /* Position */ int y,
  520. #else
  521.                Position x, Position y,
  522. #endif
  523.                XawTextPosition pos1, XawTextPosition pos2,
  524. #if NeedWidePrototypes
  525.                /* Boolean */ int highlight)
  526. #else
  527.                Boolean highlight)
  528. #endif
  529. #else
  530. XawTextSinkDisplayText(w, x, y, pos1, pos2, highlight)
  531. Widget w;
  532. Position x, y;
  533. Boolean highlight;
  534. XawTextPosition pos1, pos2;
  535. #endif
  536. {
  537.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  538.  
  539.   (*class->text_sink_class.DisplayText)(w, x, y, pos1, pos2, highlight);
  540. }
  541.  
  542. /*    Function Name: XawTextSinkInsertCursor
  543.  *    Description: Places the InsertCursor.
  544.  *    Arguments: w - the TextSink Object.
  545.  *                 x, y - location for the cursor.
  546.  *                 staye - whether to turn the cursor on, or off.
  547.  *    Returns: none.
  548.  *
  549.  * This function doesn't actually display anything, it is only a place
  550.  * holder.
  551.  */
  552.  
  553. /* ARGSUSED */
  554. void
  555. #if NeedFunctionPrototypes
  556. XawTextSinkInsertCursor(Widget w,
  557. #if NeedWidePrototypes
  558.             int x, int y, int state)
  559. #else
  560.             Position x, Position y, XawTextInsertState state)
  561. #endif
  562. #else    
  563. XawTextSinkInsertCursor(w, x, y, state)
  564. Widget w;
  565. Position x, y;
  566. XawTextInsertState state;
  567. #endif
  568. {
  569.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  570.     
  571.   (*class->text_sink_class.InsertCursor)(w, x, y, state);
  572. }
  573.  
  574.  
  575. /*    Function Name: XawTextSinkClearToBackground
  576.  *    Description: Clears a region of the sink to the background color.
  577.  *    Arguments: w - the TextSink Object.
  578.  *                 x, y  - location of area to clear.
  579.  *                 width, height - size of area to clear
  580.  *    Returns: void.
  581.  *
  582.  * This function doesn't actually display anything, it is only a place
  583.  * holder.
  584.  */
  585.  
  586. /* ARGSUSED */
  587. void
  588. #if NeedFunctionPrototypes
  589. XawTextSinkClearToBackground (Widget w,
  590. #if NeedWidePrototypes
  591.                   int x, int y, int width, int height)
  592. #else
  593.                   Position x, Position y, 
  594.                   Dimension width, Dimension height)
  595. #endif
  596. #else
  597. XawTextSinkClearToBackground (w, x, y, width, height)
  598. Widget w;
  599. Position x, y;
  600. Dimension width, height;
  601. #endif
  602. {
  603.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  604.  
  605.   (*class->text_sink_class.ClearToBackground)(w, x, y, width, height);
  606. }
  607.  
  608. /*    Function Name: XawTextSinkFindPosition
  609.  *    Description: Finds a position in the text.
  610.  *    Arguments: w - the TextSink Object.
  611.  *                 fromPos - reference position.
  612.  *                 fromX   - reference location.
  613.  *                 width,  - width of section to paint text.
  614.  *                 stopAtWordBreak - returned position is a word break?
  615.  *                 resPos - Position to return.      *** RETURNED ***
  616.  *                 resWidth - Width actually used.   *** RETURNED ***
  617.  *                 resHeight - Height actually used. *** RETURNED ***
  618.  *    Returns: none (see above).
  619.  */
  620.  
  621. /* ARGSUSED */
  622. void
  623. #if NeedFunctionPrototypes
  624. XawTextSinkFindPosition(Widget w, XawTextPosition fromPos, int fromx,
  625.             int width,
  626. #if NeedWidePrototypes
  627.             /* Boolean */ int stopAtWordBreak,
  628. #else
  629.             Boolean stopAtWordBreak,
  630. #endif
  631.             XawTextPosition *resPos, int *resWidth, int *resHeight)
  632. #else
  633. XawTextSinkFindPosition(w, fromPos, fromx, width, stopAtWordBreak, 
  634.             resPos, resWidth, resHeight)
  635. Widget w;
  636. XawTextPosition fromPos; 
  637. int fromx, width;            
  638. Boolean stopAtWordBreak;        
  639. XawTextPosition *resPos;    
  640. int *resWidth, *resHeight;
  641. #endif
  642. {
  643.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  644.  
  645.   (*class->text_sink_class.FindPosition)(w, fromPos, fromx, width,
  646.                      stopAtWordBreak, 
  647.                      resPos, resWidth, resHeight);
  648. }
  649.  
  650. /*    Function Name: XawTextSinkFindDistance
  651.  *    Description: Find the Pixel Distance between two text Positions.
  652.  *    Arguments: w - the TextSink Object.
  653.  *                 fromPos - starting Position.
  654.  *                 fromX   - x location of starting Position.
  655.  *                 toPos   - end Position.
  656.  *                 resWidth - Distance between fromPos and toPos.
  657.  *                 resPos   - Acutal toPos used.
  658.  *                 resHeight - Height required by this text.
  659.  *    Returns: none.
  660.  */
  661.  
  662. /* ARGSUSED */
  663. void
  664. #if NeedFunctionPrototypes
  665. XawTextSinkFindDistance (Widget w, XawTextPosition fromPos, int fromx,
  666.              XawTextPosition toPos, int *resWidth, 
  667.              XawTextPosition *resPos, int *resHeight)
  668. #else
  669. XawTextSinkFindDistance (w, fromPos, fromx, toPos, resWidth, resPos, resHeight)
  670. Widget w;
  671. XawTextPosition fromPos, toPos, *resPos;
  672. int fromx, *resWidth, *resHeight;
  673. #endif
  674. {
  675.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  676.  
  677.   (*class->text_sink_class.FindDistance)(w, fromPos, fromx, toPos,
  678.                      resWidth, resPos, resHeight);
  679. }
  680.  
  681. /*    Function Name: XawTextSinkResolve
  682.  *    Description: Resloves a location to a position.
  683.  *    Arguments: w - the TextSink Object.
  684.  *                 pos - a reference Position.
  685.  *                 fromx - a reference Location.
  686.  *                 width - width to move.
  687.  *                 resPos - the resulting position.
  688.  *    Returns: none
  689.  */
  690.  
  691. /* ARGSUSED */
  692. void
  693. #if NeedFunctionPrototypes
  694. XawTextSinkResolve(Widget w, XawTextPosition pos, int fromx, int width,
  695.            XawTextPosition *resPos)
  696. #else
  697. XawTextSinkResolve(w, pos, fromx, width, resPos)
  698. Widget w;
  699. XawTextPosition pos;
  700. int fromx, width;
  701. XawTextPosition *resPos;
  702. #endif
  703. {
  704.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  705.  
  706.   (*class->text_sink_class.Resolve)(w, pos, fromx, width, resPos);
  707. }
  708.  
  709. /*    Function Name: XawTextSinkMaxLines
  710.  *    Description: Finds the Maximum number of lines that will fit in
  711.  *                   a given height.
  712.  *    Arguments: w - the TextSink Object.
  713.  *                 height - height to fit lines into.
  714.  *    Returns: the number of lines that will fit.
  715.  */
  716.  
  717. /* ARGSUSED */
  718. int
  719. #if NeedFunctionPrototypes
  720. XawTextSinkMaxLines(Widget w,
  721. #if NeedWidePrototypes
  722.             /* Dimension */ int height)
  723. #else
  724.             Dimension height)
  725. #endif
  726. #else
  727. XawTextSinkMaxLines(w, height)
  728. Widget w;
  729. Dimension height;
  730. #endif
  731. {
  732.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  733.  
  734.   return((*class->text_sink_class.MaxLines)(w, height));
  735. }
  736.  
  737. /*    Function Name: XawTextSinkMaxHeight
  738.  *    Description: Finds the Minimum height that will contain a given number 
  739.  *                   lines.
  740.  *    Arguments: w - the TextSink Object.
  741.  *                 lines - the number of lines.
  742.  *    Returns: the height.
  743.  */
  744.  
  745. /* ARGSUSED */
  746. int
  747. #if NeedFunctionPrototypes
  748. XawTextSinkMaxHeight(Widget w, int lines)
  749. #else
  750. XawTextSinkMaxHeight(w, lines)
  751. Widget w;
  752. int lines;
  753. #endif
  754. {
  755.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  756.  
  757.   return((*class->text_sink_class.MaxHeight)(w, lines));
  758. }
  759.  
  760. /*    Function Name: XawTextSinkSetTabs
  761.  *    Description: Sets the Tab stops.
  762.  *    Arguments: w - the TextSink Object.
  763.  *                 tab_count - the number of tabs in the list.
  764.  *                 tabs - the text positions of the tabs.
  765.  *    Returns: none
  766.  */
  767.  
  768. void
  769. #if NeedFunctionPrototypes
  770. XawTextSinkSetTabs(Widget w, int tab_count, int *tabs)
  771. #else
  772. XawTextSinkSetTabs(w, tab_count, tabs)
  773. Widget w;
  774. int tab_count, *tabs;
  775. #endif
  776. {
  777.   if (tab_count > 0) {
  778.     TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  779.     short *char_tabs = (short*)XtMalloc( (unsigned)tab_count*sizeof(short) );
  780.     register short *tab;
  781.     register int i;
  782.  
  783.     for (i = tab_count, tab = char_tabs; i; i--) *tab++ = (short)*tabs++;
  784.  
  785.     (*class->text_sink_class.SetTabs)(w, tab_count, char_tabs);
  786.     XtFree((char *)char_tabs);
  787.   }
  788. }
  789.                           
  790. /*    Function Name: XawTextSinkGetCursorBounds
  791.  *    Description: Finds the bounding box for the insert curor (caret).
  792.  *    Arguments: w - the TextSinkObject.
  793.  *                 rect - an X rectance containing the cursor bounds.
  794.  *    Returns: none (fills in rect).
  795.  */
  796.  
  797. /* ARGSUSED */
  798. void
  799. #if NeedFunctionPrototypes
  800. XawTextSinkGetCursorBounds(Widget w, XRectangle *rect)
  801. #else
  802. XawTextSinkGetCursorBounds(w, rect)
  803. Widget w;
  804. XRectangle * rect;
  805. #endif
  806. {
  807.   TextSinkObjectClass class = (TextSinkObjectClass) w->core.widget_class;
  808.  
  809.   (*class->text_sink_class.GetCursorBounds)(w, rect);
  810. }
  811.