Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Two Unrelated NSTextView Questions

Two Unrelated NSTextView Questions
Thread Tools
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 22, 2004, 06:50 AM
 
QUESTION ONE

I want users to be able to drag blocks of selected text within an NSTextView to re-arrange the text. Currently, if a user tries to do this, it just changes the selection. How do I get a NSTextView to treat a drag as a "pick up that text and move it" operation, rather than just deselecting that text, and doing another selection operation?


QUESTION TWO

In a different NSTextView, I have some rather complex layout to do, including what will probably end up as 3 NSTextViews. So I guess I should be using NSLayoutManager. I'm still trying to come to grips with how this works. How do I determine which text ends up in which NSTextView?

Sorry, this is a very broad question, but I'm not yet sure of the best strategy to accomplish my results. As further background, I have an attributed string, including some custom attributes which I'd like to use to determine which NSTextView that part of the string ends up being displayed in. I don't even know if this is possible with NSLayoutManager.

Are there any good tutorials/example code of using NSLayoutManager for this kind of thing?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 22, 2004, 08:05 AM
 
Originally posted by Brass:
I want users to be able to drag blocks of selected text within an NSTextView to re-arrange the text. Currently, if a user tries to do this, it just changes the selection. How do I get a NSTextView to treat a drag as a "pick up that text and move it" operation, rather than just deselecting that text, and doing another selection operation?
Standard Cocoa behavior is that a user has to hold on text for a short time (~0.25 secs?) before it can be dragged, or else it starts selecting again. Do you mean to modify this behavior?

In a different NSTextView, I have some rather complex layout to do, including what will probably end up as 3 NSTextViews. So I guess I should be using NSLayoutManager. I'm still trying to come to grips with how this works. How do I determine which text ends up in which NSTextView?

Sorry, this is a very broad question, but I'm not yet sure of the best strategy to accomplish my results. As further background, I have an attributed string, including some custom attributes which I'd like to use to determine which NSTextView that part of the string ends up being displayed in. I don't even know if this is possible with NSLayoutManager.
If these views have different text, I don't see why you can't just give them different text storages. What it sounds like you want to do is such a perversion (and I mean that in a neutral way) of how the NSLayoutManager/NSTextView architecture works that it seems like almost any other approach would be easier. NSLayoutManager normally just keeps an array of NSTextContainers, and when it runs out of room in one, it flows the text into the next. It sounds like you want to completely rewire this, in which case you might be better off not using this architecture at all.

At least that's my take on it.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 22, 2004, 05:57 PM
 
Originally posted by Chuckit:
Standard Cocoa behavior is that a user has to hold on text for a short time (~0.25 secs?) before it can be dragged, or else it starts selecting again. Do you mean to modify this behavior?
Hey it works! Why have I never noticed that before? Thanks! Now I just need to add a note to my UI/Doco so the users understand it too.

If these views have different text, I don't see why you can't just give them different text storages. What it sounds like you want to do is such a perversion (and I mean that in a neutral way) of how the NSLayoutManager/NSTextView architecture works that it seems like almost any other approach would be easier. NSLayoutManager normally just keeps an array of NSTextContainers, and when it runs out of room in one, it flows the text into the next. It sounds like you want to completely rewire this, in which case you might be better off not using this architecture at all.

At least that's my take on it.
You're kind of right here. This is mostly because I'm still trying to figure out what I want to achieve (my question was probably a bit premature), and haven't been able to find a good way of describing it without using pictures.

After some more reading of the documentation, I think I've got a better idea...

I think what I want to do is to place two NSTextViews inside of another NSTextView. Ie, use the content of an NSTextView as an NSTextAttachment within another NSTextView.

I guess I could do this by creating an NSFileWrapper for a PDF of the content of the inner NSTextView, and use that NSFileWrapper for the NSTextAttachment within the outer NSTextView.

Does this make sense? Will it work? Is there a better way of doing it? Is it possible to simply place one NSTextView inside another in the same way as you would an NSTextAttachment?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 22, 2004, 10:30 PM
 
I honestly am having a really hard time picturing what exactly you're trying to accomplish (maybe I'm just not very imaginative), so it's hard to tell what the best way to do it is. I guess you could stick a PDF of some text inside a textview if that's all you want to do. It seems a little strange, though....
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 22, 2004, 10:42 PM
 
Originally posted by Chuckit:
I honestly am having a really hard time picturing what exactly you're trying to accomplish (maybe I'm just not very imaginative), so it's hard to tell what the best way to do it is. I guess you could stick a PDF of some text inside a textview if that's all you want to do. It seems a little strange, though....
I have a table of text (in an NSTableView, but easily moved and formatted into an NSTextView), and another block of text in another NSTextView.

I have a third block of text in a third NSTableView.

The user must be able to control which blocks of text go where in their page layout. Including being able to place two blocks of text next to each other. Simply placing the various views inside anothr plain NSView (as I do currently) is not good enough, because the block of text must appear within a "super-block" of text (ie, "in line" with text before, after and between the inner blocks).

If I can place an NSView (NSTableView, NSTextView) inside another NSTextView, then that would be great.

Or if there is a better solution, I'm all ears.
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 25, 2004, 10:48 PM
 
So is there no way to place an NSView in a block of text within an NSTextView (ie, "in-line")?

The only way I can see of doing it, is making an NSTextAttachment from it, but of course I can then I can no longer maintain the attachment in the same way I would the original NSView, as the attachment will be simply whatever was extracted from the view to create the attachment (eg, PDF data).
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 29, 2004, 06:30 PM
 
Originally posted by Brass:
So is there no way to place an NSView in a block of text within an NSTextView (ie, "in-line")?

The only way I can see of doing it, is making an NSTextAttachment from it, but of course I can then I can no longer maintain the attachment in the same way I would the original NSView, as the attachment will be simply whatever was extracted from the view to create the attachment (eg, PDF data).
After doing some more research on this, I may have finally found the information I need. Instead of placing the innner NSTextView/NSTableView within the text of the outer NSTextView, I could place them over the top of it, and use a custom subclass of NSTextContainer for the outer (behind) NSTextView to avoid it placing text in the areas covered by the inner (front) views.

The user wont be editting the text (in any of the views) at this stage so I don't have to worry about that.

Does this sound like a reasonable solution? It's a bit complicated, but I think it should work. I just have to get my head around the "lineFragmentRectForProposedRect:sweepDirection:mo vementDirection:remainingRect:" method, and converting rectangles between the various views coordinate spaces.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 29, 2004, 11:06 PM
 
You'll want to watch out for scrolling and resizing, which would affect the contents of the view differently than sibling views. I don't know if either of these will happen in your program, but they're worth watching out for.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:13 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,