Page Setup Cocoa vs Carbon

External developers... This forum's for you!

Page Setup Cocoa vs Carbon

Postby sctell » Fri Jul 13, 2012 4:51 am

I have a Cocoa based external which performs displaying and printing of Charts.

I currently have it printing using this code:

Code: Select all
   NSPrintInfo *printInfo;
   NSPrintOperation *printOp;
   printInfo = [NSPrintInfo sharedPrintInfo];
   [printInfo setTopMargin:0.0];
   [printInfo setBottomMargin:0.0];
   [printInfo setLeftMargin:0.0];
   [printInfo setRightMargin:0.0];
   [printInfo setHorizontalPagination: NSFitPagination];
   [printInfo setVerticalPagination: NSFitPagination];
   [printInfo setVerticallyCentered:NO];
   [printInfo setHorizontallyCentered:YES];
   
   NSPageLayout *pageLayout = [NSPageLayout pageLayout];
   [pageLayout runModalWithPrintInfo:printInfo];
   
   printOp = [NSPrintOperation printOperationWithView:self printInfo:printInfo];
   [printOp setShowPanels:YES];
   [printOp runOperation];


It works fairly well but I want to interface it to SC's Page Setup and it does not seem to work.

when I remove these two lines

NSPageLayout *pageLayout = [NSPageLayout pageLayout];
[pageLayout runModalWithPrintInfo:printInfo];

and rely on SC's pageSetup command NSPrintOperation does not recognise the changes in SC's pageSetup (i.e..) portrait to landscape.

I thought Carbon and Cocoa both used the same printing mechanism.

Perhaps I'm wrong.

Can someone point me in the right direction?

Thanks

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Page Setup Cocoa vs Carbon

Postby sctell » Fri Jul 13, 2012 9:55 am

Hi,

My current solution is to provide the external with it's own page setup command separating it from the print command.

This does work and provides the external with it's own commands:

chartPageSetup

and

printChart

I am still interested to understand why it does not work with SC's own page setup.

Thanks

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Page Setup Cocoa vs Carbon

Postby witness » Sat Jul 14, 2012 3:08 am

sctell wrote:and rely on SC's pageSetup command NSPrintOperation does not recognise the changes in SC's pageSetup (i.e..) portrait to landscape.

I thought Carbon and Cocoa both used the same printing mechanism.


They use the same mechanism to actually talk to the printer, but whether there's any shared code in the UI before that is anyone's guess. Applications that are half Carbon and half Cocoa are not really the most common case, so there are lots of gaps and edge cases and cases of "we didn't expect anyone to ever do that". They probably just save them in different places on disk, and neither knows of the other.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are Everywhere..."
http://www.zathras.de
User avatar
witness
 
Posts: 57
Joined: Thu Jul 17, 2008 2:24 pm

Re: Page Setup Cocoa vs Carbon

Postby sctell » Sat Jul 14, 2012 1:14 pm

witness wrote:They probably just save them in different places on disk, and neither knows of the other.


You are more than likely correct, I will leave my solution as above with separate commands.


Thanks

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Page Setup Cocoa vs Carbon

Postby codegreen » Tue Jul 17, 2012 10:59 am

sctell wrote:when I remove these two lines

NSPageLayout *pageLayout = [NSPageLayout pageLayout];
[pageLayout runModalWithPrintInfo:printInfo];

and rely on SC's pageSetup command NSPrintOperation does not recognise the changes in SC's pageSetup (i.e..) portrait to landscape.

I thought Carbon and Cocoa both used the same printing mechanism.

Perhaps I'm wrong.

Can someone point me in the right direction?

SC and Cocoa are chewing on different copies of the Core Printing session, settings, and page format records.

Once printing has been opened in SC, the main globals block should contain valid PMPrintSession (gp->printSession), PMPrintSettings (gp->printSettings), and PMPageFormat (gp->pageFormat) objects. SC also maintains a vestigial old-style THPrint record (gp->printrec) generated (insofar as possible) from the Core Printing settings for legacy externals that still expect to find one there.

IIRC Cocoa also maintains PMPrintSession and PMPageFormat objects as part of its NSPrintInfo state. If you want to throw up SC's dialogs and then have Cocoa use the specified settings (or vice-versa) you'll need to copy the settings from one to the other.

One way you might be able to do that is by fetching the associated objects from Cocoa and the SC globals block and passing them to PMCopyPageFormat and PMCopyPrintSettings. If Cocoa is your destination then tell it you've fiddled its PMPrintSettings and PMPageFormat objects behind its back using updateFromPMPageFormat and updateFromPMPrintSettings.

It's worth a try anyway...

-Mark
codegreen
 
Posts: 1517
Joined: Mon Jul 14, 2008 11:03 pm


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest

cron