|
|
1.1 ! root 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 handle, ! 37: * then we put our selection in the Pasteboard. The serviceActsOnSelection ! 38: * flag is so that we can effectively undo a Service request. ! 39: */ ! 40: ! 41: - (BOOL)writeSelectionToPasteboard:(Pasteboard *)pboard types:(NXAtom *)types ! 42: { ! 43: while (types && *types) { ! 44: if (*types == NXPostScriptPboardType || *types == NXTIFFPboardType || *types == DrawPboardType) break; ! 45: types++; ! 46: } ! 47: ! 48: if (types && *types && [self copyToPasteboard:pboard types:types]) { ! 49: gvFlags.serviceActsOnSelection = YES; ! 50: return YES; ! 51: } else { ! 52: return NO; ! 53: } ! 54: } ! 55: ! 56: #define SERVICE_CALL_OPERATION NXLocalStringFromTable("Operations", "Service Call", NULL, "The user action of selecting an item in the Services menu.") ! 57: ! 58: /* ! 59: * When a result comes back from the Services menu request, ! 60: * we replace the selection with the return value. ! 61: * If the user really wants the return value in addition to ! 62: * the current selection, she can simply copy, then paste ! 63: * twice to get two copies, then choose the Services menu item. ! 64: */ ! 65: ! 66: - readSelectionFromPasteboard:(Pasteboard *)pboard ! 67: { ! 68: id change; ! 69: NXRect sbbox; ! 70: NXPoint *position = &sbbox.origin; ! 71: ! 72: change = [[MultipleChange alloc] initChangeName:SERVICE_CALL_OPERATION]; ! 73: [change startChange]; ! 74: if (gvFlags.serviceActsOnSelection) { ! 75: [self getBBox:&sbbox of:slist extended:NO]; ! 76: sbbox.origin.x += floor(sbbox.size.width / 2.0 + 0.5); ! 77: sbbox.origin.y += floor(sbbox.size.height / 2.0 + 0.5); ! 78: [self delete:self]; ! 79: gvFlags.serviceActsOnSelection = NO; ! 80: } else { ! 81: position = NULL; ! 82: } ! 83: [self pasteFromPasteboard:pboard andLink:DontLink at:position]; ! 84: [change endChange]; ! 85: ! 86: return self; ! 87: } ! 88: ! 89: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.