home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / Tutorial / Cookbook / 08.copy / notes < prev    next >
Encoding:
Text File  |  1993-01-19  |  2.1 KB  |  73 lines

  1. Objective:
  2.    Learn how to copy postscript into the pastboard.
  3.  
  4. Terms:
  5.    responder - the view on the screen that is responding to messages.
  6.    In this case the correct plot view must be selected with the mouse
  7.    just before the copy method has been used.
  8.    pasteboard - the structure used to copy text, graphics and sound
  9.    between different NextStep applications.
  10.    
  11. Complexity:
  12.     4 methods
  13.     2 calls to NX library
  14.  
  15. Discussion:
  16. To use this you have to click on the view you would like to copy.
  17. It will then become the FirstResponder. You then select the copy
  18. command and the postscript code that did the drawing will be copied
  19. to the pastboard.  You can then copy the code to WriteNow, Draw or
  20. even YAP program.
  21.    
  22. Method:
  23.    Add the following code to the line program:
  24. -----------------------------------------------
  25. - copy:sender { 
  26.    id pb = [NXApp pasteboard];  /* global Pasteboard object */ 
  27.    NXStream  *st;               /* stream to collect data in */ 
  28.    char      *data;             /* actual data buffer */ 
  29.    int       length;            /* length of data */ 
  30.    int       maxLength;         /* (not used here) */
  31.  
  32.    // To see how to use the pasteboard see page 10-33 of
  33.    // the SysRefMan
  34.    // declare that we will supply a single type of data: PostScript
  35.    [pb declareTypes:&NXPostScriptPboard num:1 owner:self];
  36.  
  37.    /* get a stream which writes to memory */ 
  38.    st = NXOpenMemory( NULL, 0, NX_WRITEONLY );
  39.  
  40.    /* write PostScript code for this view into the stream */ 
  41.    [self copyPSCodeInside:NULL to:st];
  42.  
  43.    /* get actual data buffer from stream */ 
  44.    NXGetMemoryBuffer( st, &data, &length, &maxLength );
  45.  
  46.    /* write PostScript data to pasteboard */ 
  47.    [pb writeType:NXPostScriptPboard data:data length:length];
  48.  
  49.    /* deallocate stream, including its buffer */ 
  50.    NXCloseMemory( st, NX_FREEBUFFER );
  51.  
  52.    return self; 
  53. }
  54.  
  55.  
  56. /* make this view accept first responder so it will understand copy */
  57. -(BOOL)acceptsFirstResponder
  58. {
  59.     return (YES);
  60. }
  61.  
  62. -resignFirstResponder
  63. {
  64.     return self;
  65. }
  66. -----------------------------------------------
  67. Connect the Edit/Copy menu to the FirstResponder Icon in the lower left
  68. window of the Interface Builder.
  69.  
  70. Summary:
  71.  
  72.  
  73.