home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / editor / dig12.cpt / Views / CSelectLine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-01  |  3.9 KB  |  149 lines

  1. /******************************************************************************
  2.     CSelectLine.c
  3.     
  4.     Methods for a text list with selectable lines.
  5.         
  6.     Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
  7.     Copyright ⌐ 1991 Manuel A. PÄrez.  All rights reserved.
  8.  
  9.  ******************************************************************************/
  10.  
  11.  
  12. #include "CSelectLine.h"
  13. #include <Commands.h>
  14. #include <CDocument.h>
  15. #include <CBartender.h>
  16. #include <Constants.h>
  17. #include "Global.h"
  18. #include <string.h>
  19.  
  20. /*** Global Variables ***/
  21. extern    CBartender    *gBartender;
  22. extern EventRecord  gLastMouseUp;
  23.  
  24. void CSelectLine::ISelectLine(CView *anEnclosure, CBureaucrat *aSupervisor,
  25.         short vLoc, short vHeight)
  26. {
  27. Rect    margin;
  28.  
  29.     selLine = -1;
  30.     CEditText::IEditText(anEnclosure, aSupervisor,
  31.         1, vHeight,                     // aWidth, aHeight
  32.         0, vLoc,                    // aHEncl, aVEncl
  33.         sizELASTIC, sizELASTIC,        // aHSizing, aVSizing
  34.         -1);                        // lineWidth
  35.     FitToEnclosure(TRUE, FALSE);        // fit horiz, and vert
  36.  
  37.         /**
  38.          **    Give the edit pane a little margin.
  39.          **    Each element of the margin rectangle
  40.          **    specifies by how much to change that
  41.          **    edge. Positive values are down and to
  42.          **    right, negative values are up and to
  43.          **    the left.
  44.          **
  45.          **/
  46.  
  47.     (*macTE)->crOnly = -1;            // do not wrap around
  48.     SetRect(&margin, 2, 2, -2, -2);
  49.     ChangeSize(&margin, FALSE);
  50.     Specify(false, true, false);    // edit, select, style
  51.     SetCanBeGopher(true);
  52.  
  53. }
  54.  
  55. /******************************************************************************
  56.  FindEnds
  57.  
  58.  ******************************************************************************/
  59.  
  60. void    CSelectLine::FindEnds(long line, long *lineStart, long *lineEnd)
  61. {
  62.     register TEPtr        t;
  63.     long                lineNum;
  64.     
  65.     t = *macTE;
  66.                 
  67.     if (line < 0)                        // avoid problems with negative line #
  68.         line = 0;
  69.  
  70.     *lineStart = t->lineStarts[line];
  71.     if (line > t->nLines)
  72.         *lineEnd = t->teLength;            // special case, past end
  73.     else
  74.         *lineEnd = t->lineStarts[line+1];
  75. }
  76.  
  77. /******************************************************************************
  78.  DoClick {OVERRIDE}
  79.  
  80.         Respond to a mouse click within the EditText
  81.  ******************************************************************************/
  82.  
  83. void    CSelectLine::DoClick(
  84.     Point        hitPt,                    /* Mouse location in Frame coords    */
  85.     short        modifierKeys,            /* State of modifier keys            */
  86.     long        when)                    /* Tick time of mouse click            */
  87. {     
  88. long offset;
  89. LongPt lHitPt;
  90.  
  91.     QDToLongPt(hitPt, &lHitPt);
  92.     SetSelectedLine(FindLine(GetCharOffset(&lHitPt)), true);
  93.     
  94.         // CSwitchboard will never see the mouse up that ended
  95.         // the drag, so we stuff gLastMouseUp here to allow
  96.         // multi-click counting to work.
  97.         
  98.     gLastMouseUp.what = mouseUp;
  99.     gLastMouseUp.when = TickCount();
  100.     gLastMouseUp.where = hitPt;
  101.     LocalToGlobal( &gLastMouseUp.where);
  102.     gLastMouseUp.modifiers = modifierKeys;
  103.  
  104. }
  105.  
  106. void CSelectLine::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  107. {
  108. }
  109.  
  110. /******************************************************************************
  111.  SetSelectedLine
  112.  
  113.      Sets the selected text to the range corresponding to character positions
  114.      selStart through selEnd.
  115. ******************************************************************************/
  116.  
  117. void CSelectLine::SetSelectedLine( long line, Boolean fRedraw)
  118. {
  119. long selStart, selEnd;
  120.  
  121.     FindEnds(line, &selStart, &selEnd);
  122.     SetSelection(selStart, selEnd, true);
  123.  
  124.     if (line != selLine) {
  125.         selLine = line;
  126.         if (fRedraw)
  127.             SelectionChanged();
  128.     }
  129. }    /* CSelectLine::SetSelection */
  130.  
  131. long CSelectLine::GetSelectedLine(void)
  132. {
  133.     return selLine;
  134. }
  135.  
  136. /******************************************************************************
  137.  AdjustCursor {OVERRIDE}
  138.  
  139.         Mouse is inside the CSelectLine area, set the cursor to the arrow
  140.  ******************************************************************************/
  141.  
  142. void    CSelectLine::AdjustCursor(
  143.     Point        where,                    /* Mouse location in Window coords    */
  144.     RgnHandle    mouseRgn)
  145. {
  146.     SetCursor(&arrow);                    /* Use the standard arrow cursor    */
  147. }
  148.  
  149.