diff --git a/mailnews/addrbook/resources/content/addressbook.js b/mailnews/addrbook/resources/content/addressbook.js index e6ebfe1f7398..7050da53b9df 100644 --- a/mailnews/addrbook/resources/content/addressbook.js +++ b/mailnews/addrbook/resources/content/addressbook.js @@ -45,6 +45,7 @@ var gSearchTimer = null; var gStatusText = null; var gQueryURIFormat = null; var gSearchInput; +var gPrintSettings = null; // Constants that correspond to choices // in Address Book->View -->Show Name as @@ -255,6 +256,36 @@ function AbCreateNewAddressBook(name) top.addressbook.newAddressBook(properties); } +function GetPrintSettings() +{ + var prevPS = gPrintSettings; + + try { + if (gPrintSettings == null) { + var useGlobalPrintSettings = true; + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + if (pref) { + useGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings", false); + } + + // I would rather be using nsIWebBrowserPrint API + // but I really don't have a document at this point + var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] + .getService(Components.interfaces.nsIPrintOptions); + if (useGlobalPrintSettings) { + gPrintSettings = printOptionsService.globalPrintSettings; + } else { + gPrintSettings = printOptionsService.CreatePrintSettings(); + } + } + } catch (e) { + dump("GetPrintSettings "+e); + } + + return gPrintSettings; +} + function AbPrintCard() { var selectedItems = GetSelectedAbCards(); @@ -286,10 +317,14 @@ function AbPrintCard() } } + if (gPrintSettings == null) { + gPrintSettings = GetPrintSettings(); + } + printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", "", "chrome,dialog=no,all", - totalCard, selectionArray, statusFeedback); + totalCard, selectionArray, statusFeedback, gPrintSettings); return; } diff --git a/mailnews/base/public/nsIMsgPrintEngine.idl b/mailnews/base/public/nsIMsgPrintEngine.idl index 31962e4e3494..066d8a0f1b58 100644 --- a/mailnews/base/public/nsIMsgPrintEngine.idl +++ b/mailnews/base/public/nsIMsgPrintEngine.idl @@ -39,6 +39,7 @@ #include "nsIMsgStatusFeedback.idl" interface nsIDOMWindowInternal; +interface nsIPrintSettings; [scriptable, uuid(91FD6B10-E0BC-11d3-8F97-000064657374)] @@ -48,6 +49,6 @@ interface nsIMsgPrintEngine : nsISupports { void SetStatusFeedback(in nsIMsgStatusFeedback feedback); void SetPrintURICount(in PRInt32 aCount); void AddPrintURI(in wstring aURI); - void StartPrintOperation(); + void StartPrintOperation(in nsIPrintSettings aPS); }; diff --git a/mailnews/base/resources/content/mailWindowOverlay.js b/mailnews/base/resources/content/mailWindowOverlay.js index 49e511d7c510..d40fd73ef04f 100644 --- a/mailnews/base/resources/content/mailWindowOverlay.js +++ b/mailnews/base/resources/content/mailWindowOverlay.js @@ -31,6 +31,7 @@ var nsPrefBranch = null; var gOfflineManager; var gWindowManagerInterface; var gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); +var gPrintSettings = null; var gTimelineService = null; var gTimelineEnabled = ("@mozilla.org;timeline-service;1" in Components.classes); @@ -1157,6 +1158,36 @@ function MsgSendUnsentMsgs() } } +function GetPrintSettings() +{ + var prevPS = gPrintSettings; + + try { + if (gPrintSettings == null) { + var useGlobalPrintSettings = true; + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + if (pref) { + useGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings", false); + } + + // I would rather be using nsIWebBrowserPrint API + // but I really don't have a document at this point + var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] + .getService(Components.interfaces.nsIPrintOptions); + if (useGlobalPrintSettings) { + gPrintSettings = printOptionsService.globalPrintSettings; + } else { + gPrintSettings = printOptionsService.CreatePrintSettings(); + } + } + } catch (e) { + dump("GetPrintSettings "+e); + } + + return gPrintSettings; +} + function PrintEnginePrint() { var messageList = GetSelectedMessages(); @@ -1167,10 +1198,14 @@ function PrintEnginePrint() return false; } + if (gPrintSettings == null) { + gPrintSettings = GetPrintSettings(); + } + printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", "", "chrome,dialog=no,all", - numMessages, messageList, statusFeedback); + numMessages, messageList, statusFeedback, gPrintSettings); return true; } diff --git a/mailnews/base/resources/content/msgPrintEngine.js b/mailnews/base/resources/content/msgPrintEngine.js index f945c2bbeb6a..b955c0e6021c 100644 --- a/mailnews/base/resources/content/msgPrintEngine.js +++ b/mailnews/base/resources/content/msgPrintEngine.js @@ -24,13 +24,14 @@ var printEngineContractID = "@mozilla.org/messenger/msgPrintEngine;1"; var printEngineWindow; var printEngine; +var printSettings; /* Functions related to startup */ function OnLoadPrintEngine() { PrintEngineCreateGlobals(); InitPrintEngineWindow(); - printEngine.StartPrintOperation(); + printEngine.StartPrintOperation(printSettings); } function OnUnloadPrintEngine() @@ -57,9 +58,10 @@ function InitPrintEngineWindow() { var numSelected = window.arguments[0]; var uriArray = window.arguments[1]; - var statusFeedback = window.arguments[2]; + var statusFeedback = window.arguments[2]; + printSettings = window.arguments[3].QueryInterface(Components.interfaces.nsIPrintSettings); - printEngine.SetStatusFeedback(statusFeedback); + printEngine.SetStatusFeedback(statusFeedback); if (numSelected > 0) { diff --git a/mailnews/base/src/nsMsgPrintEngine.cpp b/mailnews/base/src/nsMsgPrintEngine.cpp index 17cf9b7eb282..5b5b9baa2bcc 100644 --- a/mailnews/base/src/nsMsgPrintEngine.cpp +++ b/mailnews/base/src/nsMsgPrintEngine.cpp @@ -278,8 +278,10 @@ nsMsgPrintEngine::SetPrintURICount(PRInt32 aCount) } NS_IMETHODIMP -nsMsgPrintEngine::StartPrintOperation() +nsMsgPrintEngine::StartPrintOperation(nsIPrintSettings* aPS) { + mPrintSettings = aPS; + // Load the about:blank on the tail end... nsresult rv = AddPrintURI(NS_LITERAL_STRING("about:blank").get()); if (NS_FAILED(rv)) return rv;