1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/cocoa/nsPrintDialogX.mm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,621 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/ArrayUtils.h" 1.10 + 1.11 +#include "nsPrintDialogX.h" 1.12 +#include "nsIPrintSettings.h" 1.13 +#include "nsPrintSettingsX.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsServiceManagerUtils.h" 1.16 +#include "nsIWebProgressListener.h" 1.17 +#include "nsIStringBundle.h" 1.18 +#include "nsIWebBrowserPrint.h" 1.19 +#include "nsCRT.h" 1.20 + 1.21 +#import <Cocoa/Cocoa.h> 1.22 +#include "nsObjCExceptions.h" 1.23 + 1.24 +using namespace mozilla; 1.25 + 1.26 +NS_IMPL_ISUPPORTS(nsPrintDialogServiceX, nsIPrintDialogService) 1.27 + 1.28 +nsPrintDialogServiceX::nsPrintDialogServiceX() 1.29 +{ 1.30 +} 1.31 + 1.32 +nsPrintDialogServiceX::~nsPrintDialogServiceX() 1.33 +{ 1.34 +} 1.35 + 1.36 +NS_IMETHODIMP 1.37 +nsPrintDialogServiceX::Init() 1.38 +{ 1.39 + return NS_OK; 1.40 +} 1.41 + 1.42 +NS_IMETHODIMP 1.43 +nsPrintDialogServiceX::Show(nsIDOMWindow *aParent, nsIPrintSettings *aSettings, 1.44 + nsIWebBrowserPrint *aWebBrowserPrint) 1.45 +{ 1.46 + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 1.47 + 1.48 + NS_PRECONDITION(aSettings, "aSettings must not be null"); 1.49 + 1.50 + nsRefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aSettings)); 1.51 + if (!settingsX) 1.52 + return NS_ERROR_FAILURE; 1.53 + 1.54 + // Set the print job title 1.55 + char16_t** docTitles; 1.56 + uint32_t titleCount; 1.57 + nsresult rv = aWebBrowserPrint->EnumerateDocumentNames(&titleCount, &docTitles); 1.58 + if (NS_SUCCEEDED(rv) && titleCount > 0) { 1.59 + CFStringRef cfTitleString = CFStringCreateWithCharacters(NULL, reinterpret_cast<const UniChar*>(docTitles[0]), 1.60 + NS_strlen(docTitles[0])); 1.61 + if (cfTitleString) { 1.62 + ::PMPrintSettingsSetJobName(settingsX->GetPMPrintSettings(), cfTitleString); 1.63 + CFRelease(cfTitleString); 1.64 + } 1.65 + for (int32_t i = titleCount - 1; i >= 0; i--) { 1.66 + NS_Free(docTitles[i]); 1.67 + } 1.68 + NS_Free(docTitles); 1.69 + docTitles = NULL; 1.70 + titleCount = 0; 1.71 + } 1.72 + 1.73 + NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo(); 1.74 + 1.75 + // Put the print info into the current print operation, since that's where 1.76 + // [panel runModal] will look for it. We create the view because otherwise 1.77 + // we'll get unrelated warnings printed to the console. 1.78 + NSView* tmpView = [[NSView alloc] init]; 1.79 + NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:tmpView printInfo:printInfo]; 1.80 + [NSPrintOperation setCurrentOperation:printOperation]; 1.81 + 1.82 + NSPrintPanel* panel = [NSPrintPanel printPanel]; 1.83 + PrintPanelAccessoryController* viewController = 1.84 + [[PrintPanelAccessoryController alloc] initWithSettings:aSettings]; 1.85 + [panel addAccessoryController:viewController]; 1.86 + [viewController release]; 1.87 + 1.88 + // Show the dialog. 1.89 + nsCocoaUtils::PrepareForNativeAppModalDialog(); 1.90 + int button = [panel runModal]; 1.91 + nsCocoaUtils::CleanUpAfterNativeAppModalDialog(); 1.92 + 1.93 + settingsX->SetCocoaPrintInfo([[[NSPrintOperation currentOperation] printInfo] copy]); 1.94 + [NSPrintOperation setCurrentOperation:nil]; 1.95 + [printInfo release]; 1.96 + [tmpView release]; 1.97 + 1.98 + if (button != NSOKButton) 1.99 + return NS_ERROR_ABORT; 1.100 + 1.101 + // Export settings. 1.102 + [viewController exportSettings]; 1.103 + 1.104 + int16_t pageRange; 1.105 + aSettings->GetPrintRange(&pageRange); 1.106 + if (pageRange != nsIPrintSettings::kRangeSelection) { 1.107 + PMPrintSettings nativePrintSettings = settingsX->GetPMPrintSettings(); 1.108 + UInt32 firstPage, lastPage; 1.109 + OSStatus status = ::PMGetFirstPage(nativePrintSettings, &firstPage); 1.110 + if (status == noErr) { 1.111 + status = ::PMGetLastPage(nativePrintSettings, &lastPage); 1.112 + if (status == noErr && lastPage != UINT32_MAX) { 1.113 + aSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange); 1.114 + aSettings->SetStartPageRange(firstPage); 1.115 + aSettings->SetEndPageRange(lastPage); 1.116 + } 1.117 + } 1.118 + } 1.119 + 1.120 + return NS_OK; 1.121 + 1.122 + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 1.123 +} 1.124 + 1.125 +NS_IMETHODIMP 1.126 +nsPrintDialogServiceX::ShowPageSetup(nsIDOMWindow *aParent, 1.127 + nsIPrintSettings *aNSSettings) 1.128 +{ 1.129 + NS_PRECONDITION(aParent, "aParent must not be null"); 1.130 + NS_PRECONDITION(aNSSettings, "aSettings must not be null"); 1.131 + NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE); 1.132 + 1.133 + nsRefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aNSSettings)); 1.134 + if (!settingsX) 1.135 + return NS_ERROR_FAILURE; 1.136 + 1.137 + NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo(); 1.138 + NSPageLayout *pageLayout = [NSPageLayout pageLayout]; 1.139 + nsCocoaUtils::PrepareForNativeAppModalDialog(); 1.140 + int button = [pageLayout runModalWithPrintInfo:printInfo]; 1.141 + nsCocoaUtils::CleanUpAfterNativeAppModalDialog(); 1.142 + 1.143 + return button == NSOKButton ? NS_OK : NS_ERROR_ABORT; 1.144 +} 1.145 + 1.146 +// Accessory view 1.147 + 1.148 +@interface PrintPanelAccessoryView (Private) 1.149 + 1.150 +- (NSString*)localizedString:(const char*)aKey; 1.151 + 1.152 +- (int16_t)chosenFrameSetting; 1.153 + 1.154 +- (const char*)headerFooterStringForList:(NSPopUpButton*)aList; 1.155 + 1.156 +- (void)exportHeaderFooterSettings; 1.157 + 1.158 +- (void)initBundle; 1.159 + 1.160 +- (NSTextField*)label:(const char*)aLabel 1.161 + withFrame:(NSRect)aRect 1.162 + alignment:(NSTextAlignment)aAlignment; 1.163 + 1.164 +- (void)addLabel:(const char*)aLabel 1.165 + withFrame:(NSRect)aRect 1.166 + alignment:(NSTextAlignment)aAlignment; 1.167 + 1.168 +- (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect; 1.169 + 1.170 +- (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect; 1.171 + 1.172 +- (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect; 1.173 + 1.174 +- (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect 1.175 + selectedItem:(const char16_t*)aCurrentString; 1.176 + 1.177 +- (void)addOptionsSection; 1.178 + 1.179 +- (void)addAppearanceSection; 1.180 + 1.181 +- (void)addFramesSection; 1.182 + 1.183 +- (void)addHeaderFooterSection; 1.184 + 1.185 +- (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox; 1.186 + 1.187 +- (NSString*)framesSummaryValue; 1.188 + 1.189 +- (NSString*)headerSummaryValue; 1.190 + 1.191 +- (NSString*)footerSummaryValue; 1.192 + 1.193 +@end 1.194 + 1.195 +static const char sHeaderFooterTags[][4] = {"", "&T", "&U", "&D", "&P", "&PT"}; 1.196 + 1.197 +@implementation PrintPanelAccessoryView 1.198 + 1.199 +// Public methods 1.200 + 1.201 +- (id)initWithSettings:(nsIPrintSettings*)aSettings 1.202 +{ 1.203 + [super initWithFrame:NSMakeRect(0, 0, 540, 270)]; 1.204 + 1.205 + mSettings = aSettings; 1.206 + [self initBundle]; 1.207 + [self addOptionsSection]; 1.208 + [self addAppearanceSection]; 1.209 + [self addFramesSection]; 1.210 + [self addHeaderFooterSection]; 1.211 + 1.212 + return self; 1.213 +} 1.214 + 1.215 +- (void)exportSettings 1.216 +{ 1.217 + mSettings->SetPrintRange([mPrintSelectionOnlyCheckbox state] == NSOnState ? 1.218 + (int16_t)nsIPrintSettings::kRangeSelection : 1.219 + (int16_t)nsIPrintSettings::kRangeAllPages); 1.220 + mSettings->SetShrinkToFit([mShrinkToFitCheckbox state] == NSOnState); 1.221 + mSettings->SetPrintBGColors([mPrintBGColorsCheckbox state] == NSOnState); 1.222 + mSettings->SetPrintBGImages([mPrintBGImagesCheckbox state] == NSOnState); 1.223 + mSettings->SetPrintFrameType([self chosenFrameSetting]); 1.224 + 1.225 + [self exportHeaderFooterSettings]; 1.226 +} 1.227 + 1.228 +- (void)dealloc 1.229 +{ 1.230 + NS_IF_RELEASE(mPrintBundle); 1.231 + [super dealloc]; 1.232 +} 1.233 + 1.234 +// Localization 1.235 + 1.236 +- (void)initBundle 1.237 +{ 1.238 + nsCOMPtr<nsIStringBundleService> bundleSvc = do_GetService(NS_STRINGBUNDLE_CONTRACTID); 1.239 + bundleSvc->CreateBundle("chrome://global/locale/printdialog.properties", &mPrintBundle); 1.240 +} 1.241 + 1.242 +- (NSString*)localizedString:(const char*)aKey 1.243 +{ 1.244 + if (!mPrintBundle) 1.245 + return @""; 1.246 + 1.247 + nsXPIDLString intlString; 1.248 + mPrintBundle->GetStringFromName(NS_ConvertUTF8toUTF16(aKey).get(), getter_Copies(intlString)); 1.249 + NSMutableString* s = [NSMutableString stringWithUTF8String:NS_ConvertUTF16toUTF8(intlString).get()]; 1.250 + 1.251 + // Remove all underscores (they're used in the GTK dialog for accesskeys). 1.252 + [s replaceOccurrencesOfString:@"_" withString:@"" options:0 range:NSMakeRange(0, [s length])]; 1.253 + return s; 1.254 +} 1.255 + 1.256 +// Widget helpers 1.257 + 1.258 +- (NSTextField*)label:(const char*)aLabel 1.259 + withFrame:(NSRect)aRect 1.260 + alignment:(NSTextAlignment)aAlignment 1.261 +{ 1.262 + NSTextField* label = [[[NSTextField alloc] initWithFrame:aRect] autorelease]; 1.263 + [label setStringValue:[self localizedString:aLabel]]; 1.264 + [label setEditable:NO]; 1.265 + [label setSelectable:NO]; 1.266 + [label setBezeled:NO]; 1.267 + [label setBordered:NO]; 1.268 + [label setDrawsBackground:NO]; 1.269 + [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 1.270 + [label setAlignment:aAlignment]; 1.271 + return label; 1.272 +} 1.273 + 1.274 +- (void)addLabel:(const char*)aLabel 1.275 + withFrame:(NSRect)aRect 1.276 + alignment:(NSTextAlignment)aAlignment 1.277 +{ 1.278 + NSTextField* label = [self label:aLabel withFrame:aRect alignment:aAlignment]; 1.279 + [self addSubview:label]; 1.280 +} 1.281 + 1.282 +- (void)addLabel:(const char*)aLabel withFrame:(NSRect)aRect 1.283 +{ 1.284 + [self addLabel:aLabel withFrame:aRect alignment:NSRightTextAlignment]; 1.285 +} 1.286 + 1.287 +- (void)addCenteredLabel:(const char*)aLabel withFrame:(NSRect)aRect 1.288 +{ 1.289 + [self addLabel:aLabel withFrame:aRect alignment:NSCenterTextAlignment]; 1.290 +} 1.291 + 1.292 +- (NSButton*)checkboxWithLabel:(const char*)aLabel andFrame:(NSRect)aRect 1.293 +{ 1.294 + aRect.origin.y += 4.0f; 1.295 + NSButton* checkbox = [[[NSButton alloc] initWithFrame:aRect] autorelease]; 1.296 + [checkbox setButtonType:NSSwitchButton]; 1.297 + [checkbox setTitle:[self localizedString:aLabel]]; 1.298 + [checkbox setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 1.299 + [checkbox sizeToFit]; 1.300 + return checkbox; 1.301 +} 1.302 + 1.303 +- (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect 1.304 + selectedItem:(const char16_t*)aCurrentString 1.305 +{ 1.306 + NSPopUpButton* list = [[[NSPopUpButton alloc] initWithFrame:aRect pullsDown:NO] autorelease]; 1.307 + [list setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; 1.308 + [[list cell] setControlSize:NSSmallControlSize]; 1.309 + NSArray* items = 1.310 + [NSArray arrayWithObjects:[self localizedString:"headerFooterBlank"], 1.311 + [self localizedString:"headerFooterTitle"], 1.312 + [self localizedString:"headerFooterURL"], 1.313 + [self localizedString:"headerFooterDate"], 1.314 + [self localizedString:"headerFooterPage"], 1.315 + [self localizedString:"headerFooterPageTotal"], 1.316 + nil]; 1.317 + [list addItemsWithTitles:items]; 1.318 + 1.319 + NS_ConvertUTF16toUTF8 currentStringUTF8(aCurrentString); 1.320 + for (unsigned int i = 0; i < ArrayLength(sHeaderFooterTags); i++) { 1.321 + if (!strcmp(currentStringUTF8.get(), sHeaderFooterTags[i])) { 1.322 + [list selectItemAtIndex:i]; 1.323 + break; 1.324 + } 1.325 + } 1.326 + 1.327 + return list; 1.328 +} 1.329 + 1.330 +// Build sections 1.331 + 1.332 +- (void)addOptionsSection 1.333 +{ 1.334 + // Title 1.335 + [self addLabel:"optionsTitleMac" withFrame:NSMakeRect(0, 240, 151, 22)]; 1.336 + 1.337 + // "Print Selection Only" 1.338 + mPrintSelectionOnlyCheckbox = [self checkboxWithLabel:"selectionOnly" 1.339 + andFrame:NSMakeRect(156, 240, 0, 0)]; 1.340 + 1.341 + bool canPrintSelection; 1.342 + mSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, 1.343 + &canPrintSelection); 1.344 + [mPrintSelectionOnlyCheckbox setEnabled:canPrintSelection]; 1.345 + 1.346 + int16_t printRange; 1.347 + mSettings->GetPrintRange(&printRange); 1.348 + if (printRange == nsIPrintSettings::kRangeSelection) { 1.349 + [mPrintSelectionOnlyCheckbox setState:NSOnState]; 1.350 + } 1.351 + 1.352 + [self addSubview:mPrintSelectionOnlyCheckbox]; 1.353 + 1.354 + // "Shrink To Fit" 1.355 + mShrinkToFitCheckbox = [self checkboxWithLabel:"shrinkToFit" 1.356 + andFrame:NSMakeRect(156, 218, 0, 0)]; 1.357 + 1.358 + bool shrinkToFit; 1.359 + mSettings->GetShrinkToFit(&shrinkToFit); 1.360 + [mShrinkToFitCheckbox setState:(shrinkToFit ? NSOnState : NSOffState)]; 1.361 + 1.362 + [self addSubview:mShrinkToFitCheckbox]; 1.363 +} 1.364 + 1.365 +- (void)addAppearanceSection 1.366 +{ 1.367 + // Title 1.368 + [self addLabel:"appearanceTitleMac" withFrame:NSMakeRect(0, 188, 151, 22)]; 1.369 + 1.370 + // "Print Background Colors" 1.371 + mPrintBGColorsCheckbox = [self checkboxWithLabel:"printBGColors" 1.372 + andFrame:NSMakeRect(156, 188, 0, 0)]; 1.373 + 1.374 + bool geckoBool; 1.375 + mSettings->GetPrintBGColors(&geckoBool); 1.376 + [mPrintBGColorsCheckbox setState:(geckoBool ? NSOnState : NSOffState)]; 1.377 + 1.378 + [self addSubview:mPrintBGColorsCheckbox]; 1.379 + 1.380 + // "Print Background Images" 1.381 + mPrintBGImagesCheckbox = [self checkboxWithLabel:"printBGImages" 1.382 + andFrame:NSMakeRect(156, 166, 0, 0)]; 1.383 + 1.384 + mSettings->GetPrintBGImages(&geckoBool); 1.385 + [mPrintBGImagesCheckbox setState:(geckoBool ? NSOnState : NSOffState)]; 1.386 + 1.387 + [self addSubview:mPrintBGImagesCheckbox]; 1.388 +} 1.389 + 1.390 +- (void)addFramesSection 1.391 +{ 1.392 + // Title 1.393 + [self addLabel:"framesTitleMac" withFrame:NSMakeRect(0, 124, 151, 22)]; 1.394 + 1.395 + // Radio matrix 1.396 + NSButtonCell *radio = [[NSButtonCell alloc] init]; 1.397 + [radio setButtonType:NSRadioButton]; 1.398 + [radio setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 1.399 + NSMatrix *matrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(156, 81, 400, 66) 1.400 + mode:NSRadioModeMatrix 1.401 + prototype:(NSCell*)radio 1.402 + numberOfRows:3 1.403 + numberOfColumns:1]; 1.404 + [radio release]; 1.405 + [matrix setCellSize:NSMakeSize(400, 21)]; 1.406 + [self addSubview:matrix]; 1.407 + [matrix release]; 1.408 + NSArray *cellArray = [matrix cells]; 1.409 + mAsLaidOutRadio = [cellArray objectAtIndex:0]; 1.410 + mSelectedFrameRadio = [cellArray objectAtIndex:1]; 1.411 + mSeparateFramesRadio = [cellArray objectAtIndex:2]; 1.412 + [mAsLaidOutRadio setTitle:[self localizedString:"asLaidOut"]]; 1.413 + [mSelectedFrameRadio setTitle:[self localizedString:"selectedFrame"]]; 1.414 + [mSeparateFramesRadio setTitle:[self localizedString:"separateFrames"]]; 1.415 + 1.416 + // Radio enabled state 1.417 + int16_t frameUIFlag; 1.418 + mSettings->GetHowToEnableFrameUI(&frameUIFlag); 1.419 + if (frameUIFlag == nsIPrintSettings::kFrameEnableNone) { 1.420 + [mAsLaidOutRadio setEnabled:NO]; 1.421 + [mSelectedFrameRadio setEnabled:NO]; 1.422 + [mSeparateFramesRadio setEnabled:NO]; 1.423 + } else if (frameUIFlag == nsIPrintSettings::kFrameEnableAsIsAndEach) { 1.424 + [mSelectedFrameRadio setEnabled:NO]; 1.425 + } 1.426 + 1.427 + // Radio values 1.428 + int16_t printFrameType; 1.429 + mSettings->GetPrintFrameType(&printFrameType); 1.430 + switch (printFrameType) { 1.431 + case nsIPrintSettings::kFramesAsIs: 1.432 + [mAsLaidOutRadio setState:NSOnState]; 1.433 + break; 1.434 + case nsIPrintSettings::kSelectedFrame: 1.435 + [mSelectedFrameRadio setState:NSOnState]; 1.436 + break; 1.437 + case nsIPrintSettings::kEachFrameSep: 1.438 + [mSeparateFramesRadio setState:NSOnState]; 1.439 + break; 1.440 + } 1.441 +} 1.442 + 1.443 +- (void)addHeaderFooterSection 1.444 +{ 1.445 + // Labels 1.446 + [self addLabel:"pageHeadersTitleMac" withFrame:NSMakeRect(0, 44, 151, 22)]; 1.447 + [self addLabel:"pageFootersTitleMac" withFrame:NSMakeRect(0, 0, 151, 22)]; 1.448 + [self addCenteredLabel:"left" withFrame:NSMakeRect(156, 22, 100, 22)]; 1.449 + [self addCenteredLabel:"center" withFrame:NSMakeRect(256, 22, 100, 22)]; 1.450 + [self addCenteredLabel:"right" withFrame:NSMakeRect(356, 22, 100, 22)]; 1.451 + 1.452 + // Lists 1.453 + nsXPIDLString sel; 1.454 + 1.455 + mSettings->GetHeaderStrLeft(getter_Copies(sel)); 1.456 + mHeaderLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 44, 100, 22) 1.457 + selectedItem:sel]; 1.458 + [self addSubview:mHeaderLeftList]; 1.459 + 1.460 + mSettings->GetHeaderStrCenter(getter_Copies(sel)); 1.461 + mHeaderCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 44, 100, 22) 1.462 + selectedItem:sel]; 1.463 + [self addSubview:mHeaderCenterList]; 1.464 + 1.465 + mSettings->GetHeaderStrRight(getter_Copies(sel)); 1.466 + mHeaderRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 44, 100, 22) 1.467 + selectedItem:sel]; 1.468 + [self addSubview:mHeaderRightList]; 1.469 + 1.470 + mSettings->GetFooterStrLeft(getter_Copies(sel)); 1.471 + mFooterLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 0, 100, 22) 1.472 + selectedItem:sel]; 1.473 + [self addSubview:mFooterLeftList]; 1.474 + 1.475 + mSettings->GetFooterStrCenter(getter_Copies(sel)); 1.476 + mFooterCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 0, 100, 22) 1.477 + selectedItem:sel]; 1.478 + [self addSubview:mFooterCenterList]; 1.479 + 1.480 + mSettings->GetFooterStrRight(getter_Copies(sel)); 1.481 + mFooterRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 0, 100, 22) 1.482 + selectedItem:sel]; 1.483 + [self addSubview:mFooterRightList]; 1.484 +} 1.485 + 1.486 +// Export settings 1.487 + 1.488 +- (int16_t)chosenFrameSetting 1.489 +{ 1.490 + if ([mAsLaidOutRadio state] == NSOnState) 1.491 + return nsIPrintSettings::kFramesAsIs; 1.492 + if ([mSelectedFrameRadio state] == NSOnState) 1.493 + return nsIPrintSettings::kSelectedFrame; 1.494 + if ([mSeparateFramesRadio state] == NSOnState) 1.495 + return nsIPrintSettings::kEachFrameSep; 1.496 + return nsIPrintSettings::kNoFrames; 1.497 +} 1.498 + 1.499 +- (const char*)headerFooterStringForList:(NSPopUpButton*)aList 1.500 +{ 1.501 + NSInteger index = [aList indexOfSelectedItem]; 1.502 + NS_ASSERTION(index < NSInteger(ArrayLength(sHeaderFooterTags)), "Index of dropdown is higher than expected!"); 1.503 + return sHeaderFooterTags[index]; 1.504 +} 1.505 + 1.506 +- (void)exportHeaderFooterSettings 1.507 +{ 1.508 + const char* headerFooterStr; 1.509 + headerFooterStr = [self headerFooterStringForList:mHeaderLeftList]; 1.510 + mSettings->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get()); 1.511 + 1.512 + headerFooterStr = [self headerFooterStringForList:mHeaderCenterList]; 1.513 + mSettings->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get()); 1.514 + 1.515 + headerFooterStr = [self headerFooterStringForList:mHeaderRightList]; 1.516 + mSettings->SetHeaderStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get()); 1.517 + 1.518 + headerFooterStr = [self headerFooterStringForList:mFooterLeftList]; 1.519 + mSettings->SetFooterStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get()); 1.520 + 1.521 + headerFooterStr = [self headerFooterStringForList:mFooterCenterList]; 1.522 + mSettings->SetFooterStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get()); 1.523 + 1.524 + headerFooterStr = [self headerFooterStringForList:mFooterRightList]; 1.525 + mSettings->SetFooterStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get()); 1.526 +} 1.527 + 1.528 +// Summary 1.529 + 1.530 +- (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox 1.531 +{ 1.532 + if (![aCheckbox isEnabled]) 1.533 + return [self localizedString:"summaryNAValue"]; 1.534 + 1.535 + return [aCheckbox state] == NSOnState ? 1.536 + [self localizedString:"summaryOnValue"] : 1.537 + [self localizedString:"summaryOffValue"]; 1.538 +} 1.539 + 1.540 +- (NSString*)framesSummaryValue 1.541 +{ 1.542 + switch([self chosenFrameSetting]) { 1.543 + case nsIPrintSettings::kFramesAsIs: 1.544 + return [self localizedString:"asLaidOut"]; 1.545 + case nsIPrintSettings::kSelectedFrame: 1.546 + return [self localizedString:"selectedFrame"]; 1.547 + case nsIPrintSettings::kEachFrameSep: 1.548 + return [self localizedString:"separateFrames"]; 1.549 + } 1.550 + return [self localizedString:"summaryNAValue"]; 1.551 +} 1.552 + 1.553 +- (NSString*)headerSummaryValue 1.554 +{ 1.555 + return [[mHeaderLeftList titleOfSelectedItem] stringByAppendingString: 1.556 + [@", " stringByAppendingString: 1.557 + [[mHeaderCenterList titleOfSelectedItem] stringByAppendingString: 1.558 + [@", " stringByAppendingString: 1.559 + [mHeaderRightList titleOfSelectedItem]]]]]; 1.560 +} 1.561 + 1.562 +- (NSString*)footerSummaryValue 1.563 +{ 1.564 + return [[mFooterLeftList titleOfSelectedItem] stringByAppendingString: 1.565 + [@", " stringByAppendingString: 1.566 + [[mFooterCenterList titleOfSelectedItem] stringByAppendingString: 1.567 + [@", " stringByAppendingString: 1.568 + [mFooterRightList titleOfSelectedItem]]]]]; 1.569 +} 1.570 + 1.571 +- (NSArray*)localizedSummaryItems 1.572 +{ 1.573 + return [NSArray arrayWithObjects: 1.574 + [NSDictionary dictionaryWithObjectsAndKeys: 1.575 + [self localizedString:"summaryFramesTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.576 + [self framesSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.577 + [NSDictionary dictionaryWithObjectsAndKeys: 1.578 + [self localizedString:"summarySelectionOnlyTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.579 + [self summaryValueForCheckbox:mPrintSelectionOnlyCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.580 + [NSDictionary dictionaryWithObjectsAndKeys: 1.581 + [self localizedString:"summaryShrinkToFitTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.582 + [self summaryValueForCheckbox:mShrinkToFitCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.583 + [NSDictionary dictionaryWithObjectsAndKeys: 1.584 + [self localizedString:"summaryPrintBGColorsTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.585 + [self summaryValueForCheckbox:mPrintBGColorsCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.586 + [NSDictionary dictionaryWithObjectsAndKeys: 1.587 + [self localizedString:"summaryPrintBGImagesTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.588 + [self summaryValueForCheckbox:mPrintBGImagesCheckbox], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.589 + [NSDictionary dictionaryWithObjectsAndKeys: 1.590 + [self localizedString:"summaryHeaderTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.591 + [self headerSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.592 + [NSDictionary dictionaryWithObjectsAndKeys: 1.593 + [self localizedString:"summaryFooterTitle"], NSPrintPanelAccessorySummaryItemNameKey, 1.594 + [self footerSummaryValue], NSPrintPanelAccessorySummaryItemDescriptionKey, nil], 1.595 + nil]; 1.596 +} 1.597 + 1.598 +@end 1.599 + 1.600 +// Accessory controller 1.601 + 1.602 +@implementation PrintPanelAccessoryController 1.603 + 1.604 +- (id)initWithSettings:(nsIPrintSettings*)aSettings 1.605 +{ 1.606 + [super initWithNibName:nil bundle:nil]; 1.607 + 1.608 + NSView* accView = [[PrintPanelAccessoryView alloc] initWithSettings:aSettings]; 1.609 + [self setView:accView]; 1.610 + [accView release]; 1.611 + return self; 1.612 +} 1.613 + 1.614 +- (void)exportSettings 1.615 +{ 1.616 + return [(PrintPanelAccessoryView*)[self view] exportSettings]; 1.617 +} 1.618 + 1.619 +- (NSArray *)localizedSummaryItems 1.620 +{ 1.621 + return [(PrintPanelAccessoryView*)[self view] localizedSummaryItems]; 1.622 +} 1.623 + 1.624 +@end