• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Subclassing NSTextAttachmentCell - drag and drop problems!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Subclassing NSTextAttachmentCell - drag and drop problems!


  • Subject: Subclassing NSTextAttachmentCell - drag and drop problems!
  • From: Michael Clark <email@hidden>
  • Date: Sun, 13 Jul 2003 00:42:34 -0400

Hi.

I am trying to recreate the drag and drop look and feel of the addresses in the Mail.app in Panther.

What I have figured I should do is subclass NSTextAttachmentCell and pass in the word I want it to represent and draw. I want this word to behave as if it were an image in the text document, in that you can drag it around to move it anywhere in the text view. (If I have gone down the wrong road with this approach please advice me!)

I have a few challenges I am not sure how to overcome, and I hope someone can offer from guidance!

1) I want the text that the cell is going to draw to have a similar size as the text surrounding it, i.e. I don't want it to be too obtrusive to the person creating a document in my app. I am drawing the word in a rectangle with rounded ends filled with a solid colour, but I want this rectangle to be only slightly bigger than the surrounding text. What I figured I should do is when I create the attachment cell, and set the word it represents on it, also set the current attributes (font info) of the point of insertion in the text view. But I am not sure what the best way to get this is. While playing around I ran in to the situation of nothing being in the text view to set an attribute precedence I can read from and use. How do I know what the current attribute set is at the insertion point?


2) Before I subclassed NSTextAttachmentCell I was experimenting with the cocoa text architecture, and I was manually creating an image cell and inserting a text attachment with this cell into my text view (no filewrapper!). Then I was trying to get drag and drop to work, but I kept getting this log in the console:
[NSTextView concludeDragOperation:]: Failed to read from drag pasteboard. Drag operation failed.

I tried using the methods:
- (NSArray *)textView:(NSTextView *)view writablePasteboardTypesForCell:(id <NSTextAttachmentCell>)cell atIndex:(unsigned)charIndex
and
- (BOOL)textView:(NSTextView *)view writeCell:(id <NSTextAttachmentCell>)cell atIndex:(unsigned)charIndex toPasteboard:(NSPasteboard *)pboard type:(NSString *)type

For the first methods I would return only one type, NSTIFFPboardType, and for the second I would write data from the image, using the TIFFRepresentation method on NSImage into the pasteboard. But I still got an error.

I don't understand what I should put on the pasteboard for this drag and drop to work within the text view.

Then, understanding this, what do I need to do with my subclass I mentioned above in question 1)? It's only state is an NSString, do I write this to the pasteboard somehow?


I hope this email is not too long, and someone can help me out!

Thanks in advance for your time.
Michael.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Linking a function to NSButton
  • Next by Date: Re: Linking a function to NSButton
  • Previous by thread: Re: Linking a function to NSButton
  • Next by thread: gdl2 (was Re: Linking problems with PostgreSQL)
  • Index(es):
    • Date
    • Thread