Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsDeviceContextSpecPh Class Reference

#include <nsDeviceContextSpecPh.h>

Inheritance diagram for nsDeviceContextSpecPh:
Inheritance graph
[legend]
Collaboration diagram for nsDeviceContextSpecPh:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsDeviceContextSpecPh ()
NS_DECL_ISUPPORTS NS_IMETHOD Init (nsIWidget *aWidget, nsIPrintSettings *aPrintSettings, PRBool aQuiet)
PpPrintContext_t * GetPrintContext ()

Protected Member Functions

virtual ~nsDeviceContextSpecPh ()

Protected Attributes

PpPrintContext_t * mPC

Detailed Description

Definition at line 46 of file nsDeviceContextSpecPh.h.


Constructor & Destructor Documentation

Definition at line 61 of file nsDeviceContextSpecPh.cpp.

{
       mPC = PpCreatePC();
}

Definition at line 66 of file nsDeviceContextSpecPh.cpp.

{
       PpPrintReleasePC(mPC);
}

Member Function Documentation

Definition at line 222 of file nsDeviceContextSpecPh.cpp.

{
       return (mPC);
}
NS_IMETHODIMP nsDeviceContextSpecPh::Init ( nsIWidget aWidget,
nsIPrintSettings aPrintSettings,
PRBool  aQuiet 
)

Definition at line 77 of file nsDeviceContextSpecPh.cpp.

{
       nsresult rv = NS_OK;
       PRUnichar *printer        = nsnull;
       PRBool silent;

       aPS->GetPrinterName(&printer);
       aPS->GetPrintSilent( &silent );

       if( printer ) {
              int res = 111;
              NS_ConvertUCS2toUTF8 pname(printer);
              if( !strcmp( pname.get(), "<Preview>" ) ) {
                     char preview = 1;
                     PpSetPC( mPC, Pp_PC_DO_PREVIEW, &preview, 0 );
                     }
              else res = PpLoadPrinter( mPC, pname.get() );
              }
       else PpLoadDefaultPrinter( mPC );

       if( !silent ) 
       {
              PRBool tofile = PR_FALSE;
              PRUnichar *printfile = nsnull;
              PRInt32 copies = 1;
              PRBool color = PR_FALSE;
              PRInt32 orientation = nsIPrintSettings::kPortraitOrientation;
              PRBool reversed = PR_FALSE;

              aPS->GetPrintToFile(&tofile);
              if( tofile == PR_TRUE ) {
                     aPS->GetToFileName(&printfile);
                     if( printfile ) PpSetPC( mPC, Pp_PC_FILENAME, NS_ConvertUCS2toUTF8(printfile).get(), 0 );
                     }

              aPS->GetNumCopies(&copies);
              char pcopies = ( char ) copies;
              PpSetPC( mPC, Pp_PC_COPIES, (void *) &pcopies, 0 );

              aPS->GetPrintInColor(&color);
              char ink = color == PR_TRUE ? Pp_COLOR_CMYK : Pp_COLOR_BW;
              PpSetPC( mPC, Pp_PC_INKTYPE, &ink, 0 );

              aPS->GetOrientation(&orientation);
              char paper_orientation = orientation == nsIPrintSettings::kPortraitOrientation ? 0 : 1;
              PpSetPC( mPC, Pp_PC_ORIENTATION, &paper_orientation, 0 );

              aPS->GetPrintReversed(&reversed);
              char rev = reversed == PR_TRUE ? 1 : 0;
              PpSetPC( mPC, Pp_PC_REVERSED, &rev, 0 );

              double margin_top, margin_left, margin_right, margin_bottom;
              PhRect_t rmargin = { { 0, 0 }, { 0, 0 } };
              aPS->GetMarginTop( &margin_top );
              aPS->GetMarginLeft( &margin_left );
              aPS->GetMarginRight( &margin_right );
              aPS->GetMarginBottom( &margin_bottom );


              PRInt16 unit;
              double width, height;
              aPS->GetPaperSizeUnit(&unit);
              aPS->GetPaperWidth(&width);
              aPS->GetPaperHeight(&height);

              PhDim_t *pdim, dim;
              PpGetPC( mPC, Pp_PC_PAPER_SIZE, &pdim );
              dim = *pdim;
              if( unit == nsIPrintSettings::kPaperSizeInches ) {
                dim.w  = width * 1000;
                dim.h = height * 1000;

                     rmargin.ul.x = margin_left * 1000;
                     rmargin.ul.y = margin_top * 1000;
                     rmargin.lr.x = margin_right * 1000;
                     rmargin.lr.y = margin_bottom * 1000;
                     }
              else if( unit == nsIPrintSettings::kPaperSizeMillimeters ) {
                     dim.w = short(NS_TWIPS_TO_INCHES(NS_MILLIMETERS_TO_TWIPS(float(width*1000))));
                     dim.h = short(NS_TWIPS_TO_INCHES(NS_MILLIMETERS_TO_TWIPS(float(height*1000))));

                     rmargin.ul.x = short(NS_TWIPS_TO_INCHES(NS_MILLIMETERS_TO_TWIPS(float(margin_left*1000))));
                     rmargin.ul.y = short(NS_TWIPS_TO_INCHES(NS_MILLIMETERS_TO_TWIPS(float(margin_top*1000))));
                     rmargin.lr.x = short(NS_TWIPS_TO_INCHES(NS_MILLIMETERS_TO_TWIPS(float(margin_right*1000))));
                     rmargin.lr.y = short(NS_TWIPS_TO_INCHES(NS_MILLIMETERS_TO_TWIPS(float(margin_bottom*1000))));
                     }

              PpSetPC( mPC, Pp_PC_PAPER_SIZE, &dim, 0 );
              PpSetPC( mPC, Pp_PC_NONPRINT_MARGINS, &rmargin, 0 );
  }
       else { /* silent is set - used when the call is comming from the embedded version */
              PRInt32 p;
              aPS->GetEndPageRange( &p );
              PpPrintReleasePC(mPC);
              mPC = ( PpPrintContext_t *) p;

              /* set the print frame / BG colors and images settings, according to the Pt_ARG_WEB_OPTION setting */
              nsresult res;
              nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &res));

    PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone;
    aPS->GetHowToEnableFrameUI(&howToEnableFrameUI);

    if( howToEnableFrameUI == nsIPrintSettings::kFrameEnableAll ||
        howToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach )
      {
      /* we have frames and we have a selected frame already only if kFrameEnableAll */
      /* look at the Pt_ARG_WEB_OPTION related to this */

      char *printFrame = NULL;
                     if( prefs ) prefs->CopyCharPref( "user.print.print_frame", &printFrame );

                     if( printFrame ) {
                            if( !stricmp( printFrame, "print_frame_as_is" ) ) 
           aPS->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
                            else if( !stricmp( printFrame, "print_frame_all" ) ) 
           aPS->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
                            else if( !stricmp( printFrame, "print_frame_selected" ) )  {
          if( howToEnableFrameUI == nsIPrintSettings::kFrameEnableAll )
            aPS->SetPrintFrameType(nsIPrintSettings::kSelectedFrame);
          else /* if no frame is selected, use the kFramesAsIs */
            aPS->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
                                          }
              }
              }

              char *SetPrintBGColors = NULL, *SetPrintBGImages = NULL;
              if( prefs ) prefs->CopyCharPref( "user.print.SetPrintBGColors", &SetPrintBGColors );
              if( prefs ) prefs->CopyCharPref( "user.print.SetPrintBGImages", &SetPrintBGImages );

       if( SetPrintBGColors && !stricmp( SetPrintBGColors, "true" ) )
                     aPS->SetPrintBGColors( PR_TRUE );
              else aPS->SetPrintBGColors( PR_FALSE );

       if( SetPrintBGImages && !stricmp( SetPrintBGImages, "true" ) )
         aPS->SetPrintBGImages( PR_TRUE );
       else aPS->SetPrintBGImages( PR_FALSE );
              }

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

PpPrintContext_t* nsDeviceContextSpecPh::mPC [protected]

Definition at line 58 of file nsDeviceContextSpecPh.h.


The documentation for this class was generated from the following files: