home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / hman / part03 < prev    next >
Encoding:
Text File  |  1992-03-06  |  19.6 KB  |  783 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!munnari.oz.au!mips!mips!msi!dcmartin
  3. From: mab@ecmwf.co.uk (Baudouin Raoult)
  4. Subject: v16i145: hyperwidget & manual browser, Part03/06
  5. Message-ID: <1992Mar6.204828.8719@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. References: <csx-16i143-hman@uunet.UU.NET>
  10. Date: Fri, 6 Mar 1992 20:48:28 GMT
  11. Approved: dcmartin@msi.com
  12.  
  13. Submitted-by: mab@ecmwf.co.uk (Baudouin Raoult)
  14. Posting-number: Volume 16, Issue 145
  15. Archive-name: hman/part03
  16.  
  17. #!/bin/sh
  18. # this is part 3 of a multipart archive
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file Hyper.c continued
  21. #
  22. CurArch=3
  23. if test ! -r s2_seq_.tmp
  24. then echo "Please unpack part 1 first!"
  25.      exit 1; fi
  26. ( read Scheck
  27.   if test "$Scheck" != $CurArch
  28.   then echo "Please unpack part $Scheck next!"
  29.        exit 1;
  30.   else exit 0; fi
  31. ) < s2_seq_.tmp || exit 1
  32. echo "x - Continuing file Hyper.c"
  33. sed 's/^X//' << 'SHAR_EOF' >> Hyper.c
  34. X                XFillRectangle(XtDisplay(w),XtWindow(w),
  35. X                    w->hyper.xor_gc,
  36. X                    w->hyper.grep_x,
  37. X                    w->hyper.grep_y,
  38. X                    w->hyper.grep_width,
  39. X                    w->hyper.grep_height);
  40. X
  41. X        }
  42. X    }
  43. X}
  44. X
  45. X/*------------------------------------------------------------------*/
  46. X/* SetValues : redraw only for font or color changes                */
  47. X/*------------------------------------------------------------------*/
  48. X
  49. Xstatic Boolean SetValues (current, request, new)
  50. XHyperWidget current, request, new;
  51. X{
  52. X    Boolean    redraw = FALSE;
  53. X
  54. X#define HAS_CHANGED(a)    (new->a != current->a)
  55. X
  56. X    if(
  57. X        HAS_CHANGED(core.background_pixel) ||
  58. X        HAS_CHANGED(hyper.select_color) ||
  59. X        HAS_CHANGED(hyper.highlight_color) ||
  60. X        HAS_CHANGED(hyper.highlight_font)  ||
  61. X        HAS_CHANGED(hyper.normal_color) ||
  62. X        HAS_CHANGED(hyper.normal_font)
  63. X        )
  64. X    {
  65. X
  66. X        XtReleaseGC (new, new->hyper.normal_gc);
  67. X        XtReleaseGC (new, new->hyper.highlight_gc);
  68. X        XtReleaseGC (new, new->hyper.xor_gc);
  69. X        XtReleaseGC (new, new->hyper.select_gc);
  70. X        create_gcs(new);
  71. X
  72. X        /* rebuild text */
  73. X/*
  74. X        if(HAS_CHANGED(hyper.normal_font) || 
  75. X            HAS_CHANGED(hyper.highlight_font))
  76. X            */
  77. X            create_new_text(new);
  78. X
  79. X        redraw = TRUE;
  80. X    }
  81. X
  82. X    return (redraw);
  83. X
  84. X#undef HAS_CHANGED
  85. X
  86. X}
  87. X
  88. X/*------------------------------------------------------------------*/
  89. X/* Calculate the size of the widget                                 */
  90. X/*------------------------------------------------------------------*/
  91. X
  92. Xstatic void calc_new_size (w)
  93. XHyperWidget  w;
  94. X{
  95. X    text_segment       *s = w->hyper.first_seg;
  96. X    int                 x = w->hyper.margin;
  97. X    int                 y = 0;
  98. X    int                 last_height = 0;
  99. X    Boolean             newline = TRUE;
  100. X    Dimension           maxWidth = w->hyper.margin;
  101. X    Dimension           maxHeight = w->hyper.margin;
  102. X    XtGeometryResult    result;
  103. X    Dimension           replyWidth = 0, replyHeight = 0;
  104. X
  105. X    /* Get the size of the widget */
  106. X
  107. X    while(s)
  108. X    {
  109. X        if(newline)
  110. X        {
  111. X            if(x>maxWidth) maxWidth=x;
  112. X            x = w->hyper.margin;
  113. X            y += s->height;
  114. X            if(y>maxHeight) maxHeight=y;
  115. X
  116. X        }
  117. X
  118. X        s->x = x;
  119. X        s->y = y - s->height;
  120. X
  121. X        x += s->width;
  122. X
  123. X        newline = (s->type == NEWLINE);
  124. X        last_height = s->height;
  125. X
  126. X        s = s->next;
  127. X    }
  128. X
  129. X    x+= w->hyper.margin;
  130. X    y+= last_height;
  131. X
  132. X    if(x>maxWidth ) maxWidth=x;
  133. X    if(y>maxHeight) maxHeight=y;
  134. X
  135. X    /* 
  136. X    Tell our parent we want a new size 
  137. X    */
  138. X
  139. X    if(w->core.width != maxWidth || w->core.height != maxHeight)
  140. X    {
  141. X        result = XtMakeResizeRequest(w,maxWidth,maxHeight, 
  142. X            &replyWidth, &replyHeight) ;
  143. X
  144. X        if (result == XtGeometryAlmost)
  145. X            XtMakeResizeRequest (w, replyWidth, replyHeight,NULL, NULL);
  146. X
  147. X    }
  148. X}
  149. X
  150. X/*-----------------------------------------------------------------------*/
  151. X/* Find the "visible" part of a widget as the intersection of all the    */
  152. X/* windows of it's parents' windows                                      */
  153. X/*-----------------------------------------------------------------------*/
  154. X
  155. Xstatic void find_visible_part(w,x,y,width,height)
  156. XWidget    w;
  157. XPosition  *x;
  158. XPosition  *y;
  159. XDimension *width;
  160. XDimension *height;
  161. X{
  162. X    Position root_x,root_y;
  163. X    Widget   p = w;
  164. X
  165. X    *width  = w->core.width;
  166. X    *height = w->core.height;
  167. X    XtTranslateCoords(w,0,0,&root_x,&root_y);
  168. X
  169. X    *x = 0;
  170. X    *y = 0;
  171. X
  172. X    while(p = XtParent(p))
  173. X    {
  174. X        Position  rx,ry;
  175. X        Dimension w,h;
  176. X
  177. X        /* 
  178. X           make all computations in the root's
  179. X           coordinate system
  180. X        */
  181. X
  182. X        XtTranslateCoords(p,0,0,&rx,&ry);
  183. X
  184. X        w = p->core.width;
  185. X        h = p->core.height;
  186. X
  187. X        /* 
  188. X            use the smallest rectangle
  189. X        */
  190. X
  191. X        if(w < *width)  *width  = w;
  192. X        if(h < *height) *height = h;
  193. X
  194. X        if(rx>root_x) root_x = rx;
  195. X        if(ry>root_y) root_y = ry;
  196. X
  197. X        /* stop when reach a shell,
  198. X          don't go to top level shell */
  199. X        if(XtIsShell(p)) break;
  200. X    }
  201. X
  202. X    /* Back to the widget's coordinate system */
  203. X
  204. X    XtTranslateCoords(w,0,0,x,y);
  205. X    *x = root_x - *x;
  206. X    *y = root_y - *y;
  207. X
  208. X
  209. X}
  210. X
  211. X/*-----------------------------------------------------------------------*/
  212. X/* Do an "zoom" effect animation, from the selected text segment to the  */
  213. X/* visible part of the widget                                            */
  214. X/*-----------------------------------------------------------------------*/
  215. X
  216. Xstatic void zoom_open(w,s)
  217. XHyperWidget   w;
  218. Xtext_segment *s;
  219. X{
  220. X    int dx1,dx2,dy1,dy2;
  221. X
  222. X    Position x ;
  223. X    Position y ;
  224. X    Dimension width  ;
  225. X    Dimension height ;
  226. X
  227. X    /* selected rectangle */
  228. X
  229. X    Position  xs = s->x;
  230. X    Position  ys = s->y;
  231. X    Dimension ws = s->width;
  232. X    Dimension hs = s->height;
  233. X
  234. X
  235. X    /* get the rectangle we want to zoom to */
  236. X
  237. X    find_visible_part(w,&x,&y,&width,&height);
  238. X
  239. X    /* make sure selected rectangle in visible */
  240. X
  241. X    if(xs<x) xs = x;
  242. X    if(ys<y) ys = y;
  243. X    if(xs+ws > x+width)  ws = x+width-xs;
  244. X    if(ys+hs > y+height) hs = y+height-ys;
  245. X
  246. X    /* get the offsets in each directions */
  247. X
  248. X    dx1 = x-xs;
  249. X    dy1 = y-ys;
  250. X    dx2 = ((x+width)-(xs+ws));
  251. X    dy2 = ((y+height)-(ys+hs));
  252. X
  253. X    /* in the rectangles are differents */
  254. X
  255. X    if(dx1 || dy1 || dx2 || dy2)
  256. X    {
  257. X        int min = 32000; /* <-- Can be buggy */
  258. X
  259. X        /* 
  260. X          work in "left,top,bottom,right" rectangles (Mac)
  261. X          rather than "x,y,width,height" (X)
  262. X          It's easier for the animation 
  263. X        */
  264. X
  265. X        int xws = xs+ws;
  266. X        int yhs = ys+hs;
  267. X        int xw  = x + width;
  268. X        int yh  = y + height;
  269. X
  270. X
  271. X        /* Get smallest non-null offset */
  272. X
  273. X        if(dx1) min = MIN(min,ABS(dx1));
  274. X        if(dx2) min = MIN(min,ABS(dx2));
  275. X        if(dy1) min = MIN(min,ABS(dy1));
  276. X        if(dy2) min = MIN(min,ABS(dy2));
  277. X
  278. X        /* Scale offsets so minimun offset is 1 pixel */
  279. X
  280. X        dx1 /= min;
  281. X        dx2 /= min;
  282. X        dy1 /= min;
  283. X        dy2 /= min;
  284. X
  285. X        /* Use speed .. */
  286. X
  287. X        dx1 *= w->hyper.speed;
  288. X        dx2 *= w->hyper.speed;
  289. X        dy1 *= w->hyper.speed;
  290. X        dy2 *= w->hyper.speed;
  291. X
  292. X        /* Animate */
  293. X
  294. X        while(min--)
  295. X        {
  296. X            XDrawRectangle(XtDisplay(w),XtWindow(w),
  297. X                w->hyper.xor_gc,xs,ys,xws-xs,yhs-ys);
  298. X
  299. X            /* Needed, otherwise X calls are buffered */
  300. X            XSync(XtDisplay(w),False);
  301. X
  302. X            XDrawRectangle(XtDisplay(w),XtWindow(w),
  303. X                w->hyper.xor_gc,xs,ys,xws-xs,yhs-ys);
  304. X
  305. X            xs += dx1;
  306. X            ys += dy1;
  307. X
  308. X            xws += dx2;
  309. X            yhs += dy2;
  310. X
  311. X        }
  312. X    }
  313. X
  314. X}
  315. X
  316. X/*----------------------------------------------------------------------*/
  317. X/* Find the text segment at point (x,y)                                 */
  318. X/*----------------------------------------------------------------------*/
  319. Xtext_segment *find_segment(w,x,y)
  320. XHyperWidget w;
  321. Xint x,y;
  322. X{
  323. X    text_segment *s = w->hyper.first_seg;
  324. X
  325. X    while(s)
  326. X    {
  327. X        if( s->type == HIGHLIGHT &&
  328. X            x >= s->x &&
  329. X            y >= s->y &&
  330. X            x <= s->x + s->width &&
  331. X            y <= s->y + s->height 
  332. X            )
  333. X            return s;
  334. X        s = s->next;
  335. X    }
  336. X
  337. X    return NULL;
  338. X}
  339. X
  340. X/*----------------------------------------------------------------------*/
  341. X/* highlight text under cursor                                          */
  342. X/*----------------------------------------------------------------------*/
  343. Xstatic void hilite(w,on)
  344. XHyperWidget   w;
  345. XBoolean on;
  346. X{
  347. X
  348. X    text_segment *s = w->hyper.last_selected;
  349. X
  350. X    if(s)
  351. X        XDrawImageString(XtDisplay (w), XtWindow (w),
  352. X            on?w->hyper.select_gc:s->gc,
  353. X            s->x,
  354. X            s->y+s->height,
  355. X            s->text, s->length);
  356. X
  357. X}
  358. X
  359. X/*-----------------------------------------------------------------------*/
  360. X/* Check for mouse down                                                  */
  361. X/*-----------------------------------------------------------------------*/
  362. X
  363. Xstatic void select (w, event, args, n_args)
  364. XHyperWidget   w;
  365. XXEvent        *event;
  366. Xchar          *args[];
  367. Xint            n_args;
  368. X{
  369. X    text_segment *s;
  370. X
  371. X    /* 
  372. X       Find if the used clicked in an 
  373. X       highlighted text 
  374. X    */
  375. X
  376. X    if(s = w->hyper.last_selected = find_segment(w,event->xbutton.x,event->xbutton.y))
  377. X        hilite(w,TRUE);
  378. X}
  379. X
  380. X/*-----------------------------------------------------------------------*/
  381. X/* Check for mouse up                                                    */
  382. X/*-----------------------------------------------------------------------*/
  383. X
  384. Xstatic void activate (w, event, args, n_args)
  385. XHyperWidget   w;
  386. XXEvent        *event;
  387. Xchar          *args[];
  388. Xint            n_args;
  389. X{
  390. X    hyperCallbackStruct cb;
  391. X    text_segment *s;
  392. X
  393. X    /* 
  394. X       Find if the used clicked in an 
  395. X       highlighted text 
  396. X    */
  397. X
  398. X    if((s = find_segment(w,event->xbutton.x,event->xbutton.y))
  399. X        && (s == w->hyper.last_selected))
  400. X    {
  401. X        hilite(w,FALSE);
  402. X
  403. X        /* zoom if required */
  404. X
  405. X        if(w->hyper.zoom) zoom_open(w,s);
  406. X
  407. X        /* Fill callback struct */
  408. X
  409. X        cb.text     = s->text;
  410. X        cb.length   = s->length;
  411. X        cb.reason   = HYPER_REASON;
  412. X        cb.event    = event;
  413. X
  414. X        /* call callbacks */
  415. X
  416. X        XtCallCallbacks (w, XtNactivateCallback, &cb);
  417. X    }
  418. X    w->hyper.last_selected = NULL;
  419. X}
  420. X
  421. X/*-----------------------------------------------------------------------*/
  422. X/* Check for mouse moves                                                 */
  423. X/*-----------------------------------------------------------------------*/
  424. X
  425. Xstatic void cursor (w, event, args, n_args)
  426. XHyperWidget   w;
  427. XXEvent        *event;
  428. Xchar          *args[];
  429. Xint            n_args;
  430. X{
  431. X
  432. X    text_segment *s;
  433. X
  434. X    s = find_segment(w,event->xbutton.x,event->xbutton.y);
  435. X
  436. X    if(s != w->hyper.last_cursor)
  437. X    {
  438. X        if(s)
  439. X            XDefineCursor(XtDisplay(w),XtWindow(w),w->hyper.hand);
  440. X        else
  441. X            XUndefineCursor(XtDisplay(w),XtWindow(w));
  442. X        hilite(w,s == w->hyper.last_selected);
  443. X        w->hyper.last_cursor = s;
  444. X    }
  445. X
  446. X}
  447. X
  448. X
  449. X/*-----------------------------------------------------------------------*/
  450. X/* Add a new text segment to the text                                    */
  451. X/*-----------------------------------------------------------------------*/
  452. Xstatic void add_to_text(w,word,type)
  453. XHyperWidget w;
  454. Xchar *word;
  455. Xint  type;
  456. X{
  457. X    text_segment *s = XtNew(text_segment);
  458. X    XCharStruct   char_info;
  459. X    int dir,ascent,desc;
  460. X    text_segment *p,*q;
  461. X
  462. X    s->next = NULL;
  463. X    s->text = (word?XtNewString(word):NULL);
  464. X    s->type = type;
  465. X    s->gc   = (type == HIGHLIGHT ? w->hyper.highlight_gc : w->hyper.normal_gc);
  466. X    s->x    = s->y = s->width = s->height = 0;
  467. X    s->length = (word?strlen(word):0);
  468. X
  469. X    XTextExtents(
  470. X        (type == HIGHLIGHT ? w->hyper.highlight_font : w->hyper.normal_font),
  471. X        word,
  472. X        s->length,
  473. X        &dir,&ascent,&desc,&char_info);
  474. X
  475. X    s->height = ascent + desc;
  476. X    s->desc   = desc;
  477. X    s->width  = char_info.width;
  478. X
  479. X    if(p = w->hyper.first_seg)
  480. X    {
  481. X        while(p)
  482. X        {
  483. X            q=p;
  484. X            p=p->next;
  485. X        }
  486. X        q->next = s;
  487. X    }
  488. X    else w->hyper.first_seg = s;
  489. X}
  490. X
  491. X/*-----------------------------------------------------------------------*/
  492. X/* Rebuild the text structure. Called when the font changes              */
  493. X/*-----------------------------------------------------------------------*/
  494. X
  495. Xstatic void create_new_text(w)
  496. XHyperWidget   w;
  497. X{
  498. X    text_segment *s = w->hyper.first_seg;
  499. X
  500. X    w->hyper.first_seg = w->hyper.last_selected = w->hyper.last_cursor = NULL;
  501. X
  502. X    while(s)
  503. X    {
  504. X        add_to_text(w,s->text,s->type);
  505. X        s = s->next;
  506. X    }
  507. X    free_text(s);
  508. X    calc_new_size(w);
  509. X}
  510. X
  511. X/*-----------------------------------------------------------------------*/
  512. X/* Build the text. Gets the chars from the funtion "get_next_char"       */
  513. X/* using "data" as a parameter                                           */
  514. X/*-----------------------------------------------------------------------*/
  515. X
  516. Xstatic void set_text(w,get_next_char,data)
  517. XHyperWidget   w;
  518. Xchar (*get_next_char)();
  519. XXtPointer data;
  520. X{
  521. X    char word[MAX_LINE_SIZE];
  522. X    int  i = 0;
  523. X    char soh = w->hyper.start_of_highlight;
  524. X    char eoh = w->hyper.end_of_highlight;
  525. X    char c;
  526. X    int  mode = NORMAL;
  527. X
  528. X    free_text(w->hyper.first_seg);
  529. X    w->hyper.first_seg = w->hyper.last_selected = w->hyper.last_cursor = NULL;
  530. X    w->hyper.grep_seg = NULL;
  531. X    w->hyper.grep_txt = NULL;
  532. X    w->hyper.grep_len = 0;
  533. X    w->hyper.grep_off = 0;
  534. X
  535. X    while(c = (get_next_char)(&data))
  536. X    {
  537. X
  538. X        /* New line */
  539. X
  540. X        if(c == '\n')
  541. X        {
  542. X            word[i]=0;
  543. X            if(i) add_to_text(w,word,mode);
  544. X            add_to_text(w,NULL,NEWLINE);
  545. X            i = 0;
  546. X        }
  547. X
  548. X        /* Start of highlight */
  549. X
  550. X        else if(c == soh)
  551. X        {
  552. X            word[i]=0;
  553. X            if(i) add_to_text(w,word,mode);
  554. X            mode = HIGHLIGHT;
  555. X            i = 0;
  556. X        }
  557. X
  558. X        /* End of highlight */
  559. X
  560. X        else if(c == eoh)
  561. X        {
  562. X            word[i]=0;
  563. X            if(i) add_to_text(w,word,mode);
  564. X            mode = NORMAL;
  565. X            i = 0;
  566. X        }
  567. X        else 
  568. X        {
  569. X            if(c=='\t') c = ' ';
  570. X            word[i++] = c;
  571. X            if(i==MAX_LINE_SIZE)
  572. X            {
  573. X                word[--i]=0;
  574. X                add_to_text(w,word,mode);
  575. X                i=0;
  576. X                word[i++] = c;
  577. X            }
  578. X        }
  579. X    }
  580. X
  581. X    /* flush .. */
  582. X
  583. X    if(i)
  584. X    {
  585. X        word[i]=0;
  586. X        add_to_text(w,word,mode);
  587. X    }
  588. X
  589. X    calc_new_size(w);
  590. X
  591. X}
  592. X
  593. X/*-----------------------------------------------------------------------*/
  594. X/* Create a new HyperWidget                                              */
  595. X/*-----------------------------------------------------------------------*/
  596. X
  597. XWidget CreateHyper(parent,name,al,ac)
  598. XWidget parent;
  599. Xchar   *name;
  600. XArgList al;
  601. Xint     ac;
  602. X{
  603. X    return XtCreateWidget(name,hyperWidgetClass,parent,al,ac);
  604. X}
  605. X
  606. X
  607. X/*-----------------------------------------------------------------------*/
  608. X/* Load the text from a file                                             */
  609. X/*-----------------------------------------------------------------------*/
  610. X
  611. X/* provides chars to "set_text" routine */
  612. X
  613. Xstatic char get_from_file(f)
  614. XFILE **f;
  615. X{
  616. X    int n =  getc(*f);
  617. X    return (n==EOF?0:(char)n);
  618. X}
  619. X
  620. X/* Public routine */
  621. X
  622. Xvoid HyperLoadFile(widget,fname)
  623. XWidget widget;
  624. Xchar   *fname;
  625. X{
  626. X    extern char *sys_errlist[];
  627. X
  628. X    FILE *f = fopen(fname,"r");
  629. X    if(f)
  630. X    {
  631. X        set_text(widget,get_from_file,(XtPointer)f);
  632. X        fclose(f);
  633. X    }
  634. X    else
  635. X    {
  636. X        char msg[1024];
  637. X        sprintf(msg,"%s: %s",fname,sys_errlist[errno]);
  638. X        XtWarning(XtWidgetToApplicationContext(widget),msg);
  639. X    }
  640. X
  641. X}
  642. X
  643. X/*-----------------------------------------------------------------------*/
  644. X/* Load text from memory buffer                                          */
  645. X/*-----------------------------------------------------------------------*/
  646. X
  647. X/* provides chars to "set_text" routine */
  648. X
  649. Xstatic char get_from_buffer(buffer)
  650. Xchar **buffer;
  651. X{
  652. X    char c = **buffer;
  653. X    (*buffer)++;
  654. X    return c;
  655. X}
  656. X
  657. X/* Public routine */
  658. X
  659. Xvoid HyperSetText(widget,text)
  660. XWidget  widget;
  661. Xchar *text;
  662. X{
  663. X    set_text(widget,get_from_buffer,(XtPointer)text);
  664. X}
  665. X
  666. X/*-----------------------------------------------------------------------*/
  667. X/* Specifies start and end of highlignt chars                            */
  668. X/*-----------------------------------------------------------------------*/
  669. X
  670. X#ifdef _NO_PROTO
  671. X
  672. Xvoid HyperSetTags(widget,start_highlight,end_highlight)
  673. XWidget   widget;
  674. Xunsigned char start_highlight;
  675. Xunsigned char end_highlight;
  676. X
  677. X#else
  678. X
  679. Xvoid HyperSetTags(Widget widget,
  680. X                  unsigned char start_highlight,
  681. X                  unsigned char end_highlight)
  682. X
  683. X#endif
  684. X
  685. X{
  686. X    ((HyperWidget)widget)->hyper.start_of_highlight = start_highlight;
  687. X    ((HyperWidget)widget)->hyper.end_of_highlight = end_highlight;
  688. X}
  689. X
  690. X
  691. X/*-----------------------------------------------------------------------*/
  692. X/* convert a string to lower case                                        */
  693. X/*-----------------------------------------------------------------------*/
  694. X
  695. Xstatic void lowcase(p)
  696. Xregister char *p;
  697. X{
  698. X    while(*p)
  699. X    {
  700. X        if(isupper(*p)) *p += 32;
  701. X        p++;
  702. X    }
  703. X}
  704. X
  705. X/*-----------------------------------------------------------------------*/
  706. X/* Returns the text of the widget                                        */
  707. X/* the memory is allocated. It must be freed by the application          */
  708. X/* If include_tags if FALSE, the special characters are not returned     */
  709. X/*-----------------------------------------------------------------------*/
  710. X
  711. X#ifdef _NO_PROTO
  712. X
  713. Xchar *HyperGetText(widget,include_tags)
  714. XWidget widget;
  715. XBoolean include_tags;
  716. X
  717. X#else
  718. X
  719. Xchar *HyperGetText(Widget widget,Boolean include_tags)
  720. X
  721. X#endif
  722. X{
  723. X
  724. X    HyperWidget  w = (HyperWidget)widget;
  725. X    char         *p ;
  726. X    text_segment *s = w->hyper.first_seg;
  727. X    int          len = 1;
  728. X    char         soh[2];
  729. X    char         eoh[2];
  730. X
  731. X    soh[0] = w->hyper.start_of_highlight;
  732. X    eoh[0] = w->hyper.end_of_highlight;
  733. X
  734. X    soh[1] = eoh[1] = 0;
  735. X
  736. X    /* Get size of text */
  737. X
  738. X    while(s)
  739. X    {
  740. X        len += s->length?s->length:1;
  741. X        if(include_tags && s->type == HIGHLIGHT)
  742. X            len += 2;
  743. X        s = s->next;
  744. X    }
  745. X
  746. X    p = XtMalloc(len);
  747. X    *p = 0;
  748. X
  749. X    s = w->hyper.first_seg;
  750. X    while(s)
  751. X    {
  752. X        if(s->length)
  753. X        {
  754. X            if(include_tags && s->type == HIGHLIGHT)
  755. X                strcat(p,soh);
  756. X            strcat(p,s->text);
  757. X            if(include_tags && s->type == HIGHLIGHT)
  758. X                strcat(p,eoh);
  759. X        }
  760. X        else
  761. X            strcat(p,"\n");
  762. X        s=s->next;
  763. X    }
  764. X
  765. X    return p;
  766. X
  767. X}
  768. X
  769. X/*-----------------------------------------------------------------------*/
  770. X/* Only for Motif                                                        */
  771. X/* If the widget is in a XmScrolledWindow, scroll it so the selection is */
  772. X/* visible                                                               */
  773. SHAR_EOF
  774. echo "End of part 3"
  775. echo "File Hyper.c is continued in part 4"
  776. echo "4" > s2_seq_.tmp
  777. exit 0
  778. -- 
  779. --
  780. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  781. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  782. Sunnyvale, California 94086            at&t: 408/522-9236
  783.