Back to index

lightning-sunbird  0.9+nobinonly
PDECustom.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Conrad Carlen <ccarlen@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include <Carbon/Carbon.h>
00040 #include <Print/PMPrintingDialogExtensions.h>
00041 
00042 #include "PDECore.h"
00043 #include "PDECustom.h"
00044 #include "PDEUtilities.h"
00045 
00046 // Static Prototypes
00047 static void InitSettings(MySettings* settings);
00048 static void InternSettings(CFDictionaryRef srcDict, MySettings* settings);
00049 static void ExternSettings(MySettings* settings, CFMutableDictionaryRef destDict);
00050 static void SyncPaneFromSettings(MyCustomContext context);
00051 static void SyncSettingsFromPane(MyCustomContext context);
00052 static CFStringRef GetSummaryTextBooleanValue(Boolean value);
00053 static CFStringRef GetSummaryTextNAValue();
00054 static CFStringRef GetSummaryTextHeaderFooterValue(CFStringRef inStr);
00055 static int  GetIndexForPrintString(CFStringRef stringCode);
00056 static CFStringRef GetPrintStringFromIndex(int index);
00057 
00058 /*
00059 --------------------------------------------------------------------------------
00060     MyCreateCustomContext
00061 --------------------------------------------------------------------------------
00062 */
00063 
00064 extern MyCustomContext MyCreateCustomContext()
00065 {
00066     // allocate zeroed storage for a custom context
00067     MyCustomContext context = calloc (1, sizeof (MyCustomContextBlock));
00068 
00069     return context;
00070 }
00071 
00072 
00073 /*
00074 --------------------------------------------------------------------------------
00075     MyReleaseCustomContext
00076 --------------------------------------------------------------------------------
00077 */
00078 
00079 extern void MyReleaseCustomContext (MyCustomContext context)
00080 {
00081     MyCFAssign(NULL, context->settings.mHeaderLeft);
00082     MyCFAssign(NULL, context->settings.mHeaderCenter);
00083     MyCFAssign(NULL, context->settings.mHeaderRight);
00084     MyCFAssign(NULL, context->settings.mFooterLeft);
00085     MyCFAssign(NULL, context->settings.mFooterCenter);
00086     MyCFAssign(NULL, context->settings.mFooterRight);
00087     
00088     free (context);
00089 }
00090 
00091 
00092 #pragma mark -
00093 
00094 /*
00095 --------------------------------------------------------------------------------
00096     MyGetCustomTitle
00097 --------------------------------------------------------------------------------
00098 */
00099 
00100 /*
00101     In this implementation, we only copy the localized title string once.
00102     We keep a static reference to the copy for re-use.
00103 */
00104 
00105 extern CFStringRef MyGetCustomTitle (Boolean stillNeeded)
00106 {
00107     static CFStringRef sTitle = NULL;
00108 
00109     if (stillNeeded)
00110     {
00111         if (sTitle == NULL)
00112         {
00113             // Get the name of the application hosting us.
00114             CFBundleRef appBundle = CFBundleGetMainBundle();
00115             if (appBundle)
00116             {
00117                 CFStringRef bundleString = CFBundleGetValueForInfoDictionaryKey(
00118                                             appBundle, CFSTR("CFBundleName"));
00119                 // We don't get an owning reference here, so make a copy.
00120                 if (bundleString && (CFGetTypeID(bundleString) == CFStringGetTypeID()))
00121                     sTitle = CFStringCreateCopy(NULL, bundleString);
00122             }
00123         }
00124         // If that failed, use a resource - we may be hosted by an unbundled app.
00125         if (sTitle == NULL)
00126         {
00127             sTitle = CFCopyLocalizedStringFromTableInBundle (
00128                 CFSTR("Web Browser"),
00129                 CFSTR("Localizable"),
00130                 MyGetBundle(),
00131                 "the custom pane title");
00132         }
00133     }
00134     else 
00135     {
00136         if (sTitle != NULL)
00137         {
00138             CFRelease (sTitle);
00139             sTitle = NULL;
00140         }
00141     }
00142 
00143     return sTitle;
00144 }
00145 
00146 
00147 /*
00148 --------------------------------------------------------------------------------
00149     MyEmbedCustomControls
00150 --------------------------------------------------------------------------------
00151 */
00152 
00153 extern OSStatus MyEmbedCustomControls (
00154     MyCustomContext context,
00155     WindowRef nibWindow,
00156     ControlRef userPane
00157 )
00158 
00159 {
00160     static const ControlID containerControlID = { kMozPDECreatorCode, 4000 };
00161     static const ControlID radioGroupControlID = { kMozPDECreatorCode, 4001 };
00162     static const ControlID printSelCheckControlID = { kMozPDECreatorCode, 4002 };
00163     static const ControlID shrinkToFitCheckControlID = { kMozPDECreatorCode, 4003 };
00164     static const ControlID printBGColorsCheckControlID = { kMozPDECreatorCode, 4004 };
00165     static const ControlID printBGImagesCheckControlID = { kMozPDECreatorCode, 4005 };
00166     static const ControlID headerLeftPopupControlID = { kMozPDECreatorCode, 4006 };
00167     static const ControlID headerCenterPopupControlID = { kMozPDECreatorCode, 4007 };
00168     static const ControlID headerRightPopupControlID = { kMozPDECreatorCode, 4008 };
00169     static const ControlID footerLeftPopupControlID = { kMozPDECreatorCode, 4009 };
00170     static const ControlID footerCenterPopupControlID = { kMozPDECreatorCode, 4010 };
00171     static const ControlID footerRightPopupControlID = { kMozPDECreatorCode, 4011 };
00172     
00173     OSStatus result = noErr;
00174     
00175     if (context != NULL)
00176     {
00177         ControlHandle paneControl = NULL;
00178         
00179         // The control we're embedding into the given
00180         // userPane is itself a user pane control.
00181         result = MyEmbedControl(nibWindow,
00182                                 userPane,
00183                                 &containerControlID,
00184                                 &paneControl);
00185         
00186         if (paneControl)
00187         {
00188             WindowRef controlOwner = GetControlOwner(paneControl);
00189             
00190             GetControlByID(controlOwner,
00191                            &radioGroupControlID,
00192                            &(context->controls.frameRadioGroup));
00193             if (context->controls.frameRadioGroup != NULL)
00194             {
00195 
00196                 // It doesn't seem to be possible to specify the titles of the
00197                 // radio buttons within a radio group control, so do it by hand :-/
00198                 // This is not done as a loop, but instead using CFSTR("abc") so
00199                 // that genstrings can grok this file. Maybe that's not worth it?
00200                 
00201                 CFStringRef radioTitle;
00202                 ControlRef radioControl;
00203                     
00204                 if (GetIndexedSubControl(context->controls.frameRadioGroup,
00205                                          kFramesAsLaidOutIndex, &radioControl) == noErr)
00206                 {
00207                     radioTitle = CFCopyLocalizedStringFromTableInBundle(
00208                                         CFSTR("As laid out on the screen"),
00209                                         CFSTR("Localizable"),
00210                                         MyGetBundle(),
00211                                         "top radio title");
00212                     if (radioTitle)
00213                     {
00214                         SetControlTitleWithCFString(radioControl, radioTitle);
00215                         CFRelease(radioTitle);
00216                     }
00217                 }
00218                 if (GetIndexedSubControl(context->controls.frameRadioGroup,
00219                                          kFramesSelectedIndex, &radioControl) == noErr)
00220                 {
00221                     radioTitle = CFCopyLocalizedStringFromTableInBundle(
00222                                         CFSTR("The selected frame"),
00223                                         CFSTR("Localizable"),
00224                                         MyGetBundle(),
00225                                         "middle radio title");
00226                     if (radioTitle)
00227                     {
00228                         SetControlTitleWithCFString(radioControl, radioTitle);
00229                         CFRelease(radioTitle);
00230                     }
00231                 }
00232                 if (GetIndexedSubControl(context->controls.frameRadioGroup,
00233                                          kFramesEachSeparatelyIndex, &radioControl) == noErr)
00234                 {
00235                     radioTitle = CFCopyLocalizedStringFromTableInBundle(
00236                                         CFSTR("Each frame separately"),
00237                                         CFSTR("Localizable"),
00238                                         MyGetBundle(),
00239                                         "bottom radio title");
00240                     if (radioTitle)
00241                     {
00242                         SetControlTitleWithCFString(radioControl, radioTitle);
00243                         CFRelease(radioTitle);
00244                     }
00245                 }                
00246             }
00247  
00248             GetControlByID(controlOwner,
00249                            &printSelCheckControlID,
00250                            &(context->controls.printSelCheck));
00251             GetControlByID(controlOwner,
00252                            &shrinkToFitCheckControlID,
00253                            &(context->controls.shrinkToFitCheck));
00254             GetControlByID(controlOwner,
00255                            &printBGColorsCheckControlID,
00256                            &(context->controls.printBGColorsCheck));
00257             GetControlByID(controlOwner,
00258                            &printBGImagesCheckControlID,
00259                            &(context->controls.printBGImagesCheck));
00260 
00261             GetControlByID(controlOwner,
00262                            &headerLeftPopupControlID,
00263                            &(context->controls.headerLeftPopup));
00264 
00265             GetControlByID(controlOwner,
00266                            &headerCenterPopupControlID,
00267                            &(context->controls.headerCenterPopup));
00268 
00269             GetControlByID(controlOwner,
00270                            &headerRightPopupControlID,
00271                            &(context->controls.headerRightPopup));
00272 
00273             GetControlByID(controlOwner,
00274                            &footerLeftPopupControlID,
00275                            &(context->controls.footerLeftPopup));
00276 
00277             GetControlByID(controlOwner,
00278                            &footerCenterPopupControlID,
00279                            &(context->controls.footerCenterPopup));
00280 
00281             GetControlByID(controlOwner,
00282                            &footerRightPopupControlID,
00283                            &(context->controls.footerRightPopup));
00284                            
00285             // Now that the controls are in, sync with data.
00286             SyncPaneFromSettings(context);
00287         }
00288     }
00289 
00290     return result;
00291 }
00292 
00293 
00294 /*
00295 --------------------------------------------------------------------------------
00296     MyGetSummaryText
00297 --------------------------------------------------------------------------------
00298 */
00299 
00300 extern OSStatus MyGetSummaryText (
00301     MyCustomContext context, 
00302     CFMutableArrayRef titleArray,
00303     CFMutableArrayRef valueArray
00304 )
00305 
00306 {
00307     CFStringRef title = NULL;
00308     CFStringRef value = NULL;
00309     CFStringRef format = NULL;
00310 
00311     OSStatus result = noErr;
00312 
00313     // "Print Frames" Radio Group
00314     title = CFCopyLocalizedStringFromTableInBundle (
00315                 CFSTR("Print Frames"),
00316                 CFSTR("Localizable"),
00317                 MyGetBundle(),
00318                 "the Print Frames radio group (for summary)");
00319 
00320     if (title != NULL)
00321     {        
00322         if (context->settings.mHaveFrames)
00323         {
00324             if (context->settings.mPrintFrameAsIs)
00325                 value = CFCopyLocalizedStringFromTableInBundle(
00326                                     CFSTR("As laid out on the screen"),
00327                                     CFSTR("Localizable"),
00328                                     MyGetBundle(),
00329                                     "Print Frames choice #1 (for summary)");
00330             else if (context->settings.mPrintSelectedFrame)
00331                 value = CFCopyLocalizedStringFromTableInBundle(
00332                                     CFSTR("The selected frame"),
00333                                     CFSTR("Localizable"),
00334                                     MyGetBundle(),
00335                                     "Print Frames choice #2 (for summary)");
00336             else if (context->settings.mPrintFramesSeparately)
00337                 value = CFCopyLocalizedStringFromTableInBundle(
00338                                     CFSTR("Each frame separately"),
00339                                     CFSTR("Localizable"),
00340                                     MyGetBundle(),
00341                                     "Print Frames choice #3 (for summary)");
00342         }
00343         else
00344             value = GetSummaryTextNAValue();
00345         
00346         if (value != NULL)
00347         {
00348             // append the title-value pair to the arrays
00349             CFArrayAppendValue (titleArray, title);
00350             CFArrayAppendValue (valueArray, value);
00351             
00352             CFRelease (value);
00353         }
00354         CFRelease (title);
00355     }
00356 
00357     // Print Selection
00358     title = CFCopyLocalizedStringFromTableInBundle(
00359                         CFSTR("Print Selection"),
00360                         CFSTR("Localizable"),
00361                         MyGetBundle(),
00362                         "Print Selection title (for summary)");
00363     if (title != NULL)
00364     {
00365         if (context->settings.mHaveSelection)
00366             value = GetSummaryTextBooleanValue(context->settings.mPrintSelection);
00367         else
00368             value = GetSummaryTextNAValue();
00369 
00370         if (value != NULL)
00371         {
00372             // append the title-value pair to the arrays
00373             CFArrayAppendValue (titleArray, title);
00374             CFArrayAppendValue (valueArray, value);
00375 
00376             CFRelease (value);
00377         }
00378         CFRelease (title);
00379     }
00380 
00381     // Shrink To Fit
00382     title = CFCopyLocalizedStringFromTableInBundle(
00383                         CFSTR("Shrink To Fit"),
00384                         CFSTR("Localizable"),
00385                         MyGetBundle(),
00386                         "Shrink To Fit title (for summary)");
00387     if (title != NULL)
00388     {
00389         value = GetSummaryTextBooleanValue(context->settings.mShrinkToFit);
00390         if (value != NULL)
00391         {
00392             // append the title-value pair to the arrays
00393             CFArrayAppendValue (titleArray, title);
00394             CFArrayAppendValue (valueArray, value);
00395 
00396             CFRelease (value);
00397         }
00398         CFRelease (title);
00399     }
00400 
00401     // Print BG Colors
00402     title = CFCopyLocalizedStringFromTableInBundle(
00403                         CFSTR("Print BG Colors"),
00404                         CFSTR("Localizable"),
00405                         MyGetBundle(),
00406                         "Print BG Colors title (for summary)");
00407     if (title != NULL)
00408     {
00409         value = GetSummaryTextBooleanValue(context->settings.mPrintBGColors);
00410         if (value != NULL)
00411         {
00412             // append the title-value pair to the arrays
00413             CFArrayAppendValue (titleArray, title);
00414             CFArrayAppendValue (valueArray, value);
00415 
00416             CFRelease (value);
00417         }
00418         CFRelease (title);
00419     }
00420 
00421     // Print BG Images
00422     title = CFCopyLocalizedStringFromTableInBundle(
00423                         CFSTR("Print BG Images"),
00424                         CFSTR("Localizable"),
00425                         MyGetBundle(),
00426                         "Print BG Images title (for summary)");
00427     if (title != NULL)
00428     {
00429         value = GetSummaryTextBooleanValue(context->settings.mPrintBGImages);
00430         if (value != NULL)
00431         {
00432             // append the title-value pair to the arrays
00433             CFArrayAppendValue (titleArray, title);
00434             CFArrayAppendValue (valueArray, value);
00435 
00436             CFRelease (value);
00437         }
00438         CFRelease (title);
00439     }
00440  
00441     // Page Headers
00442     title = CFCopyLocalizedStringFromTableInBundle(
00443                         CFSTR("Page Headers"),
00444                         CFSTR("Localizable"),
00445                         MyGetBundle(),
00446                         "Page Headers (for summary)");
00447     if (title != NULL)
00448     {
00449         format = CFCopyLocalizedStringFromTableInBundle(
00450                             CFSTR("%@, %@, %@"),
00451                             CFSTR("Localizable"),
00452                             MyGetBundle(),
00453                             "Page Heaader/Footer format (for summary)");
00454 
00455         if (format != NULL)
00456         {
00457             value = CFStringCreateWithFormat(NULL, NULL, format,
00458                             GetSummaryTextHeaderFooterValue(context->settings.mHeaderLeft),
00459                             GetSummaryTextHeaderFooterValue(context->settings.mHeaderCenter),
00460                             GetSummaryTextHeaderFooterValue(context->settings.mHeaderRight));
00461             if (value != NULL)
00462             {
00463                 // append the title-value pair to the arrays
00464                 CFArrayAppendValue (titleArray, title);
00465                 CFArrayAppendValue (valueArray, value);
00466 
00467                 CFRelease (value);
00468             }
00469             CFRelease(format);
00470         }
00471         CFRelease (title);
00472     }
00473 
00474     // Page Footers
00475     title = CFCopyLocalizedStringFromTableInBundle(
00476                         CFSTR("Page Footers"),
00477                         CFSTR("Localizable"),
00478                         MyGetBundle(),
00479                         "Page Footers (for summary)");
00480     if (title != NULL)
00481     {
00482         format = CFCopyLocalizedStringFromTableInBundle(
00483                             CFSTR("%@, %@, %@"),
00484                             CFSTR("Localizable"),
00485                             MyGetBundle(),
00486                             "Page Heaader/Footer format (for summary)");
00487 
00488         if (format != NULL)
00489         {
00490             value = CFStringCreateWithFormat(NULL, NULL, format,
00491                             GetSummaryTextHeaderFooterValue(context->settings.mFooterLeft),
00492                             GetSummaryTextHeaderFooterValue(context->settings.mFooterCenter),
00493                             GetSummaryTextHeaderFooterValue(context->settings.mFooterRight));
00494             if (value != NULL)
00495             {
00496                 // append the title-value pair to the arrays
00497                 CFArrayAppendValue (titleArray, title);
00498                 CFArrayAppendValue (valueArray, value);
00499 
00500                 CFRelease (value);
00501             }
00502             CFRelease(format);
00503         }
00504         CFRelease (title);
00505     }
00506 
00507     return result;
00508 }
00509 
00510 
00511 #pragma mark -
00512 
00513 
00514 /*
00515 --------------------------------------------------------------------------------
00516     MySyncPaneFromTicket
00517 --------------------------------------------------------------------------------
00518 */
00519 
00520 extern OSStatus MySyncPaneFromTicket (
00521     MyCustomContext context, 
00522     PMPrintSession session
00523 )
00524 
00525 {
00526     OSStatus result = noErr;
00527     PMTicketRef ticket = NULL;
00528 
00529     result = MyGetTicket (session, kPDE_PMPrintSettingsRef, &ticket);
00530     if (result == noErr)
00531     {
00532         CFDataRef xmlData = NULL;
00533         CFDictionaryRef dict = NULL;
00534 
00535         result = PMTicketGetCFData (
00536             ticket, 
00537             kPMTopLevel, 
00538             kPMTopLevel, 
00539             kAppPrintDialogPDEOnlyKey, 
00540             &xmlData
00541         );
00542         if (result == noErr)
00543         {
00544             dict = CFPropertyListCreateFromXMLData (
00545                         kCFAllocatorDefault,
00546                         xmlData,
00547                         kCFPropertyListImmutable,
00548                         NULL
00549                         );
00550             if (dict)
00551             {
00552                 InternSettings(dict, &context->settings);
00553                 CFRelease(dict);
00554             }
00555             else
00556                 result = kPMKeyNotFound;    // bad XML?
00557         }
00558         if (result == kPMKeyNotFound)
00559         {
00560             InitSettings(&context->settings);
00561             result = noErr;
00562         }
00563     }
00564 
00565     if (result == noErr)
00566         SyncPaneFromSettings(context);
00567     
00568     MyDebugMessage("MySyncPane", result);
00569     return result;
00570 }
00571 
00572 
00573 /*
00574 --------------------------------------------------------------------------------
00575     MySyncTicketFromPane
00576 --------------------------------------------------------------------------------
00577 */
00578 
00579 extern OSStatus MySyncTicketFromPane (
00580     MyCustomContext context, 
00581     PMPrintSession session
00582 )
00583 
00584 {
00585     OSStatus result = noErr;
00586     PMTicketRef ticket = NULL;
00587     CFMutableDictionaryRef dict = NULL;
00588     CFDataRef xmlData = NULL;
00589 
00590     result = MyGetTicket (session, kPDE_PMPrintSettingsRef, &ticket);
00591     if (result == noErr)
00592     {
00593         // If our pane has never been shown, this will be a noop.
00594         SyncSettingsFromPane(context);
00595         
00596         dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
00597                     (const CFDictionaryKeyCallBacks *)&kCFTypeDictionaryKeyCallBacks,
00598                     (const CFDictionaryValueCallBacks *)&kCFTypeDictionaryValueCallBacks);
00599         if (dict)
00600         {
00601             ExternSettings(&context->settings, dict);
00602             xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, dict);
00603             if (xmlData)
00604             {
00605                 result = PMTicketSetCFData (
00606                     ticket, 
00607                     kMyBundleIdentifier, 
00608                     kAppPrintDialogPDEOnlyKey, 
00609                     xmlData, 
00610                     kPMUnlocked
00611                 );
00612                 CFRelease(xmlData);
00613             }
00614             CFRelease(dict);
00615         }
00616     }
00617 
00618     MyDebugMessage("MySyncTicket", result);
00619     return result;
00620 }
00621 
00622 #pragma mark -
00623 
00624 /*
00625 --------------------------------------------------------------------------------
00626     Static Routines
00627 --------------------------------------------------------------------------------
00628 */
00629 
00630 static void InitSettings(MySettings* settings)
00631 {
00632     settings->mHaveSelection                = false;
00633     settings->mHaveFrames                   = false;
00634     settings->mHaveFrameSelected            = false;
00635   
00636     settings->mPrintFrameAsIs               = false;
00637     settings->mPrintSelectedFrame           = false;
00638     settings->mPrintFramesSeparately        = false;
00639     settings->mPrintSelection               = false;
00640     settings->mShrinkToFit                  = true;
00641     settings->mPrintBGColors                = true;
00642     settings->mPrintBGImages                = true;
00643     
00644     settings->mHeaderLeft                   = MyCFAssign(NULL, settings->mHeaderLeft);
00645     settings->mHeaderCenter                 = MyCFAssign(NULL, settings->mHeaderCenter);
00646     settings->mHeaderRight                  = MyCFAssign(NULL, settings->mHeaderRight);
00647     settings->mFooterLeft                   = MyCFAssign(NULL, settings->mFooterLeft);
00648     settings->mFooterCenter                 = MyCFAssign(NULL, settings->mFooterCenter);
00649     settings->mFooterRight                  = MyCFAssign(NULL, settings->mFooterRight);
00650 }
00651 
00652 static void InternSettings(CFDictionaryRef srcDict, MySettings* settings)
00653 {
00654     CFTypeRef dictValue;
00655     
00656     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHaveSelection)) &&
00657         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00658             settings->mHaveSelection = CFBooleanGetValue((CFBooleanRef)dictValue);
00659 
00660     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHaveFrames)) &&
00661         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00662             settings->mHaveFrames = CFBooleanGetValue((CFBooleanRef)dictValue);
00663 
00664     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHaveFrameSelected)) &&
00665         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00666             settings->mHaveFrameSelected = CFBooleanGetValue((CFBooleanRef)dictValue);
00667     
00668     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintFrameType)) &&
00669         (CFGetTypeID(dictValue) == CFStringGetTypeID())) {
00670         if (CFEqual(dictValue, kPDEValueFramesAsIs))
00671             settings->mPrintFrameAsIs = true;
00672         else if (CFEqual(dictValue, kPDEValueSelectedFrame))
00673             settings->mPrintSelectedFrame = true;
00674         else if (CFEqual(dictValue, kPDEValueEachFrameSep))
00675             settings->mPrintFramesSeparately = true;
00676     }
00677 
00678     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintSelection)) &&
00679         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00680             settings->mPrintSelection = CFBooleanGetValue((CFBooleanRef)dictValue); 
00681     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyShrinkToFit)) &&
00682         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00683             settings->mShrinkToFit = CFBooleanGetValue((CFBooleanRef)dictValue);
00684     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintBGColors)) &&
00685         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00686             settings->mPrintBGColors = CFBooleanGetValue((CFBooleanRef)dictValue);
00687     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyPrintBGImages)) &&
00688         (CFGetTypeID(dictValue) == CFBooleanGetTypeID()))
00689             settings->mPrintBGImages = CFBooleanGetValue((CFBooleanRef)dictValue);
00690     
00691     
00692     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHeaderLeft)) &&
00693         (CFGetTypeID(dictValue) == CFStringGetTypeID()))
00694             settings->mHeaderLeft = MyCFAssign(dictValue, settings->mHeaderLeft);
00695     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHeaderCenter)) &&
00696         (CFGetTypeID(dictValue) == CFStringGetTypeID()))
00697             settings->mHeaderCenter = MyCFAssign(dictValue, settings->mHeaderCenter);
00698     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyHeaderRight)) &&
00699         (CFGetTypeID(dictValue) == CFStringGetTypeID()))
00700             settings->mHeaderRight = MyCFAssign(dictValue, settings->mHeaderRight);
00701     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyFooterLeft)) &&
00702         (CFGetTypeID(dictValue) == CFStringGetTypeID()))
00703             settings->mFooterLeft = MyCFAssign(dictValue, settings->mFooterLeft);
00704     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyFooterCenter)) &&
00705         (CFGetTypeID(dictValue) == CFStringGetTypeID()))
00706             settings->mFooterCenter = MyCFAssign(dictValue, settings->mFooterCenter);
00707     if ((dictValue = CFDictionaryGetValue(srcDict, kPDEKeyFooterRight)) &&
00708         (CFGetTypeID(dictValue) == CFStringGetTypeID()))
00709             settings->mFooterRight = MyCFAssign(dictValue, settings->mFooterRight);
00710 }
00711 
00712 static void ExternSettings(MySettings* settings, CFMutableDictionaryRef destDict)
00713 {
00714     // Do not write the state info mHaveSelection, mHaveFrames, mHaveFrameSelected
00715     // That info is used to enable/disable UI for this session only. It's not read
00716     // back by the application, nor should it be saved in custom print settings
00717     
00718     if (settings->mPrintFrameAsIs)
00719         CFDictionaryAddValue(destDict, kPDEKeyPrintFrameType, kPDEValueFramesAsIs);
00720     else if (settings->mPrintSelectedFrame)
00721         CFDictionaryAddValue(destDict, kPDEKeyPrintFrameType, kPDEValueSelectedFrame);
00722     else if (settings->mPrintFramesSeparately)
00723         CFDictionaryAddValue(destDict, kPDEKeyPrintFrameType, kPDEValueEachFrameSep);
00724 
00725     CFDictionaryAddValue(destDict, kPDEKeyPrintSelection, settings->mPrintSelection ? kCFBooleanTrue : kCFBooleanFalse);
00726     CFDictionaryAddValue(destDict, kPDEKeyShrinkToFit, settings->mShrinkToFit ? kCFBooleanTrue : kCFBooleanFalse);
00727     CFDictionaryAddValue(destDict, kPDEKeyPrintBGColors, settings->mPrintBGColors ? kCFBooleanTrue : kCFBooleanFalse);
00728     CFDictionaryAddValue(destDict, kPDEKeyPrintBGImages, settings->mPrintBGImages ? kCFBooleanTrue : kCFBooleanFalse);
00729     
00730     CFDictionaryAddValue(destDict, kPDEKeyHeaderLeft, settings->mHeaderLeft ? settings->mHeaderLeft : CFSTR(""));
00731     CFDictionaryAddValue(destDict, kPDEKeyHeaderCenter, settings->mHeaderCenter ? settings->mHeaderCenter : CFSTR(""));
00732     CFDictionaryAddValue(destDict, kPDEKeyHeaderRight, settings->mHeaderRight ? settings->mHeaderRight : CFSTR(""));
00733     CFDictionaryAddValue(destDict, kPDEKeyFooterLeft, settings->mFooterLeft ? settings->mFooterLeft : CFSTR(""));
00734     CFDictionaryAddValue(destDict, kPDEKeyFooterCenter, settings->mFooterCenter ? settings->mFooterCenter : CFSTR(""));
00735     CFDictionaryAddValue(destDict, kPDEKeyFooterRight, settings->mFooterRight ? settings->mFooterRight : CFSTR(""));
00736 }
00737 
00738 static void SyncPaneFromSettings(MyCustomContext context)
00739 {
00740     if (context->controls.frameRadioGroup)
00741     {
00742         if (context->settings.mHaveFrames)
00743         {
00744             EnableControl(context->controls.frameRadioGroup);
00745 
00746             if (context->settings.mPrintSelectedFrame &&
00747                     context->settings.mHaveFrameSelected)
00748                 SetControl32BitValue(context->controls.frameRadioGroup,
00749                                 kFramesSelectedIndex);
00750             else if (context->settings.mPrintFramesSeparately)
00751                 SetControl32BitValue(context->controls.frameRadioGroup,
00752                                 kFramesEachSeparatelyIndex);
00753             else /* (context->settings.mPrintFrameAsIs) */
00754                 SetControl32BitValue(context->controls.frameRadioGroup,
00755                                 kFramesAsLaidOutIndex);
00756             
00757             if (!context->settings.mHaveFrameSelected)
00758             {
00759                 ControlRef radioControl;
00760                 if (GetIndexedSubControl(context->controls.frameRadioGroup,
00761                                           kFramesSelectedIndex, &radioControl) == noErr)
00762                     DisableControl(radioControl);
00763             }
00764         }
00765         else
00766         {
00767             DisableControl(context->controls.frameRadioGroup);
00768             SetControl32BitValue(context->controls.frameRadioGroup, 0);
00769         }
00770     }
00771     
00772     if (context->controls.printSelCheck)
00773     {
00774         if (context->settings.mHaveSelection)
00775         {
00776             EnableControl(context->controls.printSelCheck);
00777             SetControl32BitValue(context->controls.printSelCheck,
00778                             context->settings.mPrintSelection);
00779         }
00780         else
00781         {
00782             DisableControl(context->controls.printSelCheck);
00783             SetControl32BitValue(context->controls.printSelCheck, 0);
00784         }
00785     }
00786     if (context->controls.shrinkToFitCheck)
00787         SetControl32BitValue(context->controls.shrinkToFitCheck,
00788                         context->settings.mShrinkToFit);
00789     if (context->controls.printBGColorsCheck)
00790         SetControl32BitValue(context->controls.printBGColorsCheck,
00791                         context->settings.mPrintBGColors);
00792     if (context->controls.printBGImagesCheck)
00793         SetControl32BitValue(context->controls.printBGImagesCheck,
00794                         context->settings.mPrintBGImages);
00795                         
00796     if (context->controls.headerLeftPopup)
00797       SetControl32BitValue(context->controls.headerLeftPopup,
00798                         GetIndexForPrintString(context->settings.mHeaderLeft));
00799     if (context->controls.headerCenterPopup)
00800       SetControl32BitValue(context->controls.headerCenterPopup,
00801                         GetIndexForPrintString(context->settings.mHeaderCenter));
00802     if (context->controls.headerRightPopup)
00803       SetControl32BitValue(context->controls.headerRightPopup,
00804                         GetIndexForPrintString(context->settings.mHeaderRight));
00805 
00806     if (context->controls.footerLeftPopup)
00807       SetControl32BitValue(context->controls.footerLeftPopup,
00808                         GetIndexForPrintString(context->settings.mFooterLeft));
00809     if (context->controls.footerCenterPopup)
00810       SetControl32BitValue(context->controls.footerCenterPopup,
00811                         GetIndexForPrintString(context->settings.mFooterCenter));
00812     if (context->controls.footerRightPopup)
00813       SetControl32BitValue(context->controls.footerRightPopup,
00814                          GetIndexForPrintString(context->settings.mFooterRight));
00815 
00816 }
00817 
00818 
00819 static void SyncSettingsFromPane(MyCustomContext context)
00820 {
00821     SInt32 controlVal;
00822     
00823     if (context->controls.frameRadioGroup)
00824     {
00825         context->settings.mPrintFrameAsIs = false;
00826         context->settings.mPrintSelectedFrame = false;
00827         context->settings.mPrintFramesSeparately = false;
00828         switch (GetControl32BitValue(context->controls.frameRadioGroup))
00829         {
00830             case kFramesAsLaidOutIndex:
00831               context->settings.mPrintFrameAsIs = true;
00832               break;
00833             case kFramesSelectedIndex:
00834               context->settings.mPrintSelectedFrame = true;
00835               break;
00836             case kFramesEachSeparatelyIndex:
00837               context->settings.mPrintFramesSeparately = true;
00838               break;
00839         }
00840     }
00841     
00842     if (context->controls.printSelCheck)
00843         context->settings.mPrintSelection =
00844           GetControl32BitValue(context->controls.printSelCheck);
00845     if (context->controls.printSelCheck)
00846         context->settings.mShrinkToFit = 
00847           GetControl32BitValue(context->controls.shrinkToFitCheck);
00848     if (context->controls.printSelCheck)
00849         context->settings.mPrintBGColors = 
00850           GetControl32BitValue(context->controls.printBGColorsCheck);
00851     if (context->controls.printSelCheck)
00852         context->settings.mPrintBGImages = 
00853           GetControl32BitValue(context->controls.printBGImagesCheck);
00854           
00855     if (context->controls.headerLeftPopup) {
00856       controlVal = GetControl32BitValue(context->controls.headerLeftPopup);
00857       context->settings.mHeaderLeft = MyCFAssign(GetPrintStringFromIndex(controlVal),
00858                                                  context->settings.mHeaderLeft);      
00859     }
00860     if (context->controls.headerCenterPopup) {
00861       controlVal = GetControl32BitValue(context->controls.headerCenterPopup);
00862       context->settings.mHeaderCenter = MyCFAssign(GetPrintStringFromIndex(controlVal),
00863                                                    context->settings.mHeaderCenter);
00864     }
00865     if (context->controls.headerRightPopup) {
00866       controlVal = GetControl32BitValue(context->controls.headerRightPopup);
00867       context->settings.mHeaderRight = MyCFAssign(GetPrintStringFromIndex(controlVal),
00868                                                   context->settings.mHeaderRight);
00869     }
00870     if (context->controls.footerLeftPopup) {
00871       controlVal = GetControl32BitValue(context->controls.footerLeftPopup);
00872       context->settings.mFooterLeft = MyCFAssign(GetPrintStringFromIndex(controlVal),
00873                                       context->settings.mFooterLeft);
00874     }
00875     if (context->controls.footerCenterPopup) {
00876       controlVal = GetControl32BitValue(context->controls.footerCenterPopup);
00877       context->settings.mFooterCenter = MyCFAssign(GetPrintStringFromIndex(controlVal),
00878                                                    context->settings.mFooterCenter);
00879     }
00880     if (context->controls.footerRightPopup) {
00881       controlVal = GetControl32BitValue(context->controls.footerRightPopup);
00882       context->settings.mFooterRight = MyCFAssign(GetPrintStringFromIndex(controlVal),
00883                                                   context->settings.mFooterRight);
00884     }
00885 
00886 }
00887 
00888 #pragma mark -
00889 
00890 CFStringRef GetSummaryTextBooleanValue(Boolean value)
00891 {
00892     if (value)
00893         return CFCopyLocalizedStringFromTableInBundle(
00894                     CFSTR("On"),
00895                     CFSTR("Localizable"),
00896                     MyGetBundle(),
00897                     CFSTR("the value of a checkbox when selected"));        
00898 
00899     return CFCopyLocalizedStringFromTableInBundle(
00900                 CFSTR("Off"),
00901                 CFSTR("Localizable"),
00902                 MyGetBundle(),
00903                 CFSTR("the value of a checkbox when not selected"));
00904 }  
00905 
00906 
00907 static CFStringRef GetSummaryTextNAValue()
00908 {
00909     return CFCopyLocalizedStringFromTableInBundle(
00910                 CFSTR("N/A"),
00911                 CFSTR("Localizable"),
00912                 MyGetBundle(),
00913                 "Not Applicable (for summary)");
00914     
00915 }
00916 
00917 static CFStringRef GetSummaryTextHeaderFooterValue(CFStringRef inStr)
00918 {   
00919     if (!inStr || !CFStringGetLength(inStr))
00920         return CFCopyLocalizedStringFromTableInBundle(
00921                             CFSTR("(Blank)"),
00922                             CFSTR("Localizable"),
00923                             MyGetBundle(),
00924                             "Page Heaader/Footer <blank> (for summary)");
00925     else if (CFEqual(inStr, CFSTR("&T")))
00926         return CFCopyLocalizedStringFromTableInBundle(
00927                             CFSTR("Title"),
00928                             CFSTR("Localizable"),
00929                             MyGetBundle(),
00930                             "Page Heaader/Footer <title> (for summary)");
00931     else if (CFEqual(inStr, CFSTR("&U")))
00932         return CFCopyLocalizedStringFromTableInBundle(
00933                             CFSTR("URL"),
00934                             CFSTR("Localizable"),
00935                             MyGetBundle(),
00936                             "Page Heaader/Footer <url> (for summary)");
00937     else if (CFEqual(inStr, CFSTR("&D")))
00938         return CFCopyLocalizedStringFromTableInBundle(
00939                             CFSTR("Date"),
00940                             CFSTR("Localizable"),
00941                             MyGetBundle(),
00942                             "Page Heaader/Footer <date> (for summary)");
00943     else if (CFEqual(inStr, CFSTR("&P")))
00944         return CFCopyLocalizedStringFromTableInBundle(
00945                             CFSTR("Page #"),
00946                             CFSTR("Localizable"),
00947                             MyGetBundle(),
00948                             "Page Heaader/Footer <page #> (for summary)");
00949     else if (CFEqual(inStr, CFSTR("&PT")))
00950         return CFCopyLocalizedStringFromTableInBundle(
00951                             CFSTR("Page # of #"),
00952                             CFSTR("Localizable"),
00953                             MyGetBundle(),
00954                             "Page Heaader/Footer <page # of #> (for summary)");
00955     else
00956         return CFRetain(inStr);
00957 }
00958 
00959 //
00960 // Here we have a mapping of control codes to pop-up button messages
00961 //
00962 
00963 static int  GetIndexForPrintString(CFStringRef stringCode)
00964 {
00965     if (stringCode)
00966     {
00967         // title
00968         if (CFEqual(stringCode, CFSTR("&T")))
00969             return 2;
00970         // URL
00971         if (CFEqual(stringCode, CFSTR("&U")))
00972             return 3;
00973         // Date/Time
00974         if (CFEqual(stringCode, CFSTR("&D")))
00975             return 4;
00976         // Page Number
00977         if (CFEqual(stringCode, CFSTR("&P")))
00978             return 5;
00979         // Page Number of Total Page Numbers
00980         if (CFEqual(stringCode, CFSTR("&PT")))
00981             return 6;
00982     }
00983     // Something Else - aka "Blank"
00984     return 1;
00985 }
00986 
00987 CFStringRef GetPrintStringFromIndex(int index)
00988 {
00989     switch (index)
00990     {
00991         case 2: // title
00992             return CFSTR("&T");
00993         case 3: // url
00994             return CFSTR("&U");
00995         case 4: // date/time
00996             return CFSTR("&D");
00997         case 5: // Page #
00998             return CFSTR("&P");
00999         case 6: // Page # of #
01000             return CFSTR("&PT");
01001         default: // blank OR custom (need to implement custom)
01002             return CFSTR("");
01003     }
01004  }
01005 
01006 /* END OF SOURCE */