home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CDisplayIndex.c
-
- Methods for a text list with selectable lines.
-
- Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
- Copyright ⌐ 1991 Manuel A. PÄrez. All rights reserved.
-
- ******************************************************************************/
-
-
- #include "CDisplayIndex.h"
- #include <Commands.h>
- #include <CDocument.h>
- #include <CBartender.h>
- #include <Constants.h>
- #include "Global.h"
- #include <string.h>
-
- /*** Global Variables ***/
- extern CBartender *gBartender;
- extern EventRecord gLastMouseUp;
-
- void CDisplayIndex::IDisplayIndex(CView *anEnclosure, CBureaucrat *aSupervisor,
- short vLoc, short vHeight, BrowserDir theDir, long index_displayed)
- {
-
- inherited::ISelectLine(anEnclosure, aSupervisor, vLoc, vHeight);
- itsDir = theDir;
- SetIndex(index_displayed);
-
- }
-
- /******************************************************************************
- SetIndex
-
- Build a text handle with the information for the index list, and
- stuff it into the TE item
- ******************************************************************************/
-
- void CDisplayIndex::SetIndex(long index_displayed)
- {
- BrowserItemPtr p;
- long offset;
- long totalSize;
- short len;
- Handle data;
- char *a;
-
- // as part of the initialization process, check how much
- // data we have in the header, create a handle and copy
- // it there.
-
- totalSize = 0;
- for (p = itsDir.topItem; p != NULL; p = p->next)
- switch (index_displayed) {
- case 200:
- default:
- totalSize += strlen(p->from) + 1; // 1 is for new line
- break;
- case 201:
- totalSize += strlen(p->date) + 1; // 1 is for new line
- break;
- case 202:
- totalSize += strlen(p->subject) + 1; // 1 is for new line
- break;
- }
-
- FailNIL(data = NewHandle(totalSize));
- HLock(data);
- offset = 0;
- for (p = itsDir.topItem; p != NULL; p = p->next) {
- switch (index_displayed) {
- case 200:
- default:
- a = p->from;
- break;
- case 201:
- a = p->date;
- break;
- case 202:
- a = p->subject;
- break;
- }
- len = strlen(a);
- BlockMove(a, (*data)+offset, len);
- offset += len;
- (*data)[offset++] = '\r'; // TE new line
- }
- (*data)[--offset] = ' '; // remove the last new line
- HUnlock(data);
- SetTextHandle(data);
- DisposHandle(data);
-
- }
-
-
- /******************************************************************************/
- void CDisplayIndex::Dispose(void)
- {
- BrowserItemPtr p, q;
-
- // release memory occupied by link list
- for (p = itsDir.topItem; p != NULL;) {
- q = p->next;
- Deallocate(p);
- p = q;
- }
- itsDir.topItem = NULL;
-
- // and close file
- fclose(itsDir.fp);
- inherited::Dispose();
-
- }
-
- /******************************************************************************
- SelectionChanged
-
- Called after the selection may have changed to notify dependants.
- ******************************************************************************/
-
- void CDisplayIndex::SelectionChanged(void)
- {
- register BrowserItemPtr p;
- long i;
-
- // find item
- p = itsDir.topItem;
- for (i = 0; i != selLine && p; i++)
- p = p->next;
-
- BroadcastChange(textSelectionChanged, (void *)p);
- }
-