home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 January / macpower199701.bin / AMUG / Programming_10 / WASTE 1.3a1.sit / WASTE 1.3a1 Distribution / WASTE 1.3a1 / WESelectors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-23  |  5.4 KB  |  174 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    WESelectors.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *  Routines for manipulating selector lookup tables
  6.  *
  7.  *  Copyright (c) 1993-1996 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  *  C port by Dan Crevier
  11.  *
  12.  */
  13.  
  14.  
  15. #include "WASTEIntf.h"
  16.  
  17. // MPW can't handle FIELD_DESC stuff (duh!)
  18.  
  19. #ifdef applec
  20.  
  21. //#error "hand-made selector tables not up-to-date!"
  22.  
  23. // this is **ugly** and will break if we change the declaration of WERec
  24.  
  25. WELookupTable _weMainSelectorTable[] = {
  26. { weRefCon,                     0x0078, 0x0004 },
  27. { wePort,                        0x0000, 0x0004 },
  28. { weText,                        0x0004, 0x0004 },
  29. { weCharToPixelHook,            0x00BC, 0x0004 },
  30. { weCharByteHook,                0x00C8, 0x0004 },
  31. { weCharTypeHook,                0x00CC, 0x0004 },
  32. { weClickLoop,                    0x009C, 0x0004 },
  33. { weCurrentDrag,                0x008C, 0x0004 },
  34. { weDrawTextHook,                0x00B4, 0x0004 },
  35. { weEraseHook,                    0x00D0, 0x0004 },
  36. { weHiliteDropAreaHook,         0x00B0, 0x0004 },
  37. { weLineBreakHook,                0x00C0, 0x0004 },
  38. { weLineArray,                    0x0008, 0x0004 },
  39. { wePixelToCharHook,            0x00B8, 0x0004 },
  40. { weTSMPostUpdate,                0x00A8, 0x0004 },
  41. { weTSMPreUpdate,                0x00A4, 0x0004 },
  42. { weRunArray,                    0x0010, 0x0004 },
  43. { weScrollProc,                    0x00A0, 0x0004 },
  44. { weStyleTable,                    0x000C, 0x0004 },
  45. { weTSMDocumentID,                0x0080, 0x0004 },
  46. { weWordBreakHook,                0x00C4, 0x0004 },
  47. { weTranslateDragHook,            0x00AC, 0x0004 },
  48. #if WASTE_TRANSLUCENT_DRAGS
  49. { weTranslucencyThreshold,        0x00EC, 0x0004 },
  50. #endif
  51. #if WASTE_IC_SUPPORT
  52. { weURLHint,                    0x00F0, 0x0004 },
  53. #endif
  54. { 0,                     0, 0 }};
  55.  
  56. #if WASTE_OBJECTS
  57.  
  58. WELookupTable _weObjectHandlerSelectorTable[] = {
  59. { weClickHandler,        0x0010, 0x0004 },
  60. { weDrawHandler,        0x000C, 0x0004 },
  61. { weDisposeHandler,        0x0008, 0x0004 },
  62. { weNewHandler,            0x0004, 0x0004 },
  63. { weStreamHandler,      0x0014, 0x0004 },
  64. { weRefCon,             0x0018, 0x0004 },
  65. { 0,                     0, 0 }};
  66.  
  67. #endif  // WASTE_OBJECTS
  68.  
  69. #else
  70.  
  71. // proper way of defining selector tables
  72.  
  73. #define FIELD_OFFSET(FIELD, STRUCT)        (SInt16) &((STRUCT *) 0L)->FIELD
  74. #define FIELD_SIZE(FIELD, STRUCT)        (SInt16) sizeof(((STRUCT *) 0L)->FIELD)
  75. #define FIELD_DESC(FIELD, STRUCT)        { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
  76.  
  77. WELookupTable _weMainSelectorTable[] = {
  78. { weRefCon,                 FIELD_DESC(refCon,                    WERec) },
  79. { wePort,                    FIELD_DESC(port,                      WERec) },
  80. { weText,                    FIELD_DESC(hText,                     WERec) },
  81. { weCharToPixelHook,        FIELD_DESC(charToPixelHook,           WERec) },
  82. { weCharByteHook,            FIELD_DESC(charByteHook,              WERec) },
  83. { weCharTypeHook,            FIELD_DESC(charTypeHook,              WERec) },
  84. { weClickLoop,                FIELD_DESC(clickLoop,                 WERec) },
  85. { weCurrentDrag,            FIELD_DESC(currentDrag,               WERec) },
  86. { weDrawTextHook,            FIELD_DESC(drawTextHook,              WERec) },
  87. { weEraseHook,                FIELD_DESC(eraseHook,                WERec) },
  88. { weHiliteDropAreaHook,        FIELD_DESC(hiliteDropAreaHook,        WERec) },
  89. { weLineBreakHook,            FIELD_DESC(lineBreakHook,             WERec) },
  90. { weLineArray,                FIELD_DESC(hLines,                    WERec) },
  91. { wePixelToCharHook,        FIELD_DESC(pixelToCharHook,           WERec) },
  92. { weTSMPostUpdate,            FIELD_DESC(tsmPostUpdate,             WERec) },
  93. { weTSMPreUpdate,            FIELD_DESC(tsmPreUpdate,              WERec) },
  94. { weRunArray,                FIELD_DESC(hRuns,                     WERec) },
  95. { weScrollProc,                FIELD_DESC(scrollProc,                WERec) },
  96. { weStyleTable,                FIELD_DESC(hStyles,                   WERec) },
  97. { weTSMDocumentID,            FIELD_DESC(tsmReference,              WERec) },
  98. { weWordBreakHook,            FIELD_DESC(wordBreakHook,            WERec) },
  99. { weTranslateDragHook,        FIELD_DESC(translateDragHook,         WERec) },
  100. #if WASTE_TRANSLUCENT_DRAGS
  101. { weTranslucencyThreshold,     FIELD_DESC(translucencyThreshold,    WERec) },
  102. #endif
  103. #if WASTE_IC_SUPPORT
  104. { weURLHint,                FIELD_DESC(hURLHint,                  WERec) },
  105. #endif
  106. { 0,                     0, 0 }};
  107.  
  108. #if WASTE_OBJECTS
  109.  
  110. WELookupTable _weObjectHandlerSelectorTable[] = {
  111. { weClickHandler,        FIELD_DESC(clickHandler,      WEOHTableElement) },
  112. { weDrawHandler,        FIELD_DESC(drawHandler,       WEOHTableElement) },
  113. { weDisposeHandler,        FIELD_DESC(freeHandler,       WEOHTableElement) },
  114. { weNewHandler,            FIELD_DESC(newHandler,        WEOHTableElement) },
  115. { weStreamHandler,      FIELD_DESC(streamHandler,     WEOHTableElement) },
  116. { weRefCon,             FIELD_DESC(refCon,            WEOHTableElement) },
  117. { 0,                     0, 0 }};
  118.  
  119. #endif    // WASTE_OBJECTS
  120.  
  121. #endif    // !applec
  122.  
  123. pascal void _WELookupSelector(const WELookupTable *table, WESelector selector, WEFieldDescriptor *desc)
  124. {
  125.     for ( ; table->selector != selector ; table++ )
  126.         if ( * (SInt32 *) &(table->desc) == 0L )
  127.             break;
  128.  
  129.     *desc = table->desc;
  130. }
  131.  
  132. pascal OSErr _WEGetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  133. {
  134.     WEFieldDescriptor desc;
  135.  
  136.     _WELookupSelector(table, selector, &desc);
  137.  
  138.     if (desc.fLength == 0)
  139.         return weUndefinedSelectorErr;
  140.  
  141.     *info = * (SInt32 *) ((SInt32) structure + desc.fOffset);
  142.     return noErr;
  143. }
  144.  
  145. pascal OSErr _WESetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  146. {
  147.     WEFieldDescriptor desc;
  148.  
  149.     _WELookupSelector(table, selector, &desc);
  150.  
  151.     if (desc.fLength == 0)
  152.         return weUndefinedSelectorErr;
  153.  
  154.     * (SInt32 *) ((SInt32) structure + desc.fOffset) = *info;
  155.     return noErr;
  156. }
  157.  
  158. pascal OSErr WEGetInfo(WESelector selector, void *info, WEHandle hWE)
  159. {
  160.     return _WEGetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  161. }
  162.  
  163. pascal OSErr WESetInfo(WESelector selector, const void *info, WEHandle hWE)
  164. {
  165.     OSErr err;
  166.  
  167.     err = _WESetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  168.  
  169.     // the hook fields can never be nil, so replace any nil field with the default address
  170.     _WESetStandardHooks(hWE);
  171.  
  172.     return err;
  173. }
  174.