Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsPrintDialogUtil.cpp File Reference
#include "prmem.h"
#include "plstr.h"
#include <windows.h>
#include <tchar.h>
#include <unknwn.h>
#include <commdlg.h>
#include "nsIWebBrowserPrint.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsIWidget.h"
#include "nsIPrintSettings.h"
#include "nsIPrintSettingsWin.h"
#include "nsUnitConversion.h"
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsRect.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsCRT.h"
#include "prenv.h"
#include <winspool.h>
#include "nsIStringBundle.h"
#include "nsNativeCharsetUtils.h"
#include <dlgs.h>

Go to the source code of this file.

Classes

struct  NativePaperSizes
struct  PropKeyInfo

Defines

#define GetPrintDlgExQuoted   "PrintDlgExA"
#define PRINTDLG_PROPERTIES   "chrome://global/locale/printdialog.properties"

Functions

static NS_DEFINE_IID (kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID)
static NS_DEFINE_CID (kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID)
static PRBool CheckForExtendedDialog ()
static void MapPaperSizeToNativeEnum (LPDEVMODE aDevMode, PRInt16 aType, double aW, double aH)
static void SetupDevModeFromSettings (LPDEVMODE aDevMode, nsIPrintSettings *aPrintSettings)
static nsresult SetPrintSettingsFromDevMode (nsIPrintSettings *aPrintSettings, LPDEVMODE aDevMode)
static nsresult GetLocalizedBundle (const char *aPropFileName, nsIStringBundle **aStrBundle)
static nsresult GetLocalizedString (nsIStringBundle *aStrBundle, const char *aKey, nsString &oVal)
static void SetTextOnWnd (HWND aControl, const nsString &aStr)
static void SetText (HWND aParent, UINT aId, nsIStringBundle *aStrBundle, const char *aKey)
static void SetRadio (HWND aParent, UINT aId, PRBool aIsSet, PRBool isEnabled=PR_TRUE)
static void SetRadioOfGroup (HWND aDlg, int aRadId)
static void GetLocalRect (HWND aWnd, RECT &aRect, HWND aParent)
static void Show (HWND aWnd, PRBool bState)
static HWND CreateControl (LPCTSTR aType, DWORD aStyle, HINSTANCE aHInst, HWND aHdlg, int aId, const nsAString &aStr, const nsRect &aRect)
static HWND CreateRadioBtn (HINSTANCE aHInst, HWND aHdlg, int aId, const char *aStr, const nsRect &aRect)
static HWND CreateGroupBox (HINSTANCE aHInst, HWND aHdlg, int aId, const nsAString &aStr, const nsRect &aRect)
static void InitializeExtendedDialog (HWND hdlg, PRInt16 aHowToEnableFrameUI)
static UINT CALLBACK PrintHookProc (HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
static HGLOBAL CreateGlobalDevModeAndInit (LPCTSTR aPrintName, nsIPrintSettings *aPS)
static PRUnicharGetDefaultPrinterNameFromGlobalPrinters ()
static PRBool ShouldExtendPrintDialog ()
static nsresult ShowNativePrintDialog (HWND aHWnd, nsIPrintSettings *aPrintSettings)
static void PrepareForPrintDialog (nsIWebBrowserPrint *aWebBrowserPrint, nsIPrintSettings *aPS)
nsresult NativeShowPrintDialog (HWND aHWnd, nsIWebBrowserPrint *aWebBrowserPrint, nsIPrintSettings *aPrintSettings)

Variables

static const char * kAsLaidOutOnScreenStr = "As &laid out on the screen"
static const char * kTheSelectedFrameStr = "The selected &frame"
static const char * kEachFrameSeparately = "&Each frame separately"
static UINT gFrameSelectedRadioBtn = 0
static PRPackedBool gDialogWasExtended = PR_FALSE
static HWND gParentWnd = NULL
const NativePaperSizes kPaperSizes []
const PRInt32 kNumPaperSizes = 41
static PropKeyInfo gAllPropKeys []

Class Documentation

struct NativePaperSizes

Definition at line 131 of file nsPrintDialogUtil.cpp.

Class Members
double mHeight
PRBool mIsInches
short mPaperSize
double mWidth
struct PropKeyInfo

Definition at line 464 of file nsPrintDialogUtil.cpp.

Class Members
long mKeyId
char * mKeyStr

Define Documentation

#define GetPrintDlgExQuoted   "PrintDlgExA"

Definition at line 107 of file nsPrintDialogUtil.cpp.

#define PRINTDLG_PROPERTIES   "chrome://global/locale/printdialog.properties"

Definition at line 124 of file nsPrintDialogUtil.cpp.


Function Documentation

static PRBool CheckForExtendedDialog ( ) [static]

Definition at line 186 of file nsPrintDialogUtil.cpp.

{
#ifdef MOZ_REQUIRE_CURRENT_SDK
  HMODULE lib = GetModuleHandle("comdlg32.dll");
  if ( lib ) {
    return GetProcAddress(lib, GetPrintDlgExQuoted);
  }
#endif
  return PR_FALSE;
}

Here is the caller graph for this function:

static HWND CreateControl ( LPCTSTR  aType,
DWORD  aStyle,
HINSTANCE  aHInst,
HWND  aHdlg,
int  aId,
const nsAString &  aStr,
const nsRect aRect 
) [static]

Definition at line 513 of file nsPrintDialogUtil.cpp.

{
  nsCAutoString str;
  if (NS_FAILED(NS_CopyUnicodeToNative(aStr, str)))
    return NULL;

  HWND hWnd = ::CreateWindow (aType, str.get(),
                              WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | aStyle,
                              aRect.x, aRect.y, aRect.width, aRect.height,
                              (HWND)aHdlg, (HMENU)aId,
                              aHInst, NULL);
  if (hWnd == NULL) return NULL;

  // get the native font for the dialog and 
  // set it into the new control
  HFONT hFont = (HFONT)::SendMessage(aHdlg, WM_GETFONT, (WPARAM)0, (LPARAM)0);
  if (hFont != NULL) {
    ::SendMessage(hWnd, WM_SETFONT, (WPARAM) hFont, (LPARAM)0);
  }
  return hWnd;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HGLOBAL CreateGlobalDevModeAndInit ( LPCTSTR  aPrintName,
nsIPrintSettings aPS 
) [static]

Definition at line 759 of file nsPrintDialogUtil.cpp.

{
  HGLOBAL hGlobalDevMode = NULL;

  nsresult rv = NS_ERROR_FAILURE;
  HANDLE hPrinter = NULL;
  // const cast kludge for silly Win32 api's
  LPTSTR printName = NS_CONST_CAST(char*, aPrintName);
  BOOL status = ::OpenPrinter(printName, &hPrinter, NULL);
  if (status) {

    LPDEVMODE   pNewDevMode;
    DWORD       dwNeeded, dwRet;

    // Get the buffer size
    dwNeeded = ::DocumentProperties(gParentWnd, hPrinter, printName, NULL, NULL, 0);
    if (dwNeeded == 0) {
      return NULL;
    }

    // Allocate a buffer of the correct size.
    pNewDevMode = (LPDEVMODE)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, dwNeeded);
    if (!pNewDevMode) return NULL;

    hGlobalDevMode = (HGLOBAL)::GlobalAlloc(GHND, dwNeeded);
    if (!hGlobalDevMode) {
      ::HeapFree(::GetProcessHeap(), 0, pNewDevMode);
      return NULL;
    }

    dwRet = ::DocumentProperties(gParentWnd, hPrinter, printName, pNewDevMode, NULL, DM_OUT_BUFFER);

    if (dwRet != IDOK) {
      ::HeapFree(::GetProcessHeap(), 0, pNewDevMode);
      ::GlobalFree(hGlobalDevMode);
      ::ClosePrinter(hPrinter);
      return NULL;
    }

    // Lock memory and copy contents from DEVMODE (current printer)
    // to Global Memory DEVMODE
    LPDEVMODE devMode = (DEVMODE *)::GlobalLock(hGlobalDevMode);
    if (devMode) {
      memcpy(devMode, pNewDevMode, dwNeeded);
      // Initialize values from the PrintSettings
      SetupDevModeFromSettings(devMode, aPS);

      // Sets back the changes we made to the DevMode into the Printer Driver
      dwRet = ::DocumentProperties(gParentWnd, hPrinter, printName, devMode, devMode, DM_IN_BUFFER | DM_OUT_BUFFER);
      if (dwRet != IDOK) {
        ::GlobalUnlock(hGlobalDevMode);
        ::GlobalFree(hGlobalDevMode);
        ::HeapFree(::GetProcessHeap(), 0, pNewDevMode);
        ::ClosePrinter(hPrinter);
         return NULL;
      }

      ::GlobalUnlock(hGlobalDevMode);
    } else {
      ::GlobalFree(hGlobalDevMode);
      hGlobalDevMode = NULL;
    }

    ::HeapFree(::GetProcessHeap(), 0, pNewDevMode);

    ::ClosePrinter(hPrinter);

  } else {
    return NULL;
  }

  return hGlobalDevMode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HWND CreateGroupBox ( HINSTANCE  aHInst,
HWND  aHdlg,
int  aId,
const nsAString &  aStr,
const nsRect aRect 
) [static]

Definition at line 556 of file nsPrintDialogUtil.cpp.

{
  return CreateControl("BUTTON", BS_GROUPBOX, aHInst, aHdlg, aId, aStr, aRect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HWND CreateRadioBtn ( HINSTANCE  aHInst,
HWND  aHdlg,
int  aId,
const char *  aStr,
const nsRect aRect 
) [static]

Definition at line 543 of file nsPrintDialogUtil.cpp.

{
  nsString cStr;
  cStr.AssignWithConversion(aStr);
  return CreateControl("BUTTON", BS_RADIOBUTTON, aHInst, aHdlg, aId, cStr, aRect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 835 of file nsPrintDialogUtil.cpp.

{
  nsresult rv;
  PRUnichar * printerName = nsnull;
  nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService(kPrinterEnumeratorCID, &rv);
  if (prtEnum) {
    prtEnum->GetDefaultPrinterName(&printerName);
  }
  return printerName;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult GetLocalizedBundle ( const char *  aPropFileName,
nsIStringBundle **  aStrBundle 
) [static]

Definition at line 363 of file nsPrintDialogUtil.cpp.

{
  NS_ENSURE_ARG_POINTER(aPropFileName);
  NS_ENSURE_ARG_POINTER(aStrBundle);

  nsresult rv;
  nsCOMPtr<nsIStringBundle> bundle;
  

  // Create bundle
  nsCOMPtr<nsIStringBundleService> stringService = 
    do_GetService(kStringBundleServiceCID, &rv);
  if (NS_SUCCEEDED(rv) && stringService) {
    rv = stringService->CreateBundle(aPropFileName, aStrBundle);
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult GetLocalizedString ( nsIStringBundle aStrBundle,
const char *  aKey,
nsString oVal 
) [static]

Definition at line 385 of file nsPrintDialogUtil.cpp.

{
  NS_ENSURE_ARG_POINTER(aStrBundle);
  NS_ENSURE_ARG_POINTER(aKey);

  // Determine default label from string bundle
  nsXPIDLString valUni;
  nsAutoString key; 
  key.AssignWithConversion(aKey);
  nsresult rv = aStrBundle->GetStringFromName(key.get(), getter_Copies(valUni));
  if (NS_SUCCEEDED(rv) && valUni) {
    oVal.Assign(valUni);
  } else {
    oVal.Truncate();
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void GetLocalRect ( HWND  aWnd,
RECT &  aRect,
HWND  aParent 
) [static]

Definition at line 484 of file nsPrintDialogUtil.cpp.

{
  RECT wr;
  ::GetWindowRect(aParent, &wr);

  RECT cr;
  ::GetClientRect(aParent, &cr);

  ::GetWindowRect(aWnd, &aRect);

  int borderH = (wr.bottom-wr.top+1) - (cr.bottom-cr.top+1);
  int borderW = ((wr.right-wr.left+1) - (cr.right-cr.left+1))/2;
  aRect.top    -= wr.top+borderH-borderW;
  aRect.left   -= wr.left+borderW;
  aRect.right  -= wr.left+borderW;
  aRect.bottom -= wr.top+borderH-borderW;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void InitializeExtendedDialog ( HWND  hdlg,
PRInt16  aHowToEnableFrameUI 
) [static]

Definition at line 567 of file nsPrintDialogUtil.cpp.

{
  // Localize the new controls in the print dialog
  nsCOMPtr<nsIStringBundle> strBundle;
  if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) {
    PRInt32 i = 0;
    while (gAllPropKeys[i].mKeyStr != NULL) {
      SetText(hdlg, gAllPropKeys[i].mKeyId, strBundle, gAllPropKeys[i].mKeyStr);
      i++;
    }
  }

  // Set up radio buttons
  if (aHowToEnableFrameUI == nsIPrintSettings::kFrameEnableAll) {
    SetRadio(hdlg, rad4, PR_FALSE);  
    SetRadio(hdlg, rad5, PR_TRUE); 
    SetRadio(hdlg, rad6, PR_FALSE);
    // set default so user doesn't have to actually press on it
    gFrameSelectedRadioBtn = rad5;

  } else if (aHowToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) {
    SetRadio(hdlg, rad4, PR_FALSE);  
    SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); 
    SetRadio(hdlg, rad6, PR_TRUE);
    // set default so user doesn't have to actually press on it
    gFrameSelectedRadioBtn = rad6;


  } else {  // nsIPrintSettings::kFrameEnableNone
    // we are using this function to disabe the group box
    SetRadio(hdlg, grp3, PR_FALSE, PR_FALSE); 
    // now disable radiobuttons
    SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); 
    SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); 
    SetRadio(hdlg, rad6, PR_FALSE, PR_FALSE); 
  }

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void MapPaperSizeToNativeEnum ( LPDEVMODE  aDevMode,
PRInt16  aType,
double  aW,
double  aH 
) [static]

Definition at line 200 of file nsPrintDialogUtil.cpp.

{

#ifdef DEBUG_rods
  BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION;
  BOOL doingPaperSize   = aDevMode->dmFields & DM_PAPERSIZE;
  BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH;
  BOOL doingPaperWidth  = aDevMode->dmFields & DM_PAPERWIDTH;
#endif

  const double kThreshold = 0.05;
  PRBool foundEnum = PR_FALSE;
  for (PRInt32 i=0;i<kNumPaperSizes;i++) {
    double width  = kPaperSizes[i].mWidth;
    double height = kPaperSizes[i].mHeight;
    if (aW < width+kThreshold && aW > width-kThreshold && 
        aH < height+kThreshold && aH > height-kThreshold) {
      aDevMode->dmPaperSize = kPaperSizes[i].mPaperSize;
      aDevMode->dmFields &= ~DM_PAPERLENGTH;
      aDevMode->dmFields &= ~DM_PAPERWIDTH;
      aDevMode->dmFields |= DM_PAPERSIZE;
      return;
    }
  }

  short width  = 0;
  short height = 0;
  if (aType == nsIPrintSettings::kPaperSizeInches) {
    width  = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aW))) / 10);
    height = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aH))) / 10);

  } else if (aType == nsIPrintSettings::kPaperSizeMillimeters) {
    width  = short(aW / 10.0);
    height = short(aH / 10.0);
  } else {
    return; // don't set anything
  }

  // width and height is in 
  aDevMode->dmPaperSize   = 0;
  aDevMode->dmPaperWidth  = width;
  aDevMode->dmPaperLength = height;

  aDevMode->dmFields |= DM_PAPERSIZE;
  aDevMode->dmFields |= DM_PAPERLENGTH;
  aDevMode->dmFields |= DM_PAPERWIDTH;
}

Here is the caller graph for this function:

nsresult NativeShowPrintDialog ( HWND  aHWnd,
nsIWebBrowserPrint aWebBrowserPrint,
nsIPrintSettings aPrintSettings 
)

Definition at line 1491 of file nsPrintDialogUtil.cpp.

{
  nsresult rv = NS_ERROR_FAILURE;

  PrepareForPrintDialog(aWebBrowserPrint, aPrintSettings);

#ifdef MOZ_REQUIRE_CURRENT_SDK
  if (CheckForExtendedDialog()) {
    rv = ShowNativePrintDialogEx(aHWnd, aPrintSettings);
  } else {
    rv = ShowNativePrintDialog(aHWnd, aPrintSettings);
  }
#else
  rv = ShowNativePrintDialog(aHWnd, aPrintSettings);
#endif

  return rv;
}
static NS_DEFINE_CID ( kStringBundleServiceCID  ,
NS_STRINGBUNDLESERVICE_CID   
) [static]
static NS_DEFINE_IID ( kPrinterEnumeratorCID  ,
NS_PRINTER_ENUMERATOR_CID   
) [static]
static void PrepareForPrintDialog ( nsIWebBrowserPrint aWebBrowserPrint,
nsIPrintSettings aPS 
) [static]

Definition at line 1457 of file nsPrintDialogUtil.cpp.

{
  NS_ASSERTION(aWebBrowserPrint, "Can't be null");
  NS_ASSERTION(aPS, "Can't be null");

  PRBool isFramesetDocument;
  PRBool isFramesetFrameSelected;
  PRBool isIFrameSelected;
  PRBool isRangeSelection;

  aWebBrowserPrint->GetIsFramesetDocument(&isFramesetDocument);
  aWebBrowserPrint->GetIsFramesetFrameSelected(&isFramesetFrameSelected);
  aWebBrowserPrint->GetIsIFrameSelected(&isIFrameSelected);
  aWebBrowserPrint->GetIsRangeSelection(&isRangeSelection);

  // Setup print options for UI
  if (isFramesetDocument) {
    if (isFramesetFrameSelected) {
      aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll);
    } else {
      aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach);
    }
  } else {
    aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone);
  }

  // Now determine how to set up the Frame print UI
  aPS->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isRangeSelection || isIFrameSelected);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static UINT CALLBACK PrintHookProc ( HWND  hdlg,
UINT  uiMsg,
WPARAM  wParam,
LPARAM  lParam 
) [static]

Definition at line 609 of file nsPrintDialogUtil.cpp.

{

  if (uiMsg == WM_COMMAND) {
    UINT id = LOWORD(wParam);
    if (id == rad4 || id == rad5 || id == rad6) {
      gFrameSelectedRadioBtn = id;
      SetRadioOfGroup(hdlg, id);
    }

  } else if (uiMsg == WM_INITDIALOG) {
    PRINTDLG * printDlg = (PRINTDLG *)lParam;
    if (printDlg == NULL) return 0L;

    PRInt16 howToEnableFrameUI = (PRInt16)printDlg->lCustData;

    HINSTANCE hInst = (HINSTANCE)::GetWindowLong(hdlg, GWL_HINSTANCE);
    if (hInst == NULL) return 0L;

    // Start by getting the local rects of several of the controls
    // so we can calculate where the new controls are
    HWND wnd = ::GetDlgItem(hdlg, grp1);
    if (wnd == NULL) return 0L;
    RECT dlgRect;
    GetLocalRect(wnd, dlgRect, hdlg);

    wnd = ::GetDlgItem(hdlg, rad1); // this is the top control "All"
    if (wnd == NULL) return 0L;
    RECT rad1Rect;
    GetLocalRect(wnd, rad1Rect, hdlg);

    wnd = ::GetDlgItem(hdlg, rad2); // this is the bottom control "Selection"
    if (wnd == NULL) return 0L;
    RECT rad2Rect;
    GetLocalRect(wnd, rad2Rect, hdlg);

    wnd = ::GetDlgItem(hdlg, rad3); // this is the middle control "Pages"
    if (wnd == NULL) return 0L;
    RECT rad3Rect;
    GetLocalRect(wnd, rad3Rect, hdlg);

    HWND okWnd = ::GetDlgItem(hdlg, IDOK);
    if (okWnd == NULL) return 0L;
    RECT okRect;
    GetLocalRect(okWnd, okRect, hdlg);

    wnd = ::GetDlgItem(hdlg, grp4); // this is the "Print range" groupbox
    if (wnd == NULL) return 0L;
    RECT prtRect;
    GetLocalRect(wnd, prtRect, hdlg);


    // calculate various different "gaps" for layout purposes

    int rbGap     = rad3Rect.top - rad1Rect.bottom;     // gap between radiobtns
    int grpBotGap = dlgRect.bottom - rad2Rect.bottom;   // gap from bottom rb to bottom of grpbox
    int grpGap    = dlgRect.top - prtRect.bottom ;      // gap between group boxes
    int top       = dlgRect.bottom + grpGap;            
    int radHgt    = rad1Rect.bottom - rad1Rect.top + 1; // top of new group box
    int y         = top+(rad1Rect.top-dlgRect.top);     // starting pos of first radio
    int rbWidth   = dlgRect.right - rad1Rect.left - 5;  // measure from rb left to the edge of the groupbox
                                                        // (5 is arbitrary)
    nsRect rect;

    // Create and position the radio buttons
    //
    // If any one control cannot be created then 
    // hide the others and bail out
    //
    rect.SetRect(rad1Rect.left, y, rbWidth,radHgt);
    HWND rad4Wnd = CreateRadioBtn(hInst, hdlg, rad4, kAsLaidOutOnScreenStr, rect);
    if (rad4Wnd == NULL) return 0L;
    y += radHgt + rbGap;

    rect.SetRect(rad1Rect.left, y, rbWidth, radHgt);
    HWND rad5Wnd = CreateRadioBtn(hInst, hdlg, rad5, kTheSelectedFrameStr, rect);
    if (rad5Wnd == NULL) {
      Show(rad4Wnd, FALSE); // hide
      return 0L;
    }
    y += radHgt + rbGap;

    rect.SetRect(rad1Rect.left, y, rbWidth, radHgt);
    HWND rad6Wnd = CreateRadioBtn(hInst, hdlg, rad6, kEachFrameSeparately, rect);
    if (rad6Wnd == NULL) {
      Show(rad4Wnd, FALSE); // hide
      Show(rad5Wnd, FALSE); // hide
      return 0L;
    }
    y += radHgt + grpBotGap;

    // Create and position the group box
    rect.SetRect (dlgRect.left, top, dlgRect.right-dlgRect.left+1, y-top+1);
    HWND grpBoxWnd = CreateGroupBox(hInst, hdlg, grp3, NS_LITERAL_STRING("Print Frame"), rect);
    if (grpBoxWnd == NULL) {
      Show(rad4Wnd, FALSE); // hide
      Show(rad5Wnd, FALSE); // hide
      Show(rad6Wnd, FALSE); // hide
      return 0L;
    }

    // Here we figure out the old height of the dlg
    // then figure it's gap from the old grpbx to the bottom
    // then size the dlg
    RECT pr, cr; 
    ::GetWindowRect(hdlg, &pr);
    ::GetClientRect(hdlg, &cr);

    int dlgHgt = (cr.bottom - cr.top) + 1;
    int bottomGap = dlgHgt - okRect.bottom;
    pr.bottom += (dlgRect.bottom-dlgRect.top) + grpGap + 1 - (dlgHgt-dlgRect.bottom) + bottomGap;

    ::SetWindowPos(hdlg, NULL, pr.left, pr.top, pr.right-pr.left+1, pr.bottom-pr.top+1, 
                   SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER);

    // figure out the new height of the dialog
    ::GetClientRect(hdlg, &cr);
    dlgHgt = (cr.bottom - cr.top) + 1;
 
    // Reposition the OK and Cancel btns
    int okHgt = okRect.bottom - okRect.top + 1;
    ::SetWindowPos(okWnd, NULL, okRect.left, dlgHgt-bottomGap-okHgt, 0, 0, 
                   SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER);

    HWND cancelWnd = ::GetDlgItem(hdlg, IDCANCEL);
    if (cancelWnd == NULL) return 0L;

    RECT cancelRect;
    GetLocalRect(cancelWnd, cancelRect, hdlg);
    int cancelHgt = cancelRect.bottom - cancelRect.top + 1;
    ::SetWindowPos(cancelWnd, NULL, cancelRect.left, dlgHgt-bottomGap-cancelHgt, 0, 0, 
                   SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER);

    // localize and initialize the groupbox and radiobuttons
    InitializeExtendedDialog(hdlg, howToEnableFrameUI);

    // Looks like we were able to extend the dialog
    gDialogWasExtended = PR_TRUE;
  }
  return 0L;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult SetPrintSettingsFromDevMode ( nsIPrintSettings aPrintSettings,
LPDEVMODE  aDevMode 
) [static]

Definition at line 296 of file nsPrintDialogUtil.cpp.

{
  if (aPrintSettings == nsnull) {
    return NS_ERROR_FAILURE;
  }

  aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE);
  if (aDevMode->dmFields & DM_ORIENTATION) {
    PRInt32 orientation  = aDevMode->dmOrientation == DMORIENT_PORTRAIT?
                           nsIPrintSettings::kPortraitOrientation:nsIPrintSettings::kLandscapeOrientation;
    aPrintSettings->SetOrientation(orientation);
  }

  // Setup Number of Copies
  if (aDevMode->dmFields & DM_COPIES) {
    aPrintSettings->SetNumCopies(PRInt32(aDevMode->dmCopies));
  }

  // Scaling
  // Since we do the scaling, grab their value and reset back to 100
  if (aDevMode->dmFields & DM_SCALE) {
    double origScale = 1.0;
    aPrintSettings->GetScaling(&origScale);
    double scale = double(aDevMode->dmScale) / 100.0f;
    if (origScale == 1.0 || scale != 1.0) {
      aPrintSettings->SetScaling(scale);
    }
    aDevMode->dmScale = 100;
    // To turn this on you must change where the mPrt->mShrinkToFit is being set in the DocumentViewer
    //aPrintSettings->SetShrinkToFit(PR_FALSE);
  }

  if (aDevMode->dmFields & DM_PAPERSIZE) {
    aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeNativeData);
    aPrintSettings->SetPaperData(aDevMode->dmPaperSize);
    for (PRInt32 i=0;i<kNumPaperSizes;i++) {
      if (kPaperSizes[i].mPaperSize == aDevMode->dmPaperSize) {
        aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches?nsIPrintSettings::kPaperSizeInches:nsIPrintSettings::kPaperSizeMillimeters);
        break;
      }
    }

  } else if (aDevMode->dmFields & DM_PAPERLENGTH && aDevMode->dmFields & DM_PAPERWIDTH) {
    PRBool found = PR_FALSE;
    for (PRInt32 i=0;i<kNumPaperSizes;i++) {
      if (kPaperSizes[i].mPaperSize == aDevMode->dmPaperSize) {
        aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
        aPrintSettings->SetPaperWidth(kPaperSizes[i].mWidth);
        aPrintSettings->SetPaperHeight(kPaperSizes[i].mHeight);
        aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches?nsIPrintSettings::kPaperSizeInches:nsIPrintSettings::kPaperSizeMillimeters);
        found = PR_TRUE;
        break;
      }
    }
    if (!found) {
      return NS_ERROR_FAILURE;
    }
  } else {
    return NS_ERROR_FAILURE;
  }
  return NS_OK;
}

Here is the caller graph for this function:

static void SetRadio ( HWND  aParent,
UINT  aId,
PRBool  aIsSet,
PRBool  isEnabled = PR_TRUE 
) [static]

Definition at line 432 of file nsPrintDialogUtil.cpp.

{
  HWND wnd = ::GetDlgItem (aParent, aId);
  if (!wnd) {
    return;
  }
  if (!isEnabled) {
    ::EnableWindow(wnd, FALSE);
    return;
  }
  ::EnableWindow(wnd, TRUE);
  ::SendMessage(wnd, BM_SETCHECK, (WPARAM)aIsSet, (LPARAM)0);
}

Here is the caller graph for this function:

static void SetRadioOfGroup ( HWND  aDlg,
int  aRadId 
) [static]

Definition at line 450 of file nsPrintDialogUtil.cpp.

{
  int radioIds[] = {rad4, rad5, rad6};
  int numRads = 3;

  for (int i=0;i<numRads;i++) {
    HWND radWnd = ::GetDlgItem(aDlg, radioIds[i]);
    if (radWnd != NULL) {
      ::SendMessage(radWnd, BM_SETCHECK, (WPARAM)(radioIds[i] == aRadId), (LPARAM)0);
    }
  }
}

Here is the caller graph for this function:

static void SetText ( HWND  aParent,
UINT  aId,
nsIStringBundle aStrBundle,
const char *  aKey 
) [static]

Definition at line 415 of file nsPrintDialogUtil.cpp.

{
  HWND wnd = GetDlgItem (aParent, aId);
  if (!wnd) {
    return;
  }
  nsAutoString str;
  nsresult rv = GetLocalizedString(aStrBundle, aKey, str);
  if (NS_SUCCEEDED(rv)) {
    SetTextOnWnd(wnd, str);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void SetTextOnWnd ( HWND  aControl,
const nsString aStr 
) [static]

Definition at line 405 of file nsPrintDialogUtil.cpp.

{
  nsCAutoString text;
  if (NS_SUCCEEDED(NS_CopyUnicodeToNative(aStr, text))) {
    ::SetWindowText(aControl, text.get());
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void SetupDevModeFromSettings ( LPDEVMODE  aDevMode,
nsIPrintSettings aPrintSettings 
) [static]

Definition at line 255 of file nsPrintDialogUtil.cpp.

{
  // Setup paper size
  if (aPrintSettings) {
    PRInt16 type;
    aPrintSettings->GetPaperSizeType(&type);
    if (type == nsIPrintSettings::kPaperSizeNativeData) {
      PRInt16 paperEnum;
      aPrintSettings->GetPaperData(&paperEnum);
      aDevMode->dmPaperSize = paperEnum;
      aDevMode->dmFields &= ~DM_PAPERLENGTH;
      aDevMode->dmFields &= ~DM_PAPERWIDTH;
      aDevMode->dmFields |= DM_PAPERSIZE;
    } else {
      PRInt16 unit;
      double width, height;
      aPrintSettings->GetPaperSizeUnit(&unit);
      aPrintSettings->GetPaperWidth(&width);
      aPrintSettings->GetPaperHeight(&height);
      MapPaperSizeToNativeEnum(aDevMode, unit, width, height);
    }

    // Setup Orientation
    PRInt32 orientation;
    aPrintSettings->GetOrientation(&orientation);
    aDevMode->dmOrientation = orientation == nsIPrintSettings::kPortraitOrientation?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE;
    aDevMode->dmFields |= DM_ORIENTATION;

    // Setup Number of Copies
    PRInt32 copies;
    aPrintSettings->GetNumCopies(&copies);
    aDevMode->dmCopies = copies;
    aDevMode->dmFields |= DM_COPIES;

  }

}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool ShouldExtendPrintDialog ( ) [static]

Definition at line 848 of file nsPrintDialogUtil.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIPrefService> prefs =
    do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, PR_TRUE);
  nsCOMPtr<nsIPrefBranch> prefBranch;
  rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
  NS_ENSURE_SUCCESS(rv, PR_TRUE);

  PRBool result;
  rv = prefBranch->GetBoolPref("print.extend_native_print_dialog", &result);
  NS_ENSURE_SUCCESS(rv, PR_TRUE);
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void Show ( HWND  aWnd,
PRBool  bState 
) [static]

Definition at line 504 of file nsPrintDialogUtil.cpp.

{
  if (aWnd) {
    ::ShowWindow(aWnd, bState?SW_SHOW:SW_HIDE);
  }
}

Here is the caller graph for this function:

static nsresult ShowNativePrintDialog ( HWND  aHWnd,
nsIPrintSettings aPrintSettings 
) [static]

Definition at line 867 of file nsPrintDialogUtil.cpp.

{
  //NS_ENSURE_ARG_POINTER(aHWnd);
  NS_ENSURE_ARG_POINTER(aPrintSettings);

  nsresult  rv = NS_ERROR_FAILURE;
  gDialogWasExtended  = PR_FALSE;

  HGLOBAL hGlobalDevMode = NULL;
  HGLOBAL hDevNames      = NULL;

  // Get the Print Name to be used
  PRUnichar * printerName;
  aPrintSettings->GetPrinterName(&printerName);

  // If there is no name then use the default printer
  if (!printerName || (printerName && !*printerName)) {
    printerName = GetDefaultPrinterNameFromGlobalPrinters();
  } else {
    HANDLE hPrinter = NULL;
    nsCAutoString printerNameNative;
    NS_CopyUnicodeToNative(nsDependentString(printerName), printerNameNative);
    LPTSTR tempPrinterName = NS_CONST_CAST(char*, printerNameNative.get());
    if(!::OpenPrinter(tempPrinterName, &hPrinter, NULL)) {
      // If the last used printer is not found, we should use default printer.
      printerName = GetDefaultPrinterNameFromGlobalPrinters();
    } else {
      ::ClosePrinter(hPrinter);
    }
  }

  NS_ASSERTION(printerName, "We have to have a printer name");
  if (!printerName) return NS_ERROR_FAILURE;

  // Now create a DEVNAMES struct so the the dialog is initialized correctly.
  nsCAutoString tempPrinterName;
  rv = NS_CopyUnicodeToNative(nsDependentString(printerName), tempPrinterName);
  NS_ENSURE_SUCCESS(rv, rv);

  PRUint32 len = tempPrinterName.Length();
  hDevNames = (HGLOBAL)::GlobalAlloc(GHND, len+sizeof(DEVNAMES)+1);
  DEVNAMES* pDevNames = (DEVNAMES*)::GlobalLock(hDevNames);
  pDevNames->wDriverOffset = sizeof(DEVNAMES);
  pDevNames->wDeviceOffset = sizeof(DEVNAMES);
  pDevNames->wOutputOffset = sizeof(DEVNAMES)+len+1;
  pDevNames->wDefault      = 0;

  char* device = &(((char*)pDevNames)[pDevNames->wDeviceOffset]);
  strcpy(device, tempPrinterName.get());
  ::GlobalUnlock(hDevNames);

  // Create a Moveable Memory Object that holds a new DevMode
  // from the Printer Name
  // The PRINTDLG.hDevMode requires that it be a moveable memory object
  // NOTE: We only need to free hGlobalDevMode when the dialog is cancelled
  // When the user prints, it comes back in the printdlg struct and 
  // is used and cleaned up later
  hGlobalDevMode = CreateGlobalDevModeAndInit(tempPrinterName.get(), aPrintSettings);

  // Prepare to Display the Print Dialog
  PRINTDLG  prntdlg;
  memset(&prntdlg, 0, sizeof(PRINTDLG));

  prntdlg.lStructSize = sizeof(prntdlg);
  prntdlg.hwndOwner   = aHWnd;
  prntdlg.hDevMode    = hGlobalDevMode;
  prntdlg.hDevNames   = hDevNames;
  prntdlg.hDC         = NULL;
  prntdlg.Flags       = PD_ALLPAGES | PD_RETURNIC | PD_USEDEVMODECOPIESANDCOLLATE;

  // if there is a current selection then enable the "Selection" radio button
  PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone;
  PRBool isOn;
  aPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
  if (!isOn) {
    prntdlg.Flags |= PD_NOSELECTION;
  }
  aPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);

  PRInt32 pg = 1;
  aPrintSettings->GetStartPageRange(&pg);
  prntdlg.nFromPage           = pg;
  
  aPrintSettings->GetEndPageRange(&pg);
  prntdlg.nToPage             = pg;

  prntdlg.nMinPage            = 1;
  prntdlg.nMaxPage            = 0xFFFF;
  prntdlg.nCopies             = 1;
  prntdlg.lpfnSetupHook       = NULL;
  prntdlg.lpSetupTemplateName = NULL;
  prntdlg.hPrintTemplate      = NULL;
  prntdlg.hSetupTemplate      = NULL;

  prntdlg.hInstance           = NULL;
  prntdlg.lpPrintTemplateName = NULL;

  if (!ShouldExtendPrintDialog()) {
    prntdlg.lCustData         = NULL;
    prntdlg.lpfnPrintHook     = NULL;
  } else {
    // Set up print dialog "hook" procedure for extending the dialog
    prntdlg.lCustData         = (DWORD)howToEnableFrameUI;
    prntdlg.lpfnPrintHook     = (LPPRINTHOOKPROC)PrintHookProc;
    prntdlg.Flags            |= PD_ENABLEPRINTHOOK;
  }

  BOOL result = ::PrintDlg(&prntdlg);

  if (TRUE == result) {
    // check to make sure we don't have any NULL pointers
    NS_ENSURE_TRUE(aPrintSettings && prntdlg.hDevMode, NS_ERROR_FAILURE);

    if (prntdlg.hDevNames == NULL) {
      ::GlobalFree(hGlobalDevMode);
      return NS_ERROR_FAILURE;
    }
    // Lock the deviceNames and check for NULL
    DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(prntdlg.hDevNames);
    if (devnames == NULL) {
      ::GlobalFree(hGlobalDevMode);
      return NS_ERROR_FAILURE;
    }

    char* device = &(((char *)devnames)[devnames->wDeviceOffset]);
    char* driver = &(((char *)devnames)[devnames->wDriverOffset]);

    // Check to see if the "Print To File" control is checked
    // then take the name from devNames and set it in the PrintSettings
    //
    // NOTE:
    // As per Microsoft SDK documentation the returned value offset from
    // devnames->wOutputOffset is either "FILE:" or NULL
    // if the "Print To File" checkbox is checked it MUST be "FILE:"
    // We assert as an extra safety check.
    if (prntdlg.Flags & PD_PRINTTOFILE) {
      char* fileName = &(((char *)devnames)[devnames->wOutputOffset]);
      NS_ASSERTION(strcmp(fileName, "FILE:") == 0, "FileName must be `FILE:`");
      aPrintSettings->SetToFileName(NS_ConvertASCIItoUCS2(fileName).get());
      aPrintSettings->SetPrintToFile(PR_TRUE);
    } else {
      // clear "print to file" info
      aPrintSettings->SetPrintToFile(PR_FALSE);
      aPrintSettings->SetToFileName(nsnull);
    }

    nsCOMPtr<nsIPrintSettingsWin> psWin(do_QueryInterface(aPrintSettings));
    if (!psWin) {
      ::GlobalFree(hGlobalDevMode);
      return NS_ERROR_FAILURE;
    }

    // Setup local Data members
    psWin->SetDeviceName(device);
    psWin->SetDriverName(driver);

#if defined(DEBUG_rods) || defined(DEBUG_dcone)
    printf("printer: driver %s, device %s  flags: %d\n", driver, device, prntdlg.Flags);
#endif
    // fill the print options with the info from the dialog
    nsDependentCString printerNameNative(device);
    nsAutoString printerName;
    NS_CopyNativeToUnicode(printerNameNative, printerName);

    aPrintSettings->SetPrinterName(printerName.get());

    if (prntdlg.Flags & PD_SELECTION) {
      aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection);

    } else if (prntdlg.Flags & PD_PAGENUMS) {
      aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange);
      aPrintSettings->SetStartPageRange(prntdlg.nFromPage);
      aPrintSettings->SetEndPageRange(prntdlg.nToPage);

    } else { // (prntdlg.Flags & PD_ALLPAGES)
      aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
    }

    if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) {
      // make sure the dialog got extended
      if (gDialogWasExtended) {
        // check to see about the frame radio buttons
        switch (gFrameSelectedRadioBtn) {
          case rad4: 
            aPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
            break;
          case rad5: 
            aPrintSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame);
            break;
          case rad6: 
            aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
            break;
        } // switch
      } else {
        // if it didn't get extended then have it default to printing
        // each frame separately
        aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
      }
    } else {
      aPrintSettings->SetPrintFrameType(nsIPrintSettings::kNoFrames);
    }
    // Unlock DeviceNames
    ::GlobalUnlock(prntdlg.hDevNames);

    // Transfer the settings from the native data to the PrintSettings
    LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode);
    if (devMode == NULL) {
      ::GlobalFree(hGlobalDevMode);
      return NS_ERROR_FAILURE;
    }
    psWin->SetDevMode(devMode); // copies DevMode
    SetPrintSettingsFromDevMode(aPrintSettings, devMode);
    ::GlobalUnlock(prntdlg.hDevMode);

#if defined(DEBUG_rods) || defined(DEBUG_dcone)
    PRBool  printSelection = prntdlg.Flags & PD_SELECTION;
    PRBool  printAllPages  = prntdlg.Flags & PD_ALLPAGES;
    PRBool  printNumPages  = prntdlg.Flags & PD_PAGENUMS;
    PRInt32 fromPageNum    = 0;
    PRInt32 toPageNum      = 0;

    if (printNumPages) {
      fromPageNum = prntdlg.nFromPage;
      toPageNum   = prntdlg.nToPage;
    } 
    if (printSelection) {
      printf("Printing the selection\n");

    } else if (printAllPages) {
      printf("Printing all the pages\n");

    } else {
      printf("Printing from page no. %d to %d\n", fromPageNum, toPageNum);
    }
#endif
    
  } else {
    aPrintSettings->SetIsCancelled(PR_TRUE);
    if (hGlobalDevMode) ::GlobalFree(hGlobalDevMode);
    return NS_ERROR_ABORT;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
    {"PrintFrames", grp3},
    {"Aslaid", rad4},
    {"selectedframe", rad5},
    {"Eachframe", rad6},
    {NULL, NULL}}

Definition at line 471 of file nsPrintDialogUtil.cpp.

Definition at line 122 of file nsPrintDialogUtil.cpp.

Definition at line 119 of file nsPrintDialogUtil.cpp.

HWND gParentWnd = NULL [static]

Definition at line 126 of file nsPrintDialogUtil.cpp.

const char* kAsLaidOutOnScreenStr = "As &laid out on the screen" [static]

Definition at line 110 of file nsPrintDialogUtil.cpp.

const char* kEachFrameSeparately = "&Each frame separately" [static]

Definition at line 112 of file nsPrintDialogUtil.cpp.

Definition at line 182 of file nsPrintDialogUtil.cpp.

Definition at line 139 of file nsPrintDialogUtil.cpp.

const char* kTheSelectedFrameStr = "The selected &frame" [static]

Definition at line 111 of file nsPrintDialogUtil.cpp.