home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Palettes / MiscTableScroll / Framework / MiscDelegateFlags.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-31  |  5.9 KB  |  160 lines

  1. //=============================================================================
  2. //
  3. //  Copyright (C) 1995,1996,1997,1998 by Paul S. McCarthy and Eric Sunshine.
  4. //        Written by Paul S. McCarthy and Eric Sunshine.
  5. //                All Rights Reserved.
  6. //
  7. //    This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the authors
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "License.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14. //=============================================================================
  15. //-----------------------------------------------------------------------------
  16. // MiscDelegateFlags.cc
  17. //
  18. //    Flags indicating which selectors a delegate responds to.
  19. //
  20. //-----------------------------------------------------------------------------
  21. //-----------------------------------------------------------------------------
  22. // $Id: MiscDelegateFlags.cc,v 1.10 98/03/29 23:42:21 sunshine Exp $
  23. // $Log:    MiscDelegateFlags.cc,v $
  24. // Revision 1.10  98/03/29  23:42:21  sunshine
  25. // v138.1: Added -tableScroll:shouldDelayWindowOrderingForEvent:.
  26. // 
  27. // Revision 1.9  98/03/23  07:46:45  sunshine
  28. // v134.1: Eliminated -tableScroll:edit:atRow:column:.
  29. // 
  30. // Revision 1.8  97/06/18  10:28:13  sunshine
  31. // v125.9: Fixed bug: Was sending -tableScroll:textColorChangedTo: when it
  32. // should have sent -tableScroll:selectedTextColorChangedTo: and vice-versa.
  33. // highlightTextColor --> selectedTextColor
  34. // highlightBackgroundColor --> selectedBackgroundColor
  35. // buffCount --> bufferCount
  36. //-----------------------------------------------------------------------------
  37. #ifdef __GNUC__
  38. #pragma implementation
  39. #endif
  40. #include "MiscDelegateFlags.h"
  41. extern "Objective-C" {
  42. #import <Foundation/NSObject.h>
  43. }
  44. extern "C" {
  45. #include <string.h>
  46. }
  47.  
  48. static inline unsigned int BYTE_NUM( int x )    { return (x / 8); }
  49. static inline unsigned int BIT_NUM( int x )    { return (x % 8); }
  50. static inline unsigned char BIT_MASK( int x )    { return (1 << BIT_NUM(x)); }
  51.  
  52. #define PSEL(X)    &@selector(X)
  53.  
  54. // *** MUST MATCH ENUM IN .h FILE ***
  55. static SEL const* const SELECTORS[ MiscDelegateFlags::MAX_DEL_ENUM ] = 
  56.     {
  57.     PSEL(tableScroll:border:slotDraggedFrom:to:),
  58.     PSEL(tableScroll:border:slotSortReversed:),
  59.     PSEL(tableScroll:border:slotResized:),
  60.     PSEL(tableScroll:changeFont:to:),
  61.     PSEL(tableScroll:fontChangedFrom:to:),
  62.     PSEL(tableScroll:backgroundColorChangedTo:),
  63.     PSEL(tableScroll:selectedBackgroundColorChangedTo:),
  64.     PSEL(tableScroll:textColorChangedTo:),
  65.     PSEL(tableScroll:selectedTextColorChangedTo:),
  66.     PSEL(tableScroll:getISearchColumn:),
  67.     PSEL(tableScrollBufferCount:),
  68.     PSEL(tableScroll:border:slotPrototype:),
  69.     PSEL(tableScroll:border:slotTitle:),
  70.     PSEL(tableScroll:cellAtRow:column:),
  71.     PSEL(tableScroll:reviveCell:atRow:column:),
  72.     PSEL(tableScroll:retireCell:atRow:column:),
  73.     PSEL(tableScroll:tagAtRow:column:),
  74.     PSEL(tableScroll:intValueAtRow:column:),
  75.     PSEL(tableScroll:floatValueAtRow:column:),
  76.     PSEL(tableScroll:doubleValueAtRow:column:),
  77.     PSEL(tableScroll:stringValueAtRow:column:),
  78.     PSEL(tableScroll:titleAtRow:column:),
  79.     PSEL(tableScroll:stateAtRow:column:),
  80.     PSEL(tableScrollRegisterServicesTypes:),
  81.     PSEL(tableScroll:validRequestorForSendType:returnType:),
  82.     PSEL(tableScroll:canWritePboardType:),
  83.     PSEL(tableScroll:stringForPboardType:),
  84.     PSEL(tableScroll:writeSelectionToPasteboard:types:),
  85.     PSEL(tableScroll:readSelectionFromPasteboard:),
  86.     PSEL(tableScroll:allowDragOperationAtRow:column:),
  87.     PSEL(tableScroll:preparePasteboard:forDragOperationAtRow:column:),
  88.     PSEL(tableScroll:imageForDragOperationAtRow:column:),
  89.     PSEL(tableScroll:draggingSourceOperationMaskForLocal:),
  90.     PSEL(tableScrollIgnoreModifierKeysWhileDragging:),
  91.     PSEL(tableScroll:shouldDelayWindowOrderingForEvent:),
  92.     PSEL(tableScrollWillPrint:),
  93.     PSEL(tableScrollDidPrint:),
  94.     PSEL(tableScroll:willPrintPageHeader:info:),
  95.     PSEL(tableScroll:willPrintPageFooter:info:),
  96.     PSEL(tableScroll:canEdit:atRow:column:),
  97.     PSEL(tableScroll:setStringValue:atRow:column:),
  98.     PSEL(tableScroll:abortEditAtRow:column:),
  99.     PSEL(tableScroll:willEditAtRow:column:),
  100.     PSEL(tableScroll:didEdit:atRow:column:),
  101.     PSEL(controlTextDidEndEditing:),
  102.     PSEL(controlTextDidBeginEditing:),
  103.     PSEL(controlTextDidChange:),
  104.     PSEL(control:textShouldBeginEditing:),
  105.     PSEL(control:textShouldEndEditing:),
  106.     };
  107.  
  108. #undef PSEL
  109.  
  110. //-----------------------------------------------------------------------------
  111. // selToObjc
  112. //-----------------------------------------------------------------------------
  113. SEL MiscDelegateFlags::selToObjc( Selector s )
  114.     {
  115.     return *SELECTORS[s];
  116.     }
  117.  
  118.  
  119. //-----------------------------------------------------------------------------
  120. // objcToSel
  121. //-----------------------------------------------------------------------------
  122. MiscDelegateFlags::Selector MiscDelegateFlags::objcToSel( SEL s )
  123.     {
  124.     for (unsigned int i = 0; i < MAX_DEL_ENUM; i++)
  125.     if (s == *SELECTORS[i])
  126.         return (Selector)i;
  127.     return BAD_DEL_ENUM;
  128.     }
  129.  
  130.  
  131. //-----------------------------------------------------------------------------
  132. // setDelegate
  133. //-----------------------------------------------------------------------------
  134. void MiscDelegateFlags::setDelegate( id d )
  135.     {
  136.     if (d == 0)
  137.     memset( set, 0, SET_SIZE );
  138.     else
  139.     {
  140.     for (unsigned int i = 0; i < MAX_DEL_ENUM; i++)
  141.         {
  142.         unsigned char& byte = set[ BYTE_NUM(i) ];
  143.         unsigned char const mask = BIT_MASK(i);
  144.         if ([d respondsToSelector:(*SELECTORS[i])])
  145.         byte |= mask;
  146.         else
  147.         byte &= ~mask;
  148.         }
  149.     }
  150.     }
  151.  
  152.  
  153. //-----------------------------------------------------------------------------
  154. // respondsTo
  155. //-----------------------------------------------------------------------------
  156. bool MiscDelegateFlags::respondsTo( Selector s ) const
  157.     {
  158.     return ((set[ BYTE_NUM(s) ] & BIT_MASK(s)) != 0);
  159.     }
  160.