home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / Draw / gvServices.m < prev    next >
Encoding:
Text File  |  1992-07-20  |  2.6 KB  |  89 lines

  1. #import "draw.h"
  2.  
  3. @implementation GraphicView(Services)
  4.  
  5. /* Services menu methods */
  6.  
  7. /*
  8.  * Services in Draw are trivial to implement since we leverage heavily
  9.  * off of the copy/paste code.  Note that write/readSelectionTo/FromPasteboard:
  10.  * do little more than call the copy/paste code.
  11.  */
  12.  
  13. /*
  14.  * We are a valid requestor whenever any of the send or return types is
  15.  * PostScript, TIFF, or Draw (actually, any return type that NXImage can
  16.  * handle is okay with us).
  17.  */
  18.  
  19. - validRequestorForSendType:(NXAtom)sendType andReturnType:(NXAtom)returnType
  20. {
  21.  
  22.     if ((!sendType || !*sendType ||
  23.     ((sendType == NXPostScriptPboardType ||
  24.       sendType == NXTIFFPboardType ||
  25.       sendType == DrawPboardType) && [slist count])) &&
  26.     (!returnType || !*returnType ||
  27.       IncludesType([NXImage imagePasteboardTypes], returnType) ||
  28.       returnType == DrawPboardType)) {
  29.     return self;
  30.     }
  31.  
  32.     return [super validRequestorForSendType:sendType andReturnType:returnType];
  33. }
  34.  
  35. /*
  36.  * If one of the requested types is one of the ones we handRVg * then we put our selection in the Pasteboard.  The serviceActsOnSelection
  37.  * flag is so that we can effectively undo a Service request.
  38.  */
  39.  
  40. - (BOOL)writeSelectionToPasteboard:(Pasteboard *)pboard types:(NXAtom *)types
  41. {
  42.     while (types && *types) {
  43.     if (*types == NXPostScriptPboardType || *types == NXTIFFPboardType || *types == DrawPboardType) break;
  44.     types++;
  45.     }
  46.  
  47.     if (types && *types && [self copyToPasteboard:pboard types:types]) {
  48.     gvFlags.serviceActsOnSelection = YES;
  49.     return YES;
  50.     } else {
  51.     return NO;
  52.     }
  53. }
  54.  
  55. #define SERVICE_CALL_OPERATION NXLocalStringFromTable("Operations", "Service Call", NULL, "The user action of selecting an item in the Services menu.")
  56.  
  57. /*
  58.  * When a result comes back from the Services menu request,
  59.  * we replace the selection with the return value.
  60.  * If the user really wants the return value in addition to
  61.  * the current selection, she can simply copy, then paste
  62.  * twice to get two copies, then choose the Services menu item.
  63.  */
  64.  
  65. - readSelectionFromPasteboard:(Pasteboard *)pboard
  66. {
  67.     id change;
  68.     NXRect sbbox;
  69.     NXPoint *position = &sbbox.origin;
  70.     
  71.     change = [[MultipleChange alloc] initChangeName:SERVICE_CALL_OPERATION];
  72.     [change startChange];
  73.     if (gvFlags.serviceActsOnSelection) {
  74.         [self getBBox:&sbbox of:slist extended:NO];
  75.         sbbox.origin.x += floor(sbbox.size.width / 2.0 + 0.5);
  76.         sbbox.origin.y += floor(sbbox.size.height / 2.0 + 0.5);
  77.         [self delete:self];
  78.         gvFlags.serviceActsOnSelection = NO;
  79.     } else {
  80.         position = NULL;
  81.     }
  82.     [self pasteFromPasteboard:pboard andLink:DontLink at:position];
  83.     [change endChange];
  84.  
  85.     return self;
  86. }
  87.  
  88. @end
  89.