home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / WASTE 1.1a4 / WASTE Source / Assembly / Selectors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-12  |  4.4 KB  |  177 lines  |  [TEXT/R*ch]

  1. /*
  2.  *    Selectors.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *    WEGetInfo / WESetInfo
  6.  *
  7.  *    Copyright (c) 1993-1994 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  */
  11.  
  12. #ifndef _WASTE_use_68k_asm_
  13. #define _WASTE_use_68k_asm_ 1L
  14. #endif
  15.  
  16. #define weUndefinedSelectorErr            -50 /* paramErr */
  17.  
  18. #define FIELD_OFFSET(FIELD, STRUCT)        (short) &((STRUCT *) 0L)->FIELD
  19. #define FIELD_SIZE(FIELD, STRUCT)        (short) sizeof(((STRUCT *) 0L)->FIELD)
  20. #define FIELD_DESC(FIELD, STRUCT)        { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
  21.  
  22. typedef struct WEFieldDescriptor {
  23.     short fOffset;
  24.     short fLength;
  25. } WEFieldDescriptor;
  26.  
  27. typedef struct WELookupTable {
  28.     OSType selector;
  29.     WEFieldDescriptor desc;
  30. } WELookupTable;
  31.  
  32. pascal void _WELookupSelector(/*const*/ WELookupTable *table, OSType selector, WEFieldDescriptor *desc);
  33. pascal OSErr _WEGetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure);
  34. pascal OSErr _WESetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure);
  35.  
  36. typedef struct LongRect {
  37.     long top;
  38.     long left;
  39.     long bottom;
  40.     long right;
  41. } LongRect;
  42.  
  43. typedef struct    WERec {            /* version 1.1a4 */
  44.     GrafPtr port;
  45.     Handle hText;
  46.     Handle hLines;
  47.     Handle hStyles;
  48.     Handle hRuns;
  49.     long textLength;
  50.     long nLines;
  51.     long nStyles;
  52.     long nRuns;
  53.     LongRect viewRect;
  54.     LongRect destRect;
  55.     long selStart;
  56.     long selEnd;
  57.     unsigned long flags;
  58.     long caretTime;
  59.     long clickTime;
  60.     long clickLoc;
  61.     long anchorStart;
  62.     long anchorEnd;
  63.     ProcPtr clickLoop;
  64.     char unused1;
  65.     char clickEdge;
  66.     char unused2;
  67.     char firstByte;
  68.     GrafPtr offscreenPort;
  69.     RgnHandle viewRgn;
  70.     ProcPtr scrollProc;
  71.     short clickCount;    
  72.     char alignment;
  73.     long refCon;
  74.     Ptr tsmReference;
  75.     long tsmAreaStart;
  76.     long tsmAreaEnd;
  77.     ProcPtr tsmPreUpdate;
  78.     ProcPtr tsmPostUpdate;
  79.     long currentDrag;
  80.     long dragCaretOffset;
  81.     ProcPtr translateDragHook;
  82.     Handle hActionStack;
  83.     long modCount;
  84.     /* WERunAttributes nullStyle; */
  85. } WERec;
  86.  
  87. WELookupTable _WEMainSelectorTable[] = {
  88. { 'clik',     FIELD_DESC(clickLoop,         WERec) },
  89. { 'drag',     FIELD_DESC(currentDrag,       WERec) },
  90. { 'line',     FIELD_DESC(hLines,            WERec) },
  91. { 'port',     FIELD_DESC(port,              WERec) },
  92. { 'post',     FIELD_DESC(tsmPostUpdate,     WERec) },
  93. { 'pre ',     FIELD_DESC(tsmPreUpdate,      WERec) },
  94. { 'refc',     FIELD_DESC(refCon,            WERec) },
  95. { 'runa',     FIELD_DESC(hRuns,             WERec) },
  96. { 'scrl',     FIELD_DESC(scrollProc,        WERec) },
  97. { 'styl',     FIELD_DESC(hStyles,           WERec) },
  98. { 'text',     FIELD_DESC(hText,             WERec) },
  99. { 'tsmd',     FIELD_DESC(tsmReference,      WERec) },
  100. { 'xdrg',     FIELD_DESC(translateDragHook, WERec) },
  101. { 0, 0, 0 }};
  102.  
  103. typedef struct WEOHTableElement {
  104.     OSType objectType;
  105.     ProcPtr newHandler;
  106.     ProcPtr freeHandler;
  107.     ProcPtr drawHandler;
  108.     ProcPtr clickHandler;
  109.     ProcPtr cursorHandler;
  110. } WEOHTableElement;
  111.  
  112. WELookupTable _WEObjectHandlerSelectorTable[] = {
  113. { 'clik',     FIELD_DESC(clickHandler,      WEOHTableElement) },
  114. { 'curs',     FIELD_DESC(cursorHandler,     WEOHTableElement) },
  115. { 'draw',     FIELD_DESC(drawHandler,       WEOHTableElement) },
  116. { 'free',     FIELD_DESC(freeHandler,       WEOHTableElement) },
  117. { 'new ',     FIELD_DESC(newHandler,        WEOHTableElement) },
  118. { 0, 0, 0 }};
  119.  
  120. pascal void _WELookupSelector(/*const*/ WELookupTable *table, OSType selector, WEFieldDescriptor *desc)
  121. {
  122.  
  123. #if _WASTE_use_68k_asm_
  124.  
  125.     asm {
  126.             move.l selector, d0            ; d0 = selector code to search
  127.             move.l table, a0            ; a0 = start of table
  128.             move.l desc, a1                ; a1 = ptr to desc variable
  129.             clr.l (a1)                    ; 
  130.  
  131. @loop        cmp.l (a0)+, d0                ; selector found?
  132.             beq @found                    ; 
  133.             tst.l (a0)+                    ; at the end of the table?
  134.             bne.s @loop                    ; 
  135.             bra.s @exit                    ; 
  136.  
  137. @found        move.l (a0), (a1)            ; copy descriptor record
  138. @exit
  139.     }
  140.  
  141. #else
  142.  
  143.     for ( ; table->selector != selector ; table++ )
  144.         if ( * (long *) &(table->desc) == 0L )
  145.             break;
  146.     
  147.     *desc = table->desc;
  148.  
  149. #endif
  150.  
  151. }
  152.  
  153. pascal OSErr _WEGetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure)
  154. {
  155.     WEFieldDescriptor desc;
  156.     
  157.     _WELookupSelector(table, selector, &desc);
  158.     
  159.     if (desc.fLength == 0)
  160.         return weUndefinedSelectorErr;
  161.     
  162.     *info = * (long *) ((long) structure + desc.fOffset);
  163.     return noErr;
  164. }
  165.  
  166. pascal OSErr _WESetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure)
  167. {
  168.     WEFieldDescriptor desc;
  169.     
  170.     _WELookupSelector(table, selector, &desc);
  171.     
  172.     if (desc.fLength == 0)
  173.         return weUndefinedSelectorErr;
  174.     
  175.     * (long *) ((long) structure + desc.fOffset) = *info;
  176.     return noErr;
  177. }