home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / editor / dig12.cpt / Views / CDisplayText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-29  |  2.6 KB  |  103 lines

  1. /******************************************************************************
  2.     CDisplayText.c
  3.     
  4.     Methods for a text editing pane.
  5.         
  6.     Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
  7.     Copyright ⌐ 1991 Manuel A. PÄrez.  All rights reserved.
  8.  
  9.     2/29/92 - Set Scroll Bars back to the top when a new item is shown
  10.  ******************************************************************************/
  11.  
  12.  
  13. #include "CDisplayText.h"
  14. #include "Browser.h"
  15.  
  16. void CDisplayText::IDisplayText(CView *anEnclosure, CBureaucrat *aSupervisor,
  17.         short vLoc, short heigth)
  18. {
  19. Rect    margin;
  20.  
  21.     CEditText::IEditText(anEnclosure, aSupervisor,
  22.         1, height,                         // aWidth, aHeight
  23.         0, vLoc,                        // aHEncl, aVEncl
  24.         sizELASTIC, sizELASTIC,            // aHSizing, aVSizing
  25.         -1);                            // lineWidth
  26.     FitToEnclosure(TRUE, TRUE);            // fit horiz, but not vert
  27.  
  28.         /**
  29.          **    Give the edit pane a little margin.
  30.          **    Each element of the margin rectangle
  31.          **    specifies by how much to change that
  32.          **    edge. Positive values are down and to
  33.          **    right, negative values are up and to
  34.          **    the left.
  35.          **
  36.          **/
  37.  
  38.     SetRect(&margin, 2, 2, -2, -2);
  39.     ChangeSize(&margin, FALSE);
  40.     Specify(false, true, false);    // edit, select, style
  41.     SetCanBeGopher(true);
  42.  
  43.     // set default font and font size for this display
  44.     SetFontNumber(geneva);
  45.     SetFontSize(10);
  46.     (*macTE)->crOnly = 1;            // do wrap around
  47.  
  48.  
  49. }    /* IDisplayText */
  50.  
  51. void CDisplayText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  52. {
  53. }
  54.  
  55. /******************************************************************************
  56.  ProviderChanged
  57.  
  58.      Respond to the provider change.
  59.      
  60. ******************************************************************************/
  61.  
  62. void CDisplayText::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
  63.  
  64. {
  65. BrowserItemPtr p;
  66. long line;
  67. long len;
  68. Handle text;
  69. long offset;
  70. LongPt aPosition;
  71.  
  72.     switch (reason) {
  73.         case textSelectionChanged:
  74.             p = (BrowserItemPtr) info;
  75.  
  76.             // get info from file and draw it on screen
  77.             if (p) {
  78.  
  79.                 len = p->endAt - p->startAt;
  80.                 FailNIL(text = NewHandle(len));        // fail if no memory
  81.                 HLock(text);                        // lock handle
  82.                 fseek(p->fp, p->startAt, 0);        // read in text
  83.                 fread(*text, 1, len, p->fp);
  84.  
  85.                 offset = 0;                            // replace '\n' with '\r'
  86.                 do {
  87.                     offset = Munger(text, offset, "\n", 1, "\r", 1);
  88.                 } while (offset > 0);
  89.  
  90.                 HUnlock(text);                        // unlock handle
  91.                 SetTextHandle(text);                // put text on window
  92.                 DisposHandle(text);                    // release handle 
  93.  
  94.                 // Set the scrollers back to the top
  95.                 aPosition.h = 0;
  96.                 aPosition.v = 0;
  97.                 ScrollTo(&aPosition, true);
  98.             }
  99.  
  100.             break;
  101.     }
  102. }    /* ProviderChanged */
  103.