michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/ArrayUtils.h" michael@0: michael@0: #include "nsPrintDialogX.h" michael@0: #include "nsIPrintSettings.h" michael@0: #include "nsPrintSettingsX.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsIWebProgressListener.h" michael@0: #include "nsIStringBundle.h" michael@0: #include "nsIWebBrowserPrint.h" michael@0: #include "nsCRT.h" michael@0: michael@0: #import michael@0: #include "nsObjCExceptions.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: NS_IMPL_ISUPPORTS(nsPrintDialogServiceX, nsIPrintDialogService) michael@0: michael@0: nsPrintDialogServiceX::nsPrintDialogServiceX() michael@0: { michael@0: } michael@0: michael@0: nsPrintDialogServiceX::~nsPrintDialogServiceX() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsPrintDialogServiceX::Init() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsPrintDialogServiceX::Show(nsIDOMWindow *aParent, nsIPrintSettings *aSettings, michael@0: nsIWebBrowserPrint *aWebBrowserPrint) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: NS_PRECONDITION(aSettings, "aSettings must not be null"); michael@0: michael@0: nsRefPtr settingsX(do_QueryObject(aSettings)); michael@0: if (!settingsX) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: // Set the print job title michael@0: char16_t** docTitles; michael@0: uint32_t titleCount; michael@0: nsresult rv = aWebBrowserPrint->EnumerateDocumentNames(&titleCount, &docTitles); michael@0: if (NS_SUCCEEDED(rv) && titleCount > 0) { michael@0: CFStringRef cfTitleString = CFStringCreateWithCharacters(NULL, reinterpret_cast(docTitles[0]), michael@0: NS_strlen(docTitles[0])); michael@0: if (cfTitleString) { michael@0: ::PMPrintSettingsSetJobName(settingsX->GetPMPrintSettings(), cfTitleString); michael@0: CFRelease(cfTitleString); michael@0: } michael@0: for (int32_t i = titleCount - 1; i >= 0; i--) { michael@0: NS_Free(docTitles[i]); michael@0: } michael@0: NS_Free(docTitles); michael@0: docTitles = NULL; michael@0: titleCount = 0; michael@0: } michael@0: michael@0: NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo(); michael@0: michael@0: // Put the print info into the current print operation, since that's where michael@0: // [panel runModal] will look for it. We create the view because otherwise michael@0: // we'll get unrelated warnings printed to the console. michael@0: NSView* tmpView = [[NSView alloc] init]; michael@0: NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:tmpView printInfo:printInfo]; michael@0: [NSPrintOperation setCurrentOperation:printOperation]; michael@0: michael@0: NSPrintPanel* panel = [NSPrintPanel printPanel]; michael@0: PrintPanelAccessoryController* viewController = michael@0: [[PrintPanelAccessoryController alloc] initWithSettings:aSettings]; michael@0: [panel addAccessoryController:viewController]; michael@0: [viewController release]; michael@0: michael@0: // Show the dialog. michael@0: nsCocoaUtils::PrepareForNativeAppModalDialog(); michael@0: int button = [panel runModal]; michael@0: nsCocoaUtils::CleanUpAfterNativeAppModalDialog(); michael@0: michael@0: settingsX->SetCocoaPrintInfo([[[NSPrintOperation currentOperation] printInfo] copy]); michael@0: [NSPrintOperation setCurrentOperation:nil]; michael@0: [printInfo release]; michael@0: [tmpView release]; michael@0: michael@0: if (button != NSOKButton) michael@0: return NS_ERROR_ABORT; michael@0: michael@0: // Export settings. michael@0: [viewController exportSettings]; michael@0: michael@0: int16_t pageRange; michael@0: aSettings->GetPrintRange(&pageRange); michael@0: if (pageRange != nsIPrintSettings::kRangeSelection) { michael@0: PMPrintSettings nativePrintSettings = settingsX->GetPMPrintSettings(); michael@0: UInt32 firstPage, lastPage; michael@0: OSStatus status = ::PMGetFirstPage(nativePrintSettings, &firstPage); michael@0: if (status == noErr) { michael@0: status = ::PMGetLastPage(nativePrintSettings, &lastPage); michael@0: if (status == noErr && lastPage != UINT32_MAX) { michael@0: aSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange); michael@0: aSettings->SetStartPageRange(firstPage); michael@0: aSettings->SetEndPageRange(lastPage); michael@0: } michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsPrintDialogServiceX::ShowPageSetup(nsIDOMWindow *aParent, michael@0: nsIPrintSettings *aNSSettings) michael@0: { michael@0: NS_PRECONDITION(aParent, "aParent must not be null"); michael@0: NS_PRECONDITION(aNSSettings, "aSettings must not be null"); michael@0: NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE); michael@0: michael@0: nsRefPtr settingsX(do_QueryObject(aNSSettings)); michael@0: if (!settingsX) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo(); michael@0: NSPageLayout *pageLayout = [NSPageLayout pageLayout]; michael@0: nsCocoaUtils::PrepareForNativeAppModalDialog(); michael@0: int button = [pageLayout runModalWithPrintInfo:printInfo]; michael@0: nsCocoaUtils::CleanUpAfterNativeAppModalDialog(); michael@0: michael@0: return button == NSOKButton ? NS_OK : NS_ERROR_ABORT; michael@0: } michael@0: michael@0: // Accessory view michael@0: michael@0: @interface PrintPanelAccessoryView (Private) michael@0: michael@0: - (NSString*)localizedString:(const char*)aKey; michael@0: michael@0: - (int16_t)chosenFrameSetting; michael@0: michael@0: - (const char*)headerFooterStringForList:(NSPopUpButton*)aList; michael@0: michael@0: - (void)exportHeaderFooterSettings; michael@0: michael@0: - (void)initBundle; michael@0: michael@0: - (NSTextField*)label:(const char*)aLabel michael@0: withFrame:(NSRect)aRect michael@0: alignment:(NSTextAlignment)aAlignment; michael@0: michael@0: - (void)addLabel:(const char*)aLabel michael@0: withFrame:(NSRect)aRect michael@0: alignment:(NSTextAlignment)aAlignment; michael@0: michael@0: - (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect; michael@0: michael@0: - (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect; michael@0: michael@0: - (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect; michael@0: michael@0: - (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect michael@0: selectedItem:(const char16_t*)aCurrentString; michael@0: michael@0: - (void)addOptionsSection; michael@0: michael@0: - (void)addAppearanceSection; michael@0: michael@0: - (void)addFramesSection; michael@0: michael@0: - (void)addHeaderFooterSection; michael@0: michael@0: - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox; michael@0: michael@0: - (NSString*)framesSummaryValue; michael@0: michael@0: - (NSString*)headerSummaryValue; michael@0: michael@0: - (NSString*)footerSummaryValue; michael@0: michael@0: @end michael@0: michael@0: static const char sHeaderFooterTags[][4] = {"", "&T", "&U", "&D", "&P", "&PT"}; michael@0: michael@0: @implementation PrintPanelAccessoryView michael@0: michael@0: // Public methods michael@0: michael@0: - (id)initWithSettings:(nsIPrintSettings*)aSettings michael@0: { michael@0: [super initWithFrame:NSMakeRect(0, 0, 540, 270)]; michael@0: michael@0: mSettings = aSettings; michael@0: [self initBundle]; michael@0: [self addOptionsSection]; michael@0: [self addAppearanceSection]; michael@0: [self addFramesSection]; michael@0: [self addHeaderFooterSection]; michael@0: michael@0: return self; michael@0: } michael@0: michael@0: - (void)exportSettings michael@0: { michael@0: mSettings->SetPrintRange([mPrintSelectionOnlyCheckbox state] == NSOnState ? michael@0: (int16_t)nsIPrintSettings::kRangeSelection : michael@0: (int16_t)nsIPrintSettings::kRangeAllPages); michael@0: mSettings->SetShrinkToFit([mShrinkToFitCheckbox state] == NSOnState); michael@0: mSettings->SetPrintBGColors([mPrintBGColorsCheckbox state] == NSOnState); michael@0: mSettings->SetPrintBGImages([mPrintBGImagesCheckbox state] == NSOnState); michael@0: mSettings->SetPrintFrameType([self chosenFrameSetting]); michael@0: michael@0: [self exportHeaderFooterSettings]; michael@0: } michael@0: michael@0: - (void)dealloc michael@0: { michael@0: NS_IF_RELEASE(mPrintBundle); michael@0: [super dealloc]; michael@0: } michael@0: michael@0: // Localization michael@0: michael@0: - (void)initBundle michael@0: { michael@0: nsCOMPtr bundleSvc = do_GetService(NS_STRINGBUNDLE_CONTRACTID); michael@0: bundleSvc->CreateBundle("chrome://global/locale/printdialog.properties", &mPrintBundle); michael@0: } michael@0: michael@0: - (NSString*)localizedString:(const char*)aKey michael@0: { michael@0: if (!mPrintBundle) michael@0: return @""; michael@0: michael@0: nsXPIDLString intlString; michael@0: mPrintBundle->GetStringFromName(NS_ConvertUTF8toUTF16(aKey).get(), getter_Copies(intlString)); michael@0: NSMutableString* s = [NSMutableString stringWithUTF8String:NS_ConvertUTF16toUTF8(intlString).get()]; michael@0: michael@0: // Remove all underscores (they're used in the GTK dialog for accesskeys). michael@0: [s replaceOccurrencesOfString:@"_" withString:@"" options:0 range:NSMakeRange(0, [s length])]; michael@0: return s; michael@0: } michael@0: michael@0: // Widget helpers michael@0: michael@0: - (NSTextField*)label:(const char*)aLabel michael@0: withFrame:(NSRect)aRect michael@0: alignment:(NSTextAlignment)aAlignment michael@0: { michael@0: NSTextField* label = [[[NSTextField alloc] initWithFrame:aRect] autorelease]; michael@0: [label setStringValue:[self localizedString:aLabel]]; michael@0: [label setEditable:NO]; michael@0: [label setSelectable:NO]; michael@0: [label setBezeled:NO]; michael@0: [label setBordered:NO]; michael@0: [label setDrawsBackground:NO]; michael@0: [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; michael@0: [label setAlignment:aAlignment]; michael@0: return label; michael@0: } michael@0: michael@0: - (void)addLabel:(const char*)aLabel michael@0: withFrame:(NSRect)aRect michael@0: alignment:(NSTextAlignment)aAlignment michael@0: { michael@0: NSTextField* label = [self label:aLabel withFrame:aRect alignment:aAlignment]; michael@0: [self addSubview:label]; michael@0: } michael@0: michael@0: - (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect michael@0: { michael@0: [self addLabel:aLabel withFrame:aRect alignment:NSRightTextAlignment]; michael@0: } michael@0: michael@0: - (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect michael@0: { michael@0: [self addLabel:aLabel withFrame:aRect alignment:NSCenterTextAlignment]; michael@0: } michael@0: michael@0: - (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect michael@0: { michael@0: aRect.origin.y += 4.0f; michael@0: NSButton* checkbox = [[[NSButton alloc] initWithFrame:aRect] autorelease]; michael@0: [checkbox setButtonType:NSSwitchButton]; michael@0: [checkbox setTitle:[self localizedString:aLabel]]; michael@0: [checkbox setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; michael@0: [checkbox sizeToFit]; michael@0: return checkbox; michael@0: } michael@0: michael@0: - (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect michael@0: selectedItem:(const char16_t*)aCurrentString michael@0: { michael@0: NSPopUpButton* list = [[[NSPopUpButton alloc] initWithFrame:aRect pullsDown:NO] autorelease]; michael@0: [list setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; michael@0: [[list cell] setControlSize:NSSmallControlSize]; michael@0: NSArray* items = michael@0: [NSArray arrayWithObjects:[self localizedString:"headerFooterBlank"], michael@0: [self localizedString:"headerFooterTitle"], michael@0: [self localizedString:"headerFooterURL"], michael@0: [self localizedString:"headerFooterDate"], michael@0: [self localizedString:"headerFooterPage"], michael@0: [self localizedString:"headerFooterPageTotal"], michael@0: nil]; michael@0: [list addItemsWithTitles:items]; michael@0: michael@0: NS_ConvertUTF16toUTF8 currentStringUTF8(aCurrentString); michael@0: for (unsigned int i = 0; i < ArrayLength(sHeaderFooterTags); i++) { michael@0: if (!strcmp(currentStringUTF8.get(), sHeaderFooterTags[i])) { michael@0: [list selectItemAtIndex:i]; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: return list; michael@0: } michael@0: michael@0: // Build sections michael@0: michael@0: - (void)addOptionsSection michael@0: { michael@0: // Title michael@0: [self addLabel:"optionsTitleMac" withFrame:NSMakeRect(0, 240, 151, 22)]; michael@0: michael@0: // "Print Selection Only" michael@0: mPrintSelectionOnlyCheckbox = [self checkboxWithLabel:"selectionOnly" michael@0: andFrame:NSMakeRect(156, 240, 0, 0)]; michael@0: michael@0: bool canPrintSelection; michael@0: mSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, michael@0: &canPrintSelection); michael@0: [mPrintSelectionOnlyCheckbox setEnabled:canPrintSelection]; michael@0: michael@0: int16_t printRange; michael@0: mSettings->GetPrintRange(&printRange); michael@0: if (printRange == nsIPrintSettings::kRangeSelection) { michael@0: [mPrintSelectionOnlyCheckbox setState:NSOnState]; michael@0: } michael@0: michael@0: [self addSubview:mPrintSelectionOnlyCheckbox]; michael@0: michael@0: // "Shrink To Fit" michael@0: mShrinkToFitCheckbox = [self checkboxWithLabel:"shrinkToFit" michael@0: andFrame:NSMakeRect(156, 218, 0, 0)]; michael@0: michael@0: bool shrinkToFit; michael@0: mSettings->GetShrinkToFit(&shrinkToFit); michael@0: [mShrinkToFitCheckbox setState:(shrinkToFit ? NSOnState : NSOffState)]; michael@0: michael@0: [self addSubview:mShrinkToFitCheckbox]; michael@0: } michael@0: michael@0: - (void)addAppearanceSection michael@0: { michael@0: // Title michael@0: [self addLabel:"appearanceTitleMac" withFrame:NSMakeRect(0, 188, 151, 22)]; michael@0: michael@0: // "Print Background Colors" michael@0: mPrintBGColorsCheckbox = [self checkboxWithLabel:"printBGColors" michael@0: andFrame:NSMakeRect(156, 188, 0, 0)]; michael@0: michael@0: bool geckoBool; michael@0: mSettings->GetPrintBGColors(&geckoBool); michael@0: [mPrintBGColorsCheckbox setState:(geckoBool ? NSOnState : NSOffState)]; michael@0: michael@0: [self addSubview:mPrintBGColorsCheckbox]; michael@0: michael@0: // "Print Background Images" michael@0: mPrintBGImagesCheckbox = [self checkboxWithLabel:"printBGImages" michael@0: andFrame:NSMakeRect(156, 166, 0, 0)]; michael@0: michael@0: mSettings->GetPrintBGImages(&geckoBool); michael@0: [mPrintBGImagesCheckbox setState:(geckoBool ? NSOnState : NSOffState)]; michael@0: michael@0: [self addSubview:mPrintBGImagesCheckbox]; michael@0: } michael@0: michael@0: - (void)addFramesSection michael@0: { michael@0: // Title michael@0: [self addLabel:"framesTitleMac" withFrame:NSMakeRect(0, 124, 151, 22)]; michael@0: michael@0: // Radio matrix michael@0: NSButtonCell *radio = [[NSButtonCell alloc] init]; michael@0: [radio setButtonType:NSRadioButton]; michael@0: [radio setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; michael@0: NSMatrix *matrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(156, 81, 400, 66) michael@0: mode:NSRadioModeMatrix michael@0: prototype:(NSCell*)radio michael@0: numberOfRows:3 michael@0: numberOfColumns:1]; michael@0: [radio release]; michael@0: [matrix setCellSize:NSMakeSize(400, 21)]; michael@0: [self addSubview:matrix]; michael@0: [matrix release]; michael@0: NSArray *cellArray = [matrix cells]; michael@0: mAsLaidOutRadio = [cellArray objectAtIndex:0]; michael@0: mSelectedFrameRadio = [cellArray objectAtIndex:1]; michael@0: mSeparateFramesRadio = [cellArray objectAtIndex:2]; michael@0: [mAsLaidOutRadio setTitle:[self localizedString:"asLaidOut"]]; michael@0: [mSelectedFrameRadio setTitle:[self localizedString:"selectedFrame"]]; michael@0: [mSeparateFramesRadio setTitle:[self localizedString:"separateFrames"]]; michael@0: michael@0: // Radio enabled state michael@0: int16_t frameUIFlag; michael@0: mSettings->GetHowToEnableFrameUI(&frameUIFlag); michael@0: if (frameUIFlag == nsIPrintSettings::kFrameEnableNone) { michael@0: [mAsLaidOutRadio setEnabled:NO]; michael@0: [mSelectedFrameRadio setEnabled:NO]; michael@0: [mSeparateFramesRadio setEnabled:NO]; michael@0: } else if (frameUIFlag == nsIPrintSettings::kFrameEnableAsIsAndEach) { michael@0: [mSelectedFrameRadio setEnabled:NO]; michael@0: } michael@0: michael@0: // Radio values michael@0: int16_t printFrameType; michael@0: mSettings->GetPrintFrameType(&printFrameType); michael@0: switch (printFrameType) { michael@0: case nsIPrintSettings::kFramesAsIs: michael@0: [mAsLaidOutRadio setState:NSOnState]; michael@0: break; michael@0: case nsIPrintSettings::kSelectedFrame: michael@0: [mSelectedFrameRadio setState:NSOnState]; michael@0: break; michael@0: case nsIPrintSettings::kEachFrameSep: michael@0: [mSeparateFramesRadio setState:NSOnState]; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: - (void)addHeaderFooterSection michael@0: { michael@0: // Labels michael@0: [self addLabel:"pageHeadersTitleMac" withFrame:NSMakeRect(0, 44, 151, 22)]; michael@0: [self addLabel:"pageFootersTitleMac" withFrame:NSMakeRect(0, 0, 151, 22)]; michael@0: [self addCenteredLabel:"left" withFrame:NSMakeRect(156, 22, 100, 22)]; michael@0: [self addCenteredLabel:"center" withFrame:NSMakeRect(256, 22, 100, 22)]; michael@0: [self addCenteredLabel:"right" withFrame:NSMakeRect(356, 22, 100, 22)]; michael@0: michael@0: // Lists michael@0: nsXPIDLString sel; michael@0: michael@0: mSettings->GetHeaderStrLeft(getter_Copies(sel)); michael@0: mHeaderLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 44, 100, 22) michael@0: selectedItem:sel]; michael@0: [self addSubview:mHeaderLeftList]; michael@0: michael@0: mSettings->GetHeaderStrCenter(getter_Copies(sel)); michael@0: mHeaderCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 44, 100, 22) michael@0: selectedItem:sel]; michael@0: [self addSubview:mHeaderCenterList]; michael@0: michael@0: mSettings->GetHeaderStrRight(getter_Copies(sel)); michael@0: mHeaderRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 44, 100, 22) michael@0: selectedItem:sel]; michael@0: [self addSubview:mHeaderRightList]; michael@0: michael@0: mSettings->GetFooterStrLeft(getter_Copies(sel)); michael@0: mFooterLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 0, 100, 22) michael@0: selectedItem:sel]; michael@0: [self addSubview:mFooterLeftList]; michael@0: michael@0: mSettings->GetFooterStrCenter(getter_Copies(sel)); michael@0: mFooterCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 0, 100, 22) michael@0: selectedItem:sel]; michael@0: [self addSubview:mFooterCenterList]; michael@0: michael@0: mSettings->GetFooterStrRight(getter_Copies(sel)); michael@0: mFooterRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 0, 100, 22) michael@0: selectedItem:sel]; michael@0: [self addSubview:mFooterRightList]; michael@0: } michael@0: michael@0: // Export settings michael@0: michael@0: - (int16_t)chosenFrameSetting michael@0: { michael@0: if ([mAsLaidOutRadio state] == NSOnState) michael@0: return nsIPrintSettings::kFramesAsIs; michael@0: if ([mSelectedFrameRadio state] == NSOnState) michael@0: return nsIPrintSettings::kSelectedFrame; michael@0: if ([mSeparateFramesRadio state] == NSOnState) michael@0: return nsIPrintSettings::kEachFrameSep; michael@0: return nsIPrintSettings::kNoFrames; michael@0: } michael@0: michael@0: - (const char*)headerFooterStringForList:(NSPopUpButton*)aList michael@0: { michael@0: NSInteger index = [aList indexOfSelectedItem]; michael@0: NS_ASSERTION(index < NSInteger(ArrayLength(sHeaderFooterTags)), "Index of dropdown is higher than expected!"); michael@0: return sHeaderFooterTags[index]; michael@0: } michael@0: michael@0: - (void)exportHeaderFooterSettings michael@0: { michael@0: const char* headerFooterStr; michael@0: headerFooterStr = [self headerFooterStringForList:mHeaderLeftList]; michael@0: mSettings->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get()); michael@0: michael@0: headerFooterStr = [self headerFooterStringForList:mHeaderCenterList]; michael@0: mSettings->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get()); michael@0: michael@0: headerFooterStr = [self headerFooterStringForList:mHeaderRightList]; michael@0: mSettings->SetHeaderStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get()); michael@0: michael@0: headerFooterStr = [self headerFooterStringForList:mFooterLeftList]; michael@0: mSettings->SetFooterStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get()); michael@0: michael@0: headerFooterStr = [self headerFooterStringForList:mFooterCenterList]; michael@0: mSettings->SetFooterStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get()); michael@0: michael@0: headerFooterStr = [self headerFooterStringForList:mFooterRightList]; michael@0: mSettings->SetFooterStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get()); michael@0: } michael@0: michael@0: // Summary michael@0: michael@0: - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox michael@0: { michael@0: if (![aCheckbox isEnabled]) michael@0: return [self localizedString:"summaryNAValue"]; michael@0: michael@0: return [aCheckbox state] == NSOnState ? michael@0: [self localizedString:"summaryOnValue"] : michael@0: [self localizedString:"summaryOffValue"]; michael@0: } michael@0: michael@0: - (NSString*)framesSummaryValue michael@0: { michael@0: switch([self chosenFrameSetting]) { michael@0: case nsIPrintSettings::kFramesAsIs: michael@0: return [self localizedString:"asLaidOut"]; michael@0: case nsIPrintSettings::kSelectedFrame: michael@0: return [self localizedString:"selectedFrame"]; michael@0: case nsIPrintSettings::kEachFrameSep: michael@0: return [self localizedString:"separateFrames"]; michael@0: } michael@0: return [self localizedString:"summaryNAValue"]; michael@0: } michael@0: michael@0: - (NSString*)headerSummaryValue michael@0: { michael@0: return [[mHeaderLeftList titleOfSelectedItem] stringByAppendingString: michael@0: [@", " stringByAppendingString: michael@0: [[mHeaderCenterList titleOfSelectedItem] stringByAppendingString: michael@0: [@", " stringByAppendingString: michael@0: [mHeaderRightList titleOfSelectedItem]]]]]; michael@0: } michael@0: michael@0: - (NSString*)footerSummaryValue michael@0: { michael@0: return [[mFooterLeftList titleOfSelectedItem] stringByAppendingString: michael@0: [@", " stringByAppendingString: michael@0: [[mFooterCenterList titleOfSelectedItem] stringByAppendingString: michael@0: [@", " stringByAppendingString: michael@0: [mFooterRightList titleOfSelectedItem]]]]]; michael@0: } michael@0: michael@0: - (NSArray*)localizedSummaryItems michael@0: { michael@0: return [NSArray arrayWithObjects: michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summaryFramesTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self framesSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summarySelectionOnlyTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self summaryValueForCheckbox:mPrintSelectionOnlyCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summaryShrinkToFitTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self summaryValueForCheckbox:mShrinkToFitCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summaryPrintBGColorsTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self summaryValueForCheckbox:mPrintBGColorsCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summaryPrintBGImagesTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self summaryValueForCheckbox:mPrintBGImagesCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summaryHeaderTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self headerSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: [NSDictionary dictionaryWithObjectsAndKeys: michael@0: [self localizedString:"summaryFooterTitle"], NSPrintPanelAccessorySummaryItemNameKey, michael@0: [self footerSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], michael@0: nil]; michael@0: } michael@0: michael@0: @end michael@0: michael@0: // Accessory controller michael@0: michael@0: @implementation PrintPanelAccessoryController michael@0: michael@0: - (id)initWithSettings:(nsIPrintSettings*)aSettings michael@0: { michael@0: [super initWithNibName:nil bundle:nil]; michael@0: michael@0: NSView* accView = [[PrintPanelAccessoryView alloc] initWithSettings:aSettings]; michael@0: [self setView:accView]; michael@0: [accView release]; michael@0: return self; michael@0: } michael@0: michael@0: - (void)exportSettings michael@0: { michael@0: return [(PrintPanelAccessoryView*)[self view] exportSettings]; michael@0: } michael@0: michael@0: - (NSArray *)localizedSummaryItems michael@0: { michael@0: return [(PrintPanelAccessoryView*)[self view] localizedSummaryItems]; michael@0: } michael@0: michael@0: @end