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