widget/cocoa/nsPrintDialogX.mm

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "mozilla/ArrayUtils.h"
     8 #include "nsPrintDialogX.h"
     9 #include "nsIPrintSettings.h"
    10 #include "nsPrintSettingsX.h"
    11 #include "nsCOMPtr.h"
    12 #include "nsServiceManagerUtils.h"
    13 #include "nsIWebProgressListener.h"
    14 #include "nsIStringBundle.h"
    15 #include "nsIWebBrowserPrint.h"
    16 #include "nsCRT.h"
    18 #import <Cocoa/Cocoa.h>
    19 #include "nsObjCExceptions.h"
    21 using namespace mozilla;
    23 NS_IMPL_ISUPPORTS(nsPrintDialogServiceX, nsIPrintDialogService)
    25 nsPrintDialogServiceX::nsPrintDialogServiceX()
    26 {
    27 }
    29 nsPrintDialogServiceX::~nsPrintDialogServiceX()
    30 {
    31 }
    33 NS_IMETHODIMP
    34 nsPrintDialogServiceX::Init()
    35 {
    36   return NS_OK;
    37 }
    39 NS_IMETHODIMP
    40 nsPrintDialogServiceX::Show(nsIDOMWindow *aParent, nsIPrintSettings *aSettings,
    41                             nsIWebBrowserPrint *aWebBrowserPrint)
    42 {
    43   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
    45   NS_PRECONDITION(aSettings, "aSettings must not be null");
    47   nsRefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aSettings));
    48   if (!settingsX)
    49     return NS_ERROR_FAILURE;
    51   // Set the print job title
    52   char16_t** docTitles;
    53   uint32_t titleCount;
    54   nsresult rv = aWebBrowserPrint->EnumerateDocumentNames(&titleCount, &docTitles);
    55   if (NS_SUCCEEDED(rv) && titleCount > 0) {
    56     CFStringRef cfTitleString = CFStringCreateWithCharacters(NULL, reinterpret_cast<const UniChar*>(docTitles[0]),
    57                                                              NS_strlen(docTitles[0]));
    58     if (cfTitleString) {
    59       ::PMPrintSettingsSetJobName(settingsX->GetPMPrintSettings(), cfTitleString);
    60       CFRelease(cfTitleString);
    61     }
    62     for (int32_t i = titleCount - 1; i >= 0; i--) {
    63       NS_Free(docTitles[i]);
    64     }
    65     NS_Free(docTitles);
    66     docTitles = NULL;
    67     titleCount = 0;
    68   }
    70   NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo();
    72   // Put the print info into the current print operation, since that's where
    73   // [panel runModal] will look for it. We create the view because otherwise
    74   // we'll get unrelated warnings printed to the console.
    75   NSView* tmpView = [[NSView alloc] init];
    76   NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:tmpView printInfo:printInfo];
    77   [NSPrintOperation setCurrentOperation:printOperation];
    79   NSPrintPanel* panel = [NSPrintPanel printPanel];
    80   PrintPanelAccessoryController* viewController =
    81     [[PrintPanelAccessoryController alloc] initWithSettings:aSettings];
    82   [panel addAccessoryController:viewController];
    83   [viewController release];
    85   // Show the dialog.
    86   nsCocoaUtils::PrepareForNativeAppModalDialog();
    87   int button = [panel runModal];
    88   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
    90   settingsX->SetCocoaPrintInfo([[[NSPrintOperation currentOperation] printInfo] copy]);
    91   [NSPrintOperation setCurrentOperation:nil];
    92   [printInfo release];
    93   [tmpView release];
    95   if (button != NSOKButton)
    96     return NS_ERROR_ABORT;
    98   // Export settings.
    99   [viewController exportSettings];
   101   int16_t pageRange;
   102   aSettings->GetPrintRange(&pageRange);
   103   if (pageRange != nsIPrintSettings::kRangeSelection) {
   104     PMPrintSettings nativePrintSettings = settingsX->GetPMPrintSettings();
   105     UInt32 firstPage, lastPage;
   106     OSStatus status = ::PMGetFirstPage(nativePrintSettings, &firstPage);
   107     if (status == noErr) {
   108       status = ::PMGetLastPage(nativePrintSettings, &lastPage);
   109       if (status == noErr && lastPage != UINT32_MAX) {
   110         aSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange);
   111         aSettings->SetStartPageRange(firstPage);
   112         aSettings->SetEndPageRange(lastPage);
   113       }
   114     }
   115   }
   117   return NS_OK;
   119   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
   120 }
   122 NS_IMETHODIMP
   123 nsPrintDialogServiceX::ShowPageSetup(nsIDOMWindow *aParent,
   124                                      nsIPrintSettings *aNSSettings)
   125 {
   126   NS_PRECONDITION(aParent, "aParent must not be null");
   127   NS_PRECONDITION(aNSSettings, "aSettings must not be null");
   128   NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
   130   nsRefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aNSSettings));
   131   if (!settingsX)
   132     return NS_ERROR_FAILURE;
   134   NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo();
   135   NSPageLayout *pageLayout = [NSPageLayout pageLayout];
   136   nsCocoaUtils::PrepareForNativeAppModalDialog();
   137   int button = [pageLayout runModalWithPrintInfo:printInfo];
   138   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
   140   return button == NSOKButton ? NS_OK : NS_ERROR_ABORT;
   141 }
   143 // Accessory view
   145 @interface PrintPanelAccessoryView (Private)
   147 - (NSString*)localizedString:(const char*)aKey;
   149 - (int16_t)chosenFrameSetting;
   151 - (const char*)headerFooterStringForList:(NSPopUpButton*)aList;
   153 - (void)exportHeaderFooterSettings;
   155 - (void)initBundle;
   157 - (NSTextField*)label:(const char*)aLabel
   158             withFrame:(NSRect)aRect
   159             alignment:(NSTextAlignment)aAlignment;
   161 - (void)addLabel:(const char*)aLabel
   162        withFrame:(NSRect)aRect
   163        alignment:(NSTextAlignment)aAlignment;
   165 - (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect;
   167 - (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect;
   169 - (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect;
   171 - (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect
   172                                    selectedItem:(const char16_t*)aCurrentString;
   174 - (void)addOptionsSection;
   176 - (void)addAppearanceSection;
   178 - (void)addFramesSection;
   180 - (void)addHeaderFooterSection;
   182 - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox;
   184 - (NSString*)framesSummaryValue;
   186 - (NSString*)headerSummaryValue;
   188 - (NSString*)footerSummaryValue;
   190 @end
   192 static const char sHeaderFooterTags[][4] =  {"", "&T", "&U", "&D", "&P", "&PT"};
   194 @implementation PrintPanelAccessoryView
   196 // Public methods
   198 - (id)initWithSettings:(nsIPrintSettings*)aSettings
   199 {
   200   [super initWithFrame:NSMakeRect(0, 0, 540, 270)];
   202   mSettings = aSettings;
   203   [self initBundle];
   204   [self addOptionsSection];
   205   [self addAppearanceSection];
   206   [self addFramesSection];
   207   [self addHeaderFooterSection];
   209   return self;
   210 }
   212 - (void)exportSettings
   213 {
   214   mSettings->SetPrintRange([mPrintSelectionOnlyCheckbox state] == NSOnState ?
   215                              (int16_t)nsIPrintSettings::kRangeSelection :
   216                              (int16_t)nsIPrintSettings::kRangeAllPages);
   217   mSettings->SetShrinkToFit([mShrinkToFitCheckbox state] == NSOnState);
   218   mSettings->SetPrintBGColors([mPrintBGColorsCheckbox state] == NSOnState);
   219   mSettings->SetPrintBGImages([mPrintBGImagesCheckbox state] == NSOnState);
   220   mSettings->SetPrintFrameType([self chosenFrameSetting]);
   222   [self exportHeaderFooterSettings];
   223 }
   225 - (void)dealloc
   226 {
   227   NS_IF_RELEASE(mPrintBundle);
   228   [super dealloc];
   229 }
   231 // Localization
   233 - (void)initBundle
   234 {
   235   nsCOMPtr<nsIStringBundleService> bundleSvc = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
   236   bundleSvc->CreateBundle("chrome://global/locale/printdialog.properties", &mPrintBundle);
   237 }
   239 - (NSString*)localizedString:(const char*)aKey
   240 {
   241   if (!mPrintBundle)
   242     return @"";
   244   nsXPIDLString intlString;
   245   mPrintBundle->GetStringFromName(NS_ConvertUTF8toUTF16(aKey).get(), getter_Copies(intlString));
   246   NSMutableString* s = [NSMutableString stringWithUTF8String:NS_ConvertUTF16toUTF8(intlString).get()];
   248   // Remove all underscores (they're used in the GTK dialog for accesskeys).
   249   [s replaceOccurrencesOfString:@"_" withString:@"" options:0 range:NSMakeRange(0, [s length])];
   250   return s;
   251 }
   253 // Widget helpers
   255 - (NSTextField*)label:(const char*)aLabel
   256             withFrame:(NSRect)aRect
   257             alignment:(NSTextAlignment)aAlignment
   258 {
   259   NSTextField* label = [[[NSTextField alloc] initWithFrame:aRect] autorelease];
   260   [label setStringValue:[self localizedString:aLabel]];
   261   [label setEditable:NO];
   262   [label setSelectable:NO];
   263   [label setBezeled:NO];
   264   [label setBordered:NO];
   265   [label setDrawsBackground:NO];
   266   [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
   267   [label setAlignment:aAlignment];
   268   return label;
   269 }
   271 - (void)addLabel:(const char*)aLabel
   272        withFrame:(NSRect)aRect
   273        alignment:(NSTextAlignment)aAlignment
   274 {
   275   NSTextField* label = [self label:aLabel withFrame:aRect alignment:aAlignment];
   276   [self addSubview:label];
   277 }
   279 - (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect
   280 {
   281   [self addLabel:aLabel withFrame:aRect alignment:NSRightTextAlignment];
   282 }
   284 - (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect
   285 {
   286   [self addLabel:aLabel withFrame:aRect alignment:NSCenterTextAlignment];
   287 }
   289 - (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect
   290 {
   291   aRect.origin.y += 4.0f;
   292   NSButton* checkbox = [[[NSButton alloc] initWithFrame:aRect] autorelease];
   293   [checkbox setButtonType:NSSwitchButton];
   294   [checkbox setTitle:[self localizedString:aLabel]];
   295   [checkbox setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
   296   [checkbox sizeToFit];
   297   return checkbox;
   298 }
   300 - (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect
   301                                    selectedItem:(const char16_t*)aCurrentString
   302 {
   303   NSPopUpButton* list = [[[NSPopUpButton alloc] initWithFrame:aRect pullsDown:NO] autorelease];
   304   [list setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
   305   [[list cell] setControlSize:NSSmallControlSize];
   306   NSArray* items =
   307     [NSArray arrayWithObjects:[self localizedString:"headerFooterBlank"],
   308                               [self localizedString:"headerFooterTitle"],
   309                               [self localizedString:"headerFooterURL"],
   310                               [self localizedString:"headerFooterDate"],
   311                               [self localizedString:"headerFooterPage"],
   312                               [self localizedString:"headerFooterPageTotal"],
   313                               nil];
   314   [list addItemsWithTitles:items];
   316   NS_ConvertUTF16toUTF8 currentStringUTF8(aCurrentString);
   317   for (unsigned int i = 0; i < ArrayLength(sHeaderFooterTags); i++) {
   318     if (!strcmp(currentStringUTF8.get(), sHeaderFooterTags[i])) {
   319       [list selectItemAtIndex:i];
   320       break;
   321     }
   322   }
   324   return list;
   325 }
   327 // Build sections
   329 - (void)addOptionsSection
   330 {
   331   // Title
   332   [self addLabel:"optionsTitleMac" withFrame:NSMakeRect(0, 240, 151, 22)];
   334   // "Print Selection Only"
   335   mPrintSelectionOnlyCheckbox = [self checkboxWithLabel:"selectionOnly"
   336                                                andFrame:NSMakeRect(156, 240, 0, 0)];
   338   bool canPrintSelection;
   339   mSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB,
   340                              &canPrintSelection);
   341   [mPrintSelectionOnlyCheckbox setEnabled:canPrintSelection];
   343   int16_t printRange;
   344   mSettings->GetPrintRange(&printRange);
   345   if (printRange == nsIPrintSettings::kRangeSelection) {
   346     [mPrintSelectionOnlyCheckbox setState:NSOnState];
   347   }
   349   [self addSubview:mPrintSelectionOnlyCheckbox];
   351   // "Shrink To Fit"
   352   mShrinkToFitCheckbox = [self checkboxWithLabel:"shrinkToFit"
   353                                         andFrame:NSMakeRect(156, 218, 0, 0)];
   355   bool shrinkToFit;
   356   mSettings->GetShrinkToFit(&shrinkToFit);
   357   [mShrinkToFitCheckbox setState:(shrinkToFit ? NSOnState : NSOffState)];
   359   [self addSubview:mShrinkToFitCheckbox];
   360 }
   362 - (void)addAppearanceSection
   363 {
   364   // Title
   365   [self addLabel:"appearanceTitleMac" withFrame:NSMakeRect(0, 188, 151, 22)];
   367   // "Print Background Colors"
   368   mPrintBGColorsCheckbox = [self checkboxWithLabel:"printBGColors"
   369                                           andFrame:NSMakeRect(156, 188, 0, 0)];
   371   bool geckoBool;
   372   mSettings->GetPrintBGColors(&geckoBool);
   373   [mPrintBGColorsCheckbox setState:(geckoBool ? NSOnState : NSOffState)];
   375   [self addSubview:mPrintBGColorsCheckbox];
   377   // "Print Background Images"
   378   mPrintBGImagesCheckbox = [self checkboxWithLabel:"printBGImages"
   379                                           andFrame:NSMakeRect(156, 166, 0, 0)];
   381   mSettings->GetPrintBGImages(&geckoBool);
   382   [mPrintBGImagesCheckbox setState:(geckoBool ? NSOnState : NSOffState)];
   384   [self addSubview:mPrintBGImagesCheckbox];
   385 }
   387 - (void)addFramesSection
   388 {
   389   // Title
   390   [self addLabel:"framesTitleMac" withFrame:NSMakeRect(0, 124, 151, 22)];
   392   // Radio matrix
   393   NSButtonCell *radio = [[NSButtonCell alloc] init];
   394   [radio setButtonType:NSRadioButton];
   395   [radio setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
   396   NSMatrix *matrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(156, 81, 400, 66)
   397                                                 mode:NSRadioModeMatrix
   398                                            prototype:(NSCell*)radio
   399                                         numberOfRows:3
   400                                      numberOfColumns:1];
   401   [radio release];
   402   [matrix setCellSize:NSMakeSize(400, 21)];
   403   [self addSubview:matrix];
   404   [matrix release];
   405   NSArray *cellArray = [matrix cells];
   406   mAsLaidOutRadio = [cellArray objectAtIndex:0];
   407   mSelectedFrameRadio = [cellArray objectAtIndex:1];
   408   mSeparateFramesRadio = [cellArray objectAtIndex:2];
   409   [mAsLaidOutRadio setTitle:[self localizedString:"asLaidOut"]];
   410   [mSelectedFrameRadio setTitle:[self localizedString:"selectedFrame"]];
   411   [mSeparateFramesRadio setTitle:[self localizedString:"separateFrames"]];
   413   // Radio enabled state
   414   int16_t frameUIFlag;
   415   mSettings->GetHowToEnableFrameUI(&frameUIFlag);
   416   if (frameUIFlag == nsIPrintSettings::kFrameEnableNone) {
   417     [mAsLaidOutRadio setEnabled:NO];
   418     [mSelectedFrameRadio setEnabled:NO];
   419     [mSeparateFramesRadio setEnabled:NO];
   420   } else if (frameUIFlag == nsIPrintSettings::kFrameEnableAsIsAndEach) {
   421     [mSelectedFrameRadio setEnabled:NO];
   422   }
   424   // Radio values
   425   int16_t printFrameType;
   426   mSettings->GetPrintFrameType(&printFrameType);
   427   switch (printFrameType) {
   428     case nsIPrintSettings::kFramesAsIs:
   429       [mAsLaidOutRadio setState:NSOnState];
   430       break;
   431     case nsIPrintSettings::kSelectedFrame:
   432       [mSelectedFrameRadio setState:NSOnState];
   433       break;
   434     case nsIPrintSettings::kEachFrameSep:
   435       [mSeparateFramesRadio setState:NSOnState];
   436       break;
   437   }
   438 }
   440 - (void)addHeaderFooterSection
   441 {
   442   // Labels
   443   [self addLabel:"pageHeadersTitleMac" withFrame:NSMakeRect(0, 44, 151, 22)];
   444   [self addLabel:"pageFootersTitleMac" withFrame:NSMakeRect(0, 0, 151, 22)];
   445   [self addCenteredLabel:"left" withFrame:NSMakeRect(156, 22, 100, 22)];
   446   [self addCenteredLabel:"center" withFrame:NSMakeRect(256, 22, 100, 22)];
   447   [self addCenteredLabel:"right" withFrame:NSMakeRect(356, 22, 100, 22)];
   449   // Lists
   450   nsXPIDLString sel;
   452   mSettings->GetHeaderStrLeft(getter_Copies(sel));
   453   mHeaderLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 44, 100, 22)
   454                                            selectedItem:sel];
   455   [self addSubview:mHeaderLeftList];
   457   mSettings->GetHeaderStrCenter(getter_Copies(sel));
   458   mHeaderCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 44, 100, 22)
   459                                              selectedItem:sel];
   460   [self addSubview:mHeaderCenterList];
   462   mSettings->GetHeaderStrRight(getter_Copies(sel));
   463   mHeaderRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 44, 100, 22)
   464                                             selectedItem:sel];
   465   [self addSubview:mHeaderRightList];
   467   mSettings->GetFooterStrLeft(getter_Copies(sel));
   468   mFooterLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 0, 100, 22)
   469                                            selectedItem:sel];
   470   [self addSubview:mFooterLeftList];
   472   mSettings->GetFooterStrCenter(getter_Copies(sel));
   473   mFooterCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 0, 100, 22)
   474                                              selectedItem:sel];
   475   [self addSubview:mFooterCenterList];
   477   mSettings->GetFooterStrRight(getter_Copies(sel));
   478   mFooterRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 0, 100, 22)
   479                                             selectedItem:sel];
   480   [self addSubview:mFooterRightList];
   481 }
   483 // Export settings
   485 - (int16_t)chosenFrameSetting
   486 {
   487   if ([mAsLaidOutRadio state] == NSOnState)
   488     return nsIPrintSettings::kFramesAsIs;
   489   if ([mSelectedFrameRadio state] == NSOnState)
   490     return nsIPrintSettings::kSelectedFrame;
   491   if ([mSeparateFramesRadio state] == NSOnState)
   492     return nsIPrintSettings::kEachFrameSep;
   493   return nsIPrintSettings::kNoFrames;
   494 }
   496 - (const char*)headerFooterStringForList:(NSPopUpButton*)aList
   497 {
   498   NSInteger index = [aList indexOfSelectedItem];
   499   NS_ASSERTION(index < NSInteger(ArrayLength(sHeaderFooterTags)), "Index of dropdown is higher than expected!");
   500   return sHeaderFooterTags[index];
   501 }
   503 - (void)exportHeaderFooterSettings
   504 {
   505   const char* headerFooterStr;
   506   headerFooterStr = [self headerFooterStringForList:mHeaderLeftList];
   507   mSettings->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get());
   509   headerFooterStr = [self headerFooterStringForList:mHeaderCenterList];
   510   mSettings->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get());
   512   headerFooterStr = [self headerFooterStringForList:mHeaderRightList];
   513   mSettings->SetHeaderStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get());
   515   headerFooterStr = [self headerFooterStringForList:mFooterLeftList];
   516   mSettings->SetFooterStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get());
   518   headerFooterStr = [self headerFooterStringForList:mFooterCenterList];
   519   mSettings->SetFooterStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get());
   521   headerFooterStr = [self headerFooterStringForList:mFooterRightList];
   522   mSettings->SetFooterStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get());
   523 }
   525 // Summary
   527 - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox
   528 {
   529   if (![aCheckbox isEnabled])
   530     return [self localizedString:"summaryNAValue"];
   532   return [aCheckbox state] == NSOnState ?
   533     [self localizedString:"summaryOnValue"] :
   534     [self localizedString:"summaryOffValue"];
   535 }
   537 - (NSString*)framesSummaryValue
   538 {
   539   switch([self chosenFrameSetting]) {
   540     case nsIPrintSettings::kFramesAsIs:
   541       return [self localizedString:"asLaidOut"];
   542     case nsIPrintSettings::kSelectedFrame:
   543       return [self localizedString:"selectedFrame"];
   544     case nsIPrintSettings::kEachFrameSep:
   545       return [self localizedString:"separateFrames"];
   546   }
   547   return [self localizedString:"summaryNAValue"];
   548 }
   550 - (NSString*)headerSummaryValue
   551 {
   552   return [[mHeaderLeftList titleOfSelectedItem] stringByAppendingString:
   553     [@", " stringByAppendingString:
   554       [[mHeaderCenterList titleOfSelectedItem] stringByAppendingString:
   555         [@", " stringByAppendingString:
   556           [mHeaderRightList titleOfSelectedItem]]]]];
   557 }
   559 - (NSString*)footerSummaryValue
   560 {
   561   return [[mFooterLeftList titleOfSelectedItem] stringByAppendingString:
   562     [@", " stringByAppendingString:
   563       [[mFooterCenterList titleOfSelectedItem] stringByAppendingString:
   564         [@", " stringByAppendingString:
   565           [mFooterRightList titleOfSelectedItem]]]]];
   566 }
   568 - (NSArray*)localizedSummaryItems
   569 {
   570   return [NSArray arrayWithObjects:
   571     [NSDictionary dictionaryWithObjectsAndKeys:
   572       [self localizedString:"summaryFramesTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   573       [self framesSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   574     [NSDictionary dictionaryWithObjectsAndKeys:
   575       [self localizedString:"summarySelectionOnlyTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   576       [self summaryValueForCheckbox:mPrintSelectionOnlyCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   577     [NSDictionary dictionaryWithObjectsAndKeys:
   578       [self localizedString:"summaryShrinkToFitTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   579       [self summaryValueForCheckbox:mShrinkToFitCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   580     [NSDictionary dictionaryWithObjectsAndKeys:
   581       [self localizedString:"summaryPrintBGColorsTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   582       [self summaryValueForCheckbox:mPrintBGColorsCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   583     [NSDictionary dictionaryWithObjectsAndKeys:
   584       [self localizedString:"summaryPrintBGImagesTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   585       [self summaryValueForCheckbox:mPrintBGImagesCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   586     [NSDictionary dictionaryWithObjectsAndKeys:
   587       [self localizedString:"summaryHeaderTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   588       [self headerSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   589     [NSDictionary dictionaryWithObjectsAndKeys:
   590       [self localizedString:"summaryFooterTitle"], NSPrintPanelAccessorySummaryItemNameKey,
   591       [self footerSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
   592     nil];
   593 }
   595 @end
   597 // Accessory controller
   599 @implementation PrintPanelAccessoryController
   601 - (id)initWithSettings:(nsIPrintSettings*)aSettings
   602 {
   603   [super initWithNibName:nil bundle:nil];
   605   NSView* accView = [[PrintPanelAccessoryView alloc] initWithSettings:aSettings];
   606   [self setView:accView];
   607   [accView release];
   608   return self;
   609 }
   611 - (void)exportSettings
   612 {
   613   return [(PrintPanelAccessoryView*)[self view] exportSettings];
   614 }
   616 - (NSArray *)localizedSummaryItems
   617 {
   618   return [(PrintPanelAccessoryView*)[self view] localizedSummaryItems];
   619 }
   621 @end

mercurial