home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Modules / PyServicesDelegate.m < prev    next >
Encoding:
Text File  |  1996-11-14  |  3.3 KB  |  135 lines

  1. /**
  2. *** Copyright (c) 1996 by Bill Bumgarner.  All Rights Reserved
  3. *** 
  4. *** This software may be used and distributed freely for any purpose
  5. *** provided that this notice is included unchanged on any and all copies.
  6. *** The author does not warrant or guarantee this software in any way.
  7. *** 
  8. *** 
  9. *** All queries, patches, and discussions of the PyObjC project should be
  10. *** directed to <objc-sig@python.org>.  The author can be reached via
  11. *** <bbum@friday.com>.
  12. *** 
  13. *** $RCSfile: PyServicesDelegate.m,v $
  14. *** 
  15. *** $Revision: 1.3 $
  16. *** 
  17. *** $Date: 1996/11/15 02:33:44 $
  18. *** 
  19. **/
  20.  
  21. #import <objc/Object.h>
  22.  
  23. #import <python1.4/OC_PythonObject.h>
  24. #import <python1.4/OC_PythonString.h>
  25. #import <python1.4/OC_PythonInt.h>
  26.  
  27. #import <appkit/Listener.h>
  28.  
  29. #import "PyServicesDelegate.h"
  30.  
  31. #define file_version "$Revision: 1.3 $"
  32. #define file_id      "$Id: PyServicesDelegate.m,v 1.3 1996/11/15 02:33:44 bbum Exp $"
  33.  
  34. // invoked by python when module is imported
  35. static PyMethodDef PyServicesDelegate_methods[] =
  36. {
  37.   { 0, 0, 0, 0 }
  38. };
  39.  
  40. void initPyServicesDelegate()
  41. {
  42.   PyObject *m;
  43.   m = Py_InitModule4 ("PyServicesDelegate", PyServicesDelegate_methods,
  44.               NULL, NULL, PYTHON_API_VERSION);
  45.   [PyServicesDelegate class];
  46. }
  47.  
  48. @interface PyServicesDelegate (HandlerMethod)
  49. - serviceForwarder: f
  50.     withPasteboard: pb
  51.       userData: (id <PythonObject>) ud;
  52. @end
  53.  
  54. @implementation PyServicesDelegate
  55. /*"
  56.  * An instance of PyServicesDelegate acts as a Listener's services
  57.  * delegate.  It currently only responds to services aimed at the that send
  58.  * the 'forwardService' message.  This is not really a limitation as one
  59.  * can easily dispatch custom services according to the information
  60.  * contained in the %userData field.
  61.  * 
  62.  * See the python example usage for more information as to how to use this
  63.  * class.
  64. "*/
  65.  
  66. /* ========================================================================
  67. ** Instantiation
  68. ** ========================================================================
  69. */
  70. + newWithHandler: (id <PythonObject>) aHandler; 
  71. {
  72.     id returnObject;
  73.  
  74.     if (!aHandler)
  75.     return nil;
  76.  
  77.     returnObject = [self alloc];
  78.  
  79.     [returnObject initWithHandler: aHandler];
  80.  
  81.     return returnObject;
  82. }
  83.  
  84. - initWithHandler: (id <PythonObject>) aHandler; 
  85. {
  86.     [super init];
  87.  
  88.     handler = aHandler;
  89.  
  90.     return self;
  91. }
  92.  
  93. /* ========================================================================
  94. ** Destruction
  95. ** ========================================================================
  96. */
  97. - free
  98. {
  99.     if (errMessageStore)
  100.     free((char *)errMessageStore);
  101.  
  102.     return [super free];
  103. }
  104.  
  105. /* ========================================================================
  106. ** Setting the error message
  107. ** ========================================================================
  108. */
  109. - (void) setErrorMessage: (const char *) aMessage;
  110. {
  111.     errMessageStore = NXCopyStringBuffer(aMessage);
  112. }
  113.  
  114. /* ========================================================================
  115. ** Services Handler
  116. ** ========================================================================
  117. */
  118. - forwardService: (Pasteboard *) pb
  119.     userData: (const char *)userData
  120.        error: (char **)errorMessage;
  121. {
  122.     errMessageStore = NULL;
  123.  
  124.     [(id)handler
  125.       serviceForwarder: self
  126.       withPasteboard: pb
  127.       userData: [OC_PythonString fromString:(char *)userData]];
  128.     
  129.     if (errMessageStore)
  130.     *errorMessage = (char *)errMessageStore;
  131.  
  132.     return self;    
  133. }
  134. @end
  135.