 |
 |
Printing many similar NSViews? No Copy.
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
I'm trying to create a single NSView (from which to print) which includes many subviews, all of which are similar in structure, and only vary in the data that they actually contain. Ie, each subview represents one record in a database, and I want to be able to create a view which contains many records so that I can print several records per page.
The views are NOT tabular, so a table is not appropriate in this case.
What I've done is created a template view which contains all the elements that I want for each record. I'd like to be able to create a copy of this template view for each record and use the addSubview method to add these record views to the printing NSView.
However, I cannot find any easy way to do this.
The closest way I've found so far is to manually create each item for every record programatically, and that is painful. There's got to be a better way.
Can anyone offer suggestions?
Thanks in advance.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Wow, looks like I've stumped everyone with that question. Am I asking the impossible, or do people just not understand the question? 
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status:
Offline
|
|
Why use a separate subview for each record, isn't it easier to have each record draw itself into the same view? Try looking at the Sketch source code that shipped with the Dev tools (the sources are nicely commented). I've actually written a simple application for visualizing SQL database tables. I came pretty far by just making some straight forward modifications to the Sketch source. I just made my model objects (the database tables) subclass from SKTGraphic (I think that was the name of the class) and overrode a few methods that contained the actual drawing.
Perhaps none of this is directly applicable to your application (I'm not 100% sure I understood how your view should look like), but if nothing else you could look at the design how multiple model objects are drawn into the same view. Hope this helps
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by tobli:
<strong>Why use a separate subview for each record, isn't it easier to have each record draw itself into the same view? Try looking at the Sketch source code that shipped with the Dev tools (the sources are nicely commented). I've actually written a simple application for visualizing SQL database tables. I came pretty far by just making some straight forward modifications to the Sketch source. I just made my model objects (the database tables) subclass from SKTGraphic (I think that was the name of the class) and overrode a few methods that contained the actual drawing.
Perhaps none of this is directly applicable to your application (I'm not 100% sure I understood how your view should look like), but if nothing else you could look at the design how multiple model objects are drawn into the same view. Hope this helps</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Tobli,
Thanks for this suggestion. I don't have the Sketch (etc) examples here with me at the moment, but I think your suggestion is exactly what I need. I'll look into it when I get home. Thanks heaps!
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Nope, unfortunately, the Sketch example app didn't help me much. All that does is draw unique beziers.
What I want to do is draw many almost identical NSView objects, without having to specify each of them programatically each time (eg, NSTextFields, NSText, NSBox).
I can define each record object to draw its many view objects into a view, but that is very tedious, and makes things difficult to maintain.
I'd like to be able to define each record object such that it could copy each item from a template view and add them to the view. Then I could easily change their size and position in Interface Builder (which would be much easier than making changes if I was to place and size them programatically, and would allow me to use "Aqua Guidelines").
Drawing a bezier like in Sketch is very straightforward (it draws itself), but my records need to place and resize all of the NSView subclasses they'll need manually unless I can figure out a way to make it easier. Eg, for each object in a record , such as a NSText, the record object would have to do an addSubview, and setRect at a bare minumum, however, determining the required size and position of the frame in this case is not so trivial, and would be a headache to change manually if I wanted to redesign the layout.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
hmmm... I don't think I'm explaining myself very well. Let me try to simplify it...
I would like to be able to create a layout in Interface Builder ONCE that I can have appear in an NSView MANY TIMES (each occurance having data from a different record, but the same layout of objects).
Each object in the layout is a subclass of NSView (eg, NSText, NSBox).
What I was thinking of doing is creating an NSView in Interface Builder once, and then copying many times (once for each record), but it seems that NSView doesn't do copying.
Do I have to subclass NSView to make my own version that will allow copying, or is there some built in way of doing this already.
Or am I completely on the wrong track (most likely). If so, how do I achieve the ability to create a layout of NSView sublcasses in interface builder, and use that layout of objects multiple times within a single NSView?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
I think that what you want to do is have your view in a nib; multiple instances of it can then be loaded from that nib.
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Gul Banana:
<strong>I think that what you want to do is have your view in a nib; multiple instances of it can then be loaded from that nib.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Of course! That makes sense. I've been trying to do it all the one nib file (MainMenu.nib). So if I create a separate nib file for the record layout, then get each record to load a copy of the nib, then each record can add it's view as a subview of the print view in the main nib? I'll have to go and look up the doco again (I'm new to this). Hopefully I can figure it out from here (fingers crossed).
<small>[ 07-18-2002, 11:14 PM: Message edited by: Brass ]</small>
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
You can make a copy of any NSView using NSArchiver. You will lose all targets, delegates, datasources etc. that point anywhere outside the view (for example to a controller). So, if you need to have references to a bunch of textfields that you want to populate, this isn't the method for you (using a controller class with outlets and loading a nib that has only your view in it would be the better approach) but if you just need to copy a view, this should work:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> NSData *data = [NSArchiver archivedDataWithRootObject:theView];
NSView *newView = [NSUnarchiver unarchiveObjectWithData:data];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Okay, I've got it all working quite well now, using a second nib file. Each record just loads the nib when it needs to draw itself.
However, there is still one problem. I cannot seem to get pagination working. I've now got a single NSView consisting of many subviews tiled vertically (with a small gap between each for aesthetics). The subviews are each of a subclass of NSView. All the subclass does is override the basic set of 4 pagination methods. If the page bottom occurs anywhere in the view, it is supposed to push the page bottom up to the top of the view. But it ain't working. It doesn't appear to be doing anything.
Using debugging, and loggin, I've determined that the subclass' pagination methods are being called and they are returning (by reference) the correct new bottom. But it doesn't seem to be used by the superview.
Any ideas?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|