On Wed, 15 Jul 2009 21:23:29 -0700, "K. Darcy Otto" <do...@csusb.edu> said:

>For those who are working on a similar problem, I created new view
>controller object from -printOperationWithSettings:, and that view
>object in turn creates the view that I want to print.  That view
>implements various other subviews, but I was still having problems
>breaking pages at appropriate points.  The subviews, however, can say
>where they should be broken by using -adjustPageHeightNew:.

Bravo. Wherever possible, this is one of the main ways I like to print!
Typically, in this architecture, my printing NSView is created at print time
(because its size depends upon the paper size) and its drawRect contains no
code at all; it's the subviews who are doing the real work. And if they are
built-in views, maybe *their* drawRect contains no code at all. And then way
down at the bottom of the subview hierarchy there are the particular
subviews who implement adjustPageHeightNew:; they are saying, "I don't know
what's going on at a higher level, but whatever you do, don't split me
across pages!"

>In my  
>NSTableView subclass, which was the main element in the view, I
>implemented that method as follows:
>
>-(void)adjustPageHeightNew:(CGFloat *)newBottom top:(CGFloat)top
>bottom:(CGFloat)proposedBottom limit:(CGFloat)bottomLimit
>{
> *newBottom = proposedBottom;
>
> NSInteger indexCount = [deduction lineCount]-1;
> for (NSInteger i = indexCount; i>0; i--)
> {
>  NSRect rowRect = [self frameOfCellAtColumn:[self
>columnWithIdentifier:@"MyColumn"] row:i];
>  float bottomOfRow = rowRect.origin.y + rowRect.size.height;
>  if (bottomOfRow < proposedBottom)
>  {
>   *newBottom = bottomOfRow + 1.0;
>   break;
>  }
> }
>}
>
>So, the for loop just goes through the table and adjusts *newBottom so
>that it breaks at appropriate places.  There is probably some more
>efficient way to check where the page should be broken, but the above
>implementation works just fine.

Well, that looks horrible. :) I've never printed an NSTableView so I find
this approach surprising.

In the first place, as Graham Cox has already said, the loop is repulsive
(okay, he didn't actually go that far); if row height is constant, a simple
division and use of "mod" should tell you the answer instantly. (Put a log
on your loop and I think you'll be amazed how many times it's being called
in the course of printing.)

But in the second place, instead of printing an NSTableView, what I would do
is print the *data*. So each "row" - each piece of data - is an NSView of
some sort. And of course it would implement adjustPageHeightNew. So when the
printing framework is ready to paginate, it would just as *that one row*
whether it is okay to split it across pages, that one row would say "NO!",
and the whole thing would happen instantly. No loop, no table view, no muss,
no fuss.

m.

-- 
matt neuburg, phd = m...@tidbits.com, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to