home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / editor / dig12.cpt / Views / CDisplayIndex.c next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  3.1 KB  |  135 lines

  1. /******************************************************************************
  2.     CDisplayIndex.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 "CDisplayIndex.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 CDisplayIndex::IDisplayIndex(CView *anEnclosure, CBureaucrat *aSupervisor,
  25.         short vLoc, short vHeight, BrowserDir theDir, long index_displayed)
  26. {
  27.  
  28.     inherited::ISelectLine(anEnclosure, aSupervisor, vLoc, vHeight);
  29.     itsDir = theDir;
  30.     SetIndex(index_displayed);
  31.  
  32. }
  33.  
  34. /******************************************************************************
  35.  SetIndex
  36.  
  37.         Build a text handle with the information for the index list, and
  38.         stuff it into the TE item
  39.  ******************************************************************************/
  40.  
  41. void    CDisplayIndex::SetIndex(long index_displayed)
  42. {
  43. BrowserItemPtr p;
  44. long    offset;
  45. long    totalSize;
  46. short    len;
  47. Handle    data;
  48. char *a;
  49.  
  50.     // as part of the initialization process, check how much
  51.     // data we have in the header, create a handle and copy
  52.     // it there.
  53.  
  54.     totalSize = 0;
  55.     for (p = itsDir.topItem; p != NULL; p = p->next)
  56.         switch (index_displayed) {
  57.             case 200:
  58.             default:
  59.                 totalSize += strlen(p->from) + 1;        // 1 is for new line
  60.                 break;
  61.             case 201:
  62.                 totalSize += strlen(p->date) + 1;        // 1 is for new line
  63.                 break;
  64.             case 202:
  65.                 totalSize += strlen(p->subject) + 1;        // 1 is for new line
  66.                 break;
  67.         }
  68.  
  69.     FailNIL(data = NewHandle(totalSize));
  70.     HLock(data);
  71.     offset = 0;
  72.     for (p = itsDir.topItem; p != NULL; p = p->next) {
  73.         switch (index_displayed) {
  74.             case 200:
  75.             default:
  76.                 a = p->from;
  77.                 break;
  78.             case 201:
  79.                 a = p->date;
  80.                 break;
  81.             case 202:
  82.                 a = p->subject;
  83.                 break;
  84.         }
  85.         len = strlen(a);
  86.         BlockMove(a, (*data)+offset, len);
  87.         offset += len;
  88.         (*data)[offset++] = '\r';        // TE new line
  89.     }
  90.     (*data)[--offset] = ' ';            // remove the last new line
  91.     HUnlock(data);
  92.     SetTextHandle(data);
  93.     DisposHandle(data);
  94.  
  95. }
  96.  
  97.  
  98. /******************************************************************************/
  99. void CDisplayIndex::Dispose(void)
  100. {
  101. BrowserItemPtr p, q;
  102.  
  103.     // release memory occupied by link list
  104.     for (p = itsDir.topItem; p != NULL;) {
  105.         q = p->next;
  106.         Deallocate(p);
  107.         p = q;
  108.     }
  109.     itsDir.topItem = NULL;
  110.  
  111.     // and close file
  112.     fclose(itsDir.fp);
  113.     inherited::Dispose();
  114.  
  115. }
  116.  
  117. /******************************************************************************
  118.  SelectionChanged
  119.  
  120.     Called after the selection may have changed to notify dependants.
  121.  ******************************************************************************/
  122.  
  123. void CDisplayIndex::SelectionChanged(void)
  124. {
  125. register BrowserItemPtr p;
  126. long i;
  127.  
  128.     // find item
  129.     p  = itsDir.topItem;
  130.     for (i = 0; i != selLine && p; i++)
  131.         p = p->next;
  132.  
  133.     BroadcastChange(textSelectionChanged, (void *)p);
  134. }
  135.