2009-10-09 05:20:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2018-03-12 09:16:51 +00:00
|
|
|
#include "mozilla/gfx/PrintTargetCG.h"
|
2017-07-05 20:40:09 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2009-10-09 05:20:37 +00:00
|
|
|
#include "nsPrintDialogX.h"
|
|
|
|
#include "nsIPrintSettings.h"
|
2016-11-10 01:37:40 +00:00
|
|
|
#include "nsIPrintSettingsService.h"
|
2009-10-09 05:20:37 +00:00
|
|
|
#include "nsPrintSettingsX.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2015-04-15 16:47:03 +00:00
|
|
|
#include "nsQueryObject.h"
|
2009-10-09 05:20:37 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIStringBundle.h"
|
2009-11-02 19:23:53 +00:00
|
|
|
#include "nsCRT.h"
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#include "nsObjCExceptions.h"
|
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
2018-03-12 09:16:51 +00:00
|
|
|
using mozilla::gfx::PrintTarget;
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsPrintDialogServiceX, nsIPrintDialogService)
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
nsPrintDialogServiceX::nsPrintDialogServiceX() {}
|
|
|
|
|
|
|
|
nsPrintDialogServiceX::~nsPrintDialogServiceX() {}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintDialogServiceX::Init() { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-12-09 09:04:29 +00:00
|
|
|
nsPrintDialogServiceX::Show(nsPIDOMWindowOuter* aParent, nsIPrintSettings* aSettings) {
|
2009-10-09 05:20:37 +00:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aSettings, "aSettings must not be null");
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aSettings));
|
2020-10-23 11:07:21 +00:00
|
|
|
if (!settingsX) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2016-11-10 01:37:40 +00:00
|
|
|
nsCOMPtr<nsIPrintSettingsService> printSettingsSvc =
|
|
|
|
do_GetService("@mozilla.org/gfx/printsettings-service;1");
|
|
|
|
|
2020-10-23 11:07:21 +00:00
|
|
|
// Read the saved printer settings from prefs. (This relies on the printer name
|
|
|
|
// stored in settingsX to read the printer-specific prefs.)
|
2019-03-26 20:15:53 +00:00
|
|
|
printSettingsSvc->InitPrintSettingsFromPrefs(settingsX, true, nsIPrintSettings::kInitSaveAll);
|
2009-11-02 19:23:53 +00:00
|
|
|
|
2020-10-23 11:07:46 +00:00
|
|
|
NSPrintInfo* printInfo = settingsX->CreateOrCopyPrintInfo(/* aWithScaling = */ true);
|
2020-10-23 11:07:21 +00:00
|
|
|
if (NS_WARN_IF(!printInfo)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
[printInfo autorelease];
|
|
|
|
|
2020-03-02 10:45:38 +00:00
|
|
|
// Set the print job title
|
|
|
|
nsAutoString docName;
|
|
|
|
nsresult rv = aSettings->GetTitle(docName);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsAutoString adjustedTitle;
|
|
|
|
PrintTarget::AdjustPrintJobNameForIPP(docName, adjustedTitle);
|
|
|
|
CFStringRef cfTitleString = CFStringCreateWithCharacters(
|
|
|
|
NULL, reinterpret_cast<const UniChar*>(adjustedTitle.BeginReading()),
|
|
|
|
adjustedTitle.Length());
|
|
|
|
if (cfTitleString) {
|
2020-10-23 11:07:21 +00:00
|
|
|
auto pmPrintSettings = static_cast<PMPrintSettings>([printInfo PMPrintSettings]);
|
|
|
|
::PMPrintSettingsSetJobName(pmPrintSettings, cfTitleString);
|
|
|
|
[printInfo updateFromPMPrintSettings];
|
2020-03-02 10:45:38 +00:00
|
|
|
CFRelease(cfTitleString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-09 05:20:37 +00:00
|
|
|
// Put the print info into the current print operation, since that's where
|
|
|
|
// [panel runModal] will look for it. We create the view because otherwise
|
|
|
|
// we'll get unrelated warnings printed to the console.
|
|
|
|
NSView* tmpView = [[NSView alloc] init];
|
|
|
|
NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:tmpView
|
|
|
|
printInfo:printInfo];
|
|
|
|
[NSPrintOperation setCurrentOperation:printOperation];
|
|
|
|
|
|
|
|
NSPrintPanel* panel = [NSPrintPanel printPanel];
|
2015-10-18 07:22:00 +00:00
|
|
|
[panel setOptions:NSPrintPanelShowsCopies | NSPrintPanelShowsPageRange |
|
|
|
|
NSPrintPanelShowsPaperSize | NSPrintPanelShowsOrientation |
|
|
|
|
NSPrintPanelShowsScaling];
|
2009-10-09 05:20:37 +00:00
|
|
|
PrintPanelAccessoryController* viewController =
|
|
|
|
[[PrintPanelAccessoryController alloc] initWithSettings:aSettings];
|
|
|
|
[panel addAccessoryController:viewController];
|
|
|
|
[viewController release];
|
|
|
|
|
|
|
|
// Show the dialog.
|
|
|
|
nsCocoaUtils::PrepareForNativeAppModalDialog();
|
|
|
|
int button = [panel runModal];
|
|
|
|
nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
|
|
|
|
|
2020-10-23 11:07:21 +00:00
|
|
|
// Retrieve a printInfo with the updated settings. (The NSPrintOperation operates on a
|
|
|
|
// copy, so the object we passed in will not have been modified.)
|
|
|
|
NSPrintInfo* result = [[NSPrintOperation currentOperation] printInfo];
|
|
|
|
if (!result) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 18:10:21 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 05:20:37 +00:00
|
|
|
[NSPrintOperation setCurrentOperation:nil];
|
|
|
|
[tmpView release];
|
|
|
|
|
2020-10-23 11:07:21 +00:00
|
|
|
if (button != NSFileHandlingPanelOKButton) {
|
|
|
|
return NS_ERROR_ABORT;
|
2016-11-10 01:37:40 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 05:20:37 +00:00
|
|
|
// Export settings.
|
|
|
|
[viewController exportSettings];
|
|
|
|
|
2020-10-23 11:07:21 +00:00
|
|
|
// Update our settings object based on the user's choices in the dialog.
|
2020-10-23 11:07:46 +00:00
|
|
|
// We tell settingsX to adopt this printInfo so that it will be used to run print job,
|
|
|
|
// so that any printer-specific custom settings from print dialog extension panels
|
|
|
|
// will be carried through.
|
|
|
|
settingsX->SetFromPrintInfo(result, /* aAdoptPrintInfo = */ true);
|
2016-11-17 23:29:08 +00:00
|
|
|
|
2020-10-23 11:07:21 +00:00
|
|
|
// Save settings unless saving is pref'd off
|
|
|
|
if (Preferences::GetBool("print.save_print_settings", false)) {
|
|
|
|
printSettingsSvc->SavePrintSettingsToPrefs(settingsX, true,
|
|
|
|
nsIPrintSettings::kInitSaveNativeData);
|
2009-10-09 05:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPrintDialogServiceX::ShowPageSetup(nsPIDOMWindowOuter* aParent, nsIPrintSettings* aNSSettings) {
|
2017-01-15 07:47:36 +00:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aParent, "aParent must not be null");
|
|
|
|
MOZ_ASSERT(aNSSettings, "aSettings must not be null");
|
2009-10-09 05:20:37 +00:00
|
|
|
NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aNSSettings));
|
2020-10-23 11:07:21 +00:00
|
|
|
if (!settingsX) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-10-23 11:07:46 +00:00
|
|
|
NSPrintInfo* printInfo = settingsX->CreateOrCopyPrintInfo(/* aWithScaling = */ true);
|
2020-10-23 11:07:21 +00:00
|
|
|
if (NS_WARN_IF(!printInfo)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
[printInfo autorelease];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
NSPageLayout* pageLayout = [NSPageLayout pageLayout];
|
|
|
|
nsCocoaUtils::PrepareForNativeAppModalDialog();
|
|
|
|
int button = [pageLayout runModalWithPrintInfo:printInfo];
|
|
|
|
nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
|
|
|
|
|
2020-05-11 14:10:45 +00:00
|
|
|
if (button == NSFileHandlingPanelOKButton) {
|
2020-10-23 11:07:46 +00:00
|
|
|
// The Page Setup dialog does not include non-standard settings that need to be preserved,
|
|
|
|
// separate from what the base printSettings object handles, so we do not need it to adopt
|
|
|
|
// the printInfo object here.
|
|
|
|
settingsX->SetFromPrintInfo(printInfo, /* aAdoptPrintInfo = */ false);
|
2020-05-11 14:10:45 +00:00
|
|
|
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
|
|
|
|
do_GetService("@mozilla.org/gfx/printsettings-service;1");
|
|
|
|
if (printSettingsService && Preferences::GetBool("print.save_print_settings", false)) {
|
2020-05-11 14:23:12 +00:00
|
|
|
uint32_t flags = nsIPrintSettings::kInitSaveNativeData |
|
|
|
|
nsIPrintSettings::kInitSavePaperSize |
|
|
|
|
nsIPrintSettings::kInitSaveOrientation | nsIPrintSettings::kInitSaveScaling;
|
|
|
|
printSettingsService->SavePrintSettingsToPrefs(aNSSettings, true, flags);
|
2020-05-11 14:10:45 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_ABORT;
|
2017-01-15 07:47:36 +00:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2009-10-09 05:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessory view
|
|
|
|
|
|
|
|
@interface PrintPanelAccessoryView (Private)
|
|
|
|
|
|
|
|
- (NSString*)localizedString:(const char*)aKey;
|
|
|
|
|
|
|
|
- (const char*)headerFooterStringForList:(NSPopUpButton*)aList;
|
|
|
|
|
|
|
|
- (void)exportHeaderFooterSettings;
|
|
|
|
|
|
|
|
- (void)initBundle;
|
|
|
|
|
|
|
|
- (NSTextField*)label:(const char*)aLabel
|
|
|
|
withFrame:(NSRect)aRect
|
|
|
|
alignment:(NSTextAlignment)aAlignment;
|
|
|
|
|
|
|
|
- (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect alignment:(NSTextAlignment)aAlignment;
|
|
|
|
|
|
|
|
- (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect;
|
|
|
|
|
|
|
|
- (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect;
|
|
|
|
|
|
|
|
- (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect;
|
|
|
|
|
|
|
|
- (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect
|
2017-08-08 06:07:55 +00:00
|
|
|
selectedItem:(const nsAString&)aCurrentString;
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
- (void)addOptionsSection;
|
|
|
|
|
|
|
|
- (void)addAppearanceSection;
|
|
|
|
|
|
|
|
- (void)addHeaderFooterSection;
|
|
|
|
|
|
|
|
- (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox;
|
|
|
|
|
|
|
|
- (NSString*)headerSummaryValue;
|
|
|
|
|
|
|
|
- (NSString*)footerSummaryValue;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static const char sHeaderFooterTags[][4] = {"", "&T", "&U", "&D", "&P", "&PT"};
|
|
|
|
|
|
|
|
@implementation PrintPanelAccessoryView
|
|
|
|
|
|
|
|
// Public methods
|
|
|
|
|
|
|
|
- (id)initWithSettings:(nsIPrintSettings*)aSettings {
|
2019-05-14 16:04:37 +00:00
|
|
|
[super initWithFrame:NSMakeRect(0, 0, 540, 185)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
mSettings = aSettings;
|
|
|
|
[self initBundle];
|
|
|
|
[self addOptionsSection];
|
|
|
|
[self addAppearanceSection];
|
|
|
|
[self addHeaderFooterSection];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)exportSettings {
|
2020-10-02 13:59:48 +00:00
|
|
|
mSettings->SetPrintSelectionOnly([mPrintSelectionOnlyCheckbox state] == NSOnState);
|
2009-10-09 05:20:37 +00:00
|
|
|
mSettings->SetShrinkToFit([mShrinkToFitCheckbox state] == NSOnState);
|
|
|
|
mSettings->SetPrintBGColors([mPrintBGColorsCheckbox state] == NSOnState);
|
|
|
|
mSettings->SetPrintBGImages([mPrintBGImagesCheckbox state] == NSOnState);
|
|
|
|
|
|
|
|
[self exportHeaderFooterSettings];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
NS_IF_RELEASE(mPrintBundle);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Localization
|
|
|
|
|
|
|
|
- (void)initBundle {
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleSvc = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
|
|
|
bundleSvc->CreateBundle("chrome://global/locale/printdialog.properties", &mPrintBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)localizedString:(const char*)aKey {
|
|
|
|
if (!mPrintBundle) return @"";
|
|
|
|
|
2017-08-04 04:40:52 +00:00
|
|
|
nsAutoString intlString;
|
|
|
|
mPrintBundle->GetStringFromName(aKey, intlString);
|
2009-10-09 05:20:37 +00:00
|
|
|
NSMutableString* s =
|
|
|
|
[NSMutableString stringWithUTF8String:NS_ConvertUTF16toUTF8(intlString).get()];
|
|
|
|
|
|
|
|
// Remove all underscores (they're used in the GTK dialog for accesskeys).
|
|
|
|
[s replaceOccurrencesOfString:@"_" withString:@"" options:0 range:NSMakeRange(0, [s length])];
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Widget helpers
|
|
|
|
|
|
|
|
- (NSTextField*)label:(const char*)aLabel
|
|
|
|
withFrame:(NSRect)aRect
|
|
|
|
alignment:(NSTextAlignment)aAlignment {
|
|
|
|
NSTextField* label = [[[NSTextField alloc] initWithFrame:aRect] autorelease];
|
|
|
|
[label setStringValue:[self localizedString:aLabel]];
|
|
|
|
[label setEditable:NO];
|
|
|
|
[label setSelectable:NO];
|
|
|
|
[label setBezeled:NO];
|
|
|
|
[label setBordered:NO];
|
|
|
|
[label setDrawsBackground:NO];
|
|
|
|
[label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
|
|
|
|
[label setAlignment:aAlignment];
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect alignment:(NSTextAlignment)aAlignment {
|
|
|
|
NSTextField* label = [self label:aLabel withFrame:aRect alignment:aAlignment];
|
|
|
|
[self addSubview:label];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect {
|
2021-01-05 21:17:11 +00:00
|
|
|
[self addLabel:aLabel withFrame:aRect alignment:NSTextAlignmentRight];
|
2009-10-09 05:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect {
|
2021-01-05 21:17:11 +00:00
|
|
|
[self addLabel:aLabel withFrame:aRect alignment:NSTextAlignmentCenter];
|
2009-10-09 05:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect {
|
|
|
|
aRect.origin.y += 4.0f;
|
|
|
|
NSButton* checkbox = [[[NSButton alloc] initWithFrame:aRect] autorelease];
|
|
|
|
[checkbox setButtonType:NSSwitchButton];
|
|
|
|
[checkbox setTitle:[self localizedString:aLabel]];
|
|
|
|
[checkbox setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
|
|
|
|
[checkbox sizeToFit];
|
|
|
|
return checkbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect
|
2017-08-08 06:07:55 +00:00
|
|
|
selectedItem:(const nsAString&)aCurrentString {
|
2009-10-09 05:20:37 +00:00
|
|
|
NSPopUpButton* list = [[[NSPopUpButton alloc] initWithFrame:aRect pullsDown:NO] autorelease];
|
|
|
|
[list setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
|
2021-01-05 21:17:11 +00:00
|
|
|
[[list cell] setControlSize:NSControlSizeSmall];
|
2009-10-09 05:20:37 +00:00
|
|
|
NSArray* items = [NSArray arrayWithObjects:[self localizedString:"headerFooterBlank"],
|
|
|
|
[self localizedString:"headerFooterTitle"],
|
|
|
|
[self localizedString:"headerFooterURL"],
|
|
|
|
[self localizedString:"headerFooterDate"],
|
|
|
|
[self localizedString:"headerFooterPage"],
|
|
|
|
[self localizedString:"headerFooterPageTotal"], nil];
|
|
|
|
[list addItemsWithTitles:items];
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 currentStringUTF8(aCurrentString);
|
2011-10-11 05:50:08 +00:00
|
|
|
for (unsigned int i = 0; i < ArrayLength(sHeaderFooterTags); i++) {
|
2009-10-09 05:20:37 +00:00
|
|
|
if (!strcmp(currentStringUTF8.get(), sHeaderFooterTags[i])) {
|
|
|
|
[list selectItemAtIndex:i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build sections
|
|
|
|
|
|
|
|
- (void)addOptionsSection {
|
|
|
|
// Title
|
2019-05-14 16:04:37 +00:00
|
|
|
[self addLabel:"optionsTitleMac" withFrame:NSMakeRect(0, 155, 151, 22)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
// "Print Selection Only"
|
|
|
|
mPrintSelectionOnlyCheckbox = [self checkboxWithLabel:"selectionOnly"
|
2019-05-14 16:04:37 +00:00
|
|
|
andFrame:NSMakeRect(156, 155, 0, 0)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2020-10-07 00:36:51 +00:00
|
|
|
bool canPrintSelection = mSettings->GetIsPrintSelectionRBEnabled();
|
2009-10-09 05:20:37 +00:00
|
|
|
[mPrintSelectionOnlyCheckbox setEnabled:canPrintSelection];
|
|
|
|
|
2020-10-02 13:59:48 +00:00
|
|
|
if (mSettings->GetPrintSelectionOnly()) {
|
2009-10-09 05:20:37 +00:00
|
|
|
[mPrintSelectionOnlyCheckbox setState:NSOnState];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self addSubview:mPrintSelectionOnlyCheckbox];
|
|
|
|
|
|
|
|
// "Shrink To Fit"
|
2019-05-14 16:04:37 +00:00
|
|
|
mShrinkToFitCheckbox = [self checkboxWithLabel:"shrinkToFit" andFrame:NSMakeRect(156, 133, 0, 0)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool shrinkToFit;
|
2009-10-09 05:20:37 +00:00
|
|
|
mSettings->GetShrinkToFit(&shrinkToFit);
|
|
|
|
[mShrinkToFitCheckbox setState:(shrinkToFit ? NSOnState : NSOffState)];
|
|
|
|
|
|
|
|
[self addSubview:mShrinkToFitCheckbox];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addAppearanceSection {
|
|
|
|
// Title
|
2019-05-14 16:04:37 +00:00
|
|
|
[self addLabel:"appearanceTitleMac" withFrame:NSMakeRect(0, 103, 151, 22)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
// "Print Background Colors"
|
|
|
|
mPrintBGColorsCheckbox = [self checkboxWithLabel:"printBGColors"
|
2019-05-14 16:04:37 +00:00
|
|
|
andFrame:NSMakeRect(156, 103, 0, 0)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2020-09-16 11:21:41 +00:00
|
|
|
bool geckoBool = mSettings->GetPrintBGColors();
|
2009-10-09 05:20:37 +00:00
|
|
|
[mPrintBGColorsCheckbox setState:(geckoBool ? NSOnState : NSOffState)];
|
|
|
|
|
|
|
|
[self addSubview:mPrintBGColorsCheckbox];
|
|
|
|
|
|
|
|
// "Print Background Images"
|
|
|
|
mPrintBGImagesCheckbox = [self checkboxWithLabel:"printBGImages"
|
2019-05-14 16:04:37 +00:00
|
|
|
andFrame:NSMakeRect(156, 81, 0, 0)];
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2020-09-16 11:21:41 +00:00
|
|
|
geckoBool = mSettings->GetPrintBGImages();
|
2009-10-09 05:20:37 +00:00
|
|
|
[mPrintBGImagesCheckbox setState:(geckoBool ? NSOnState : NSOffState)];
|
|
|
|
|
|
|
|
[self addSubview:mPrintBGImagesCheckbox];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addHeaderFooterSection {
|
|
|
|
// Labels
|
|
|
|
[self addLabel:"pageHeadersTitleMac" withFrame:NSMakeRect(0, 44, 151, 22)];
|
|
|
|
[self addLabel:"pageFootersTitleMac" withFrame:NSMakeRect(0, 0, 151, 22)];
|
|
|
|
[self addCenteredLabel:"left" withFrame:NSMakeRect(156, 22, 100, 22)];
|
|
|
|
[self addCenteredLabel:"center" withFrame:NSMakeRect(256, 22, 100, 22)];
|
|
|
|
[self addCenteredLabel:"right" withFrame:NSMakeRect(356, 22, 100, 22)];
|
|
|
|
|
|
|
|
// Lists
|
2017-08-08 06:07:55 +00:00
|
|
|
nsString sel;
|
2009-10-09 05:20:37 +00:00
|
|
|
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->GetHeaderStrLeft(sel);
|
2009-10-09 05:20:37 +00:00
|
|
|
mHeaderLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 44, 100, 22)
|
|
|
|
selectedItem:sel];
|
|
|
|
[self addSubview:mHeaderLeftList];
|
|
|
|
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->GetHeaderStrCenter(sel);
|
2009-10-09 05:20:37 +00:00
|
|
|
mHeaderCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 44, 100, 22)
|
|
|
|
selectedItem:sel];
|
|
|
|
[self addSubview:mHeaderCenterList];
|
|
|
|
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->GetHeaderStrRight(sel);
|
2009-10-09 05:20:37 +00:00
|
|
|
mHeaderRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 44, 100, 22)
|
|
|
|
selectedItem:sel];
|
|
|
|
[self addSubview:mHeaderRightList];
|
|
|
|
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->GetFooterStrLeft(sel);
|
2009-10-09 05:20:37 +00:00
|
|
|
mFooterLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 0, 100, 22)
|
|
|
|
selectedItem:sel];
|
|
|
|
[self addSubview:mFooterLeftList];
|
|
|
|
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->GetFooterStrCenter(sel);
|
2009-10-09 05:20:37 +00:00
|
|
|
mFooterCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 0, 100, 22)
|
|
|
|
selectedItem:sel];
|
|
|
|
[self addSubview:mFooterCenterList];
|
|
|
|
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->GetFooterStrRight(sel);
|
2009-10-09 05:20:37 +00:00
|
|
|
mFooterRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 0, 100, 22)
|
|
|
|
selectedItem:sel];
|
|
|
|
[self addSubview:mFooterRightList];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export settings
|
|
|
|
|
|
|
|
- (const char*)headerFooterStringForList:(NSPopUpButton*)aList {
|
|
|
|
NSInteger index = [aList indexOfSelectedItem];
|
2011-10-11 05:50:08 +00:00
|
|
|
NS_ASSERTION(index < NSInteger(ArrayLength(sHeaderFooterTags)),
|
|
|
|
"Index of dropdown is higher than expected!");
|
2009-10-09 05:20:37 +00:00
|
|
|
return sHeaderFooterTags[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)exportHeaderFooterSettings {
|
|
|
|
const char* headerFooterStr;
|
|
|
|
headerFooterStr = [self headerFooterStringForList:mHeaderLeftList];
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr));
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
headerFooterStr = [self headerFooterStringForList:mHeaderCenterList];
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr));
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
headerFooterStr = [self headerFooterStringForList:mHeaderRightList];
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->SetHeaderStrRight(NS_ConvertUTF8toUTF16(headerFooterStr));
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
headerFooterStr = [self headerFooterStringForList:mFooterLeftList];
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->SetFooterStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr));
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
headerFooterStr = [self headerFooterStringForList:mFooterCenterList];
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->SetFooterStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr));
|
2009-10-09 05:20:37 +00:00
|
|
|
|
|
|
|
headerFooterStr = [self headerFooterStringForList:mFooterRightList];
|
2017-10-08 23:08:09 +00:00
|
|
|
mSettings->SetFooterStrRight(NS_ConvertUTF8toUTF16(headerFooterStr));
|
2009-10-09 05:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Summary
|
|
|
|
|
|
|
|
- (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox {
|
|
|
|
if (![aCheckbox isEnabled]) return [self localizedString:"summaryNAValue"];
|
|
|
|
|
|
|
|
return [aCheckbox state] == NSOnState ? [self localizedString:"summaryOnValue"]
|
|
|
|
: [self localizedString:"summaryOffValue"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)headerSummaryValue {
|
|
|
|
return [[mHeaderLeftList titleOfSelectedItem]
|
|
|
|
stringByAppendingString:
|
2019-01-21 17:18:16 +00:00
|
|
|
[@", "
|
2009-10-09 05:20:37 +00:00
|
|
|
stringByAppendingString:
|
|
|
|
[[mHeaderCenterList titleOfSelectedItem]
|
|
|
|
stringByAppendingString:
|
|
|
|
[@", " stringByAppendingString:[mHeaderRightList titleOfSelectedItem]]]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)footerSummaryValue {
|
|
|
|
return [[mFooterLeftList titleOfSelectedItem]
|
|
|
|
stringByAppendingString:
|
2019-01-21 17:18:16 +00:00
|
|
|
[@", "
|
2009-10-09 05:20:37 +00:00
|
|
|
stringByAppendingString:
|
|
|
|
[[mFooterCenterList titleOfSelectedItem]
|
|
|
|
stringByAppendingString:
|
|
|
|
[@", " stringByAppendingString:[mFooterRightList titleOfSelectedItem]]]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)localizedSummaryItems {
|
|
|
|
return [NSArray
|
|
|
|
arrayWithObjects:
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:[self localizedString:"summarySelectionOnlyTitle"],
|
|
|
|
NSPrintPanelAccessorySummaryItemNameKey,
|
|
|
|
[self
|
|
|
|
summaryValueForCheckbox:mPrintSelectionOnlyCheckbox],
|
|
|
|
NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:[self localizedString:"summaryShrinkToFitTitle"],
|
|
|
|
NSPrintPanelAccessorySummaryItemNameKey,
|
|
|
|
[self summaryValueForCheckbox:mShrinkToFitCheckbox],
|
|
|
|
NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:[self localizedString:"summaryPrintBGColorsTitle"],
|
|
|
|
NSPrintPanelAccessorySummaryItemNameKey,
|
|
|
|
[self summaryValueForCheckbox:mPrintBGColorsCheckbox],
|
|
|
|
NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:[self localizedString:"summaryPrintBGImagesTitle"],
|
|
|
|
NSPrintPanelAccessorySummaryItemNameKey,
|
|
|
|
[self summaryValueForCheckbox:mPrintBGImagesCheckbox],
|
|
|
|
NSPrintPanelAccessorySummaryItemDescriptionKey, nil],
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:[self localizedString:"summaryHeaderTitle"],
|
|
|
|
NSPrintPanelAccessorySummaryItemNameKey,
|
|
|
|
[self headerSummaryValue],
|
|
|
|
NSPrintPanelAccessorySummaryItemDescriptionKey,
|
|
|
|
nil],
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:[self localizedString:"summaryFooterTitle"],
|
|
|
|
NSPrintPanelAccessorySummaryItemNameKey,
|
|
|
|
[self footerSummaryValue],
|
|
|
|
NSPrintPanelAccessorySummaryItemDescriptionKey,
|
|
|
|
nil],
|
|
|
|
nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Accessory controller
|
|
|
|
|
|
|
|
@implementation PrintPanelAccessoryController
|
|
|
|
|
|
|
|
- (id)initWithSettings:(nsIPrintSettings*)aSettings {
|
|
|
|
[super initWithNibName:nil bundle:nil];
|
2010-02-23 20:04:05 +00:00
|
|
|
|
2009-10-09 05:20:37 +00:00
|
|
|
NSView* accView = [[PrintPanelAccessoryView alloc] initWithSettings:aSettings];
|
|
|
|
[self setView:accView];
|
|
|
|
[accView release];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)exportSettings {
|
|
|
|
return [(PrintPanelAccessoryView*)[self view] exportSettings];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)localizedSummaryItems {
|
|
|
|
return [(PrintPanelAccessoryView*)[self view] localizedSummaryItems];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|