home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / windows / x / motif / 8916 < prev    next >
Encoding:
Text File  |  1993-01-28  |  4.2 KB  |  111 lines

  1. Newsgroups: comp.windows.x.motif
  2. Path: sparky!uunet!europa.eng.gtefsd.com!gatech!paladin.american.edu!howland.reston.ans.net!usc!sdd.hp.com!hpscit.sc.hp.com!cupnews0.cup.hp.com!news1.boi.hp.com!hp-pcd!hpcvusn!hpcvusc.cv.hp.com!tommc
  3. From: tommc@hpcvusc.cv.hp.com (Tom McFarland)
  4. Subject: Re: Scrolled Text scrolling behaviour
  5. Message-ID: <1993Jan28.192304.18624@hpcvusn.cv.hp.com>
  6. Sender: nobody@hpcvusn.cv.hp.com (Nobody - UID must be 99999)
  7. Nntp-Posting-Host: hpcvusc.cv.hp.com
  8. Reply-To: tommc@cv.hp.com
  9. Organization: Hewlett Packard UTD-Corvallis
  10. References:  <15JAN199312352029@reg.triumf.ca>
  11. Date: Thu, 28 Jan 1993 19:23:04 GMT
  12. Lines: 97
  13.  
  14. In article <15JAN199312352029@reg.triumf.ca>, fwj@reg.triumf.ca (JONES,FRED_W.) writes:
  15. |> My application uses a fixed-size scrolled text region (5 lines and 80
  16. |> columns) for a running display of diagnostic messages and other
  17. |> informational output, and I'm having trouble getting the right scrolling
  18. |> behaviour.
  19.  
  20. There is no easy way to get the behavior you want.  If you are not using
  21. word wrap, I can suggest a solution (but it ain't pretty).  Before adding
  22. the new message, get the current top character (XmTextGetTopCharacter).
  23. The position returned is the text position of the beginning of the top
  24. line currently displayed in the text widget.  Knowing that position, you
  25. can scan forward for a newline character (in 1.2, you can use the
  26. XmTextFindString call), add one, and after adding your new message
  27. set the calculated position as the new top character (XmTextSetTopCharacter).
  28.  
  29. So the sequence would be:
  30.  
  31.    XmTextPosition old_top, new_top;
  32.    Boolean found = False;
  33.  
  34.    old_top = XmTextGetTopCharacter((Widget)tw);
  35.    found = XmTextFindString((Widget)tw, old_top, "\n", XmTEXT_FORWARD,
  36.                 &new_top);
  37.    new_top++;
  38.  
  39.    /* Add your new message */
  40.    if (found) XmTextSetTopCharacter((Widget)tw, new_top);
  41.  
  42.  
  43. If you are implementing with pre-1.2, you'll need to implement your own
  44. XmTextFindString() functionality.
  45.  
  46. Hope this helps,
  47.  
  48. Tom McFarland
  49. Hewlett-Packard, Co.
  50. R&D Motif team
  51. <tommc@cv.hp.com>
  52.  
  53. |> I use the following to add a line of text to the widget and ensure that 
  54. |> it is visible:
  55. |> 
  56. |>    ...
  57. |> Widget emsgarea;   /* The Text widget */
  58. |> 
  59. |> void emsg1_(msg)
  60. |>    char *msg;
  61. |> {
  62. |>    XmTextInsert(emsgarea, XmTextGetLastPosition(emsgarea), "\n" );
  63. |>    XmTextInsert(emsgarea, XmTextGetLastPosition(emsgarea), msg);
  64. |>    XmTextShowPosition(emsgarea, XmTextGetLastPosition(emsgarea));
  65. |> }
  66. |> 
  67. |> I hoped that this would scroll one line at a time to display the new
  68. |> text, but it doesn't.  After the initial text fills up the window,
  69. |> adding the next line causes all the previous text to scroll off the
  70. |> screen and the new line appears at the top of the window.  This is
  71. |> highly undesirable if you are putting out multi-line messages, and seems
  72. |> unnecessary in any case.
  73. |> 
  74. |> The code to implement the scrolled text window is as follows (generated
  75. |> by XDesigner):   emainbb is the parent, a BulletinBoard.
  76. |> 
  77. |>           ....
  78. |>     char from_s [256];    /* For font list conversion */
  79. |>     XrmValue from_value, to_value; /* ditto */
  80. |>           ....
  81. |> 
  82. |>     XtSetArg(al[ac], XmNcolumns, 80); ac++;
  83. |>     XtSetArg(al[ac], XmNeditable, FALSE); ac++;
  84. |>     XtSetArg(al[ac], XmNcursorPositionVisible, FALSE); ac++;
  85. |>     sprintf ( from_s, "-dec-terminal-medium-r-normal--
  86. |>                   14-140-75-75-c-80-iso8859-1" );
  87. |>     from_value.size = strlen(from_s)+1;
  88. |>     from_value.addr = from_s;
  89. |>     XtConvert(emainbb, XmRString, &from_value, XmRFontList, &to_value);
  90. |>     XtSetArg(al[ac], XmNfontList, *(int *)to_value.addr); ac++;
  91. |>     XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
  92. |>     XtSetArg(al[ac], XmNrows, 5); ac++;
  93. |>     XtSetArg(al[ac], XmNwordWrap, TRUE); ac++;
  94. |>     XtSetArg(al[ac], XmNscrollHorizontal, FALSE); ac++;
  95. |>     emsgarea = XmCreateScrolledText ( emainbb, "emsgarea", al, ac );
  96. |>     ac = 0;
  97. |>     widget167 = XtParent ( emsgarea );
  98. |>     XtSetArg(al[ac], XmNx, 10); ac++;
  99. |>     XtSetArg(al[ac], XmNy, 160); ac++;
  100. |>     XtSetArg(al[ac], XmNwidth, 677); ac++;
  101. |>     XtSetArg(al[ac], XmNheight, 112); ac++;
  102. |>         XtSetValues ( widget167,al, ac );
  103. |> 
  104. |> 
  105. |> Any suggestions on how to get one-line scrolling would be greatly
  106. |> appreciated.
  107. |> 
  108. |> Thanks
  109. |> Frederick Jones
  110. |> fwj@reg.triumf.ca
  111.