From 23586b00cfb70c1b02d2e360ca8963398a65d1d2 Mon Sep 17 00:00:00 2001 From: "rhp%netscape.com" Date: Tue, 15 Feb 2000 02:26:14 +0000 Subject: [PATCH] Adding new printing files to the tree - NOT PART OF THE BUILD! --- mailnews/base/public/nsIMsgPrintEngine.idl | 41 ++ .../base/resources/content/msgPrintEngine.js | 90 +++++ .../base/resources/content/msgPrintEngine.xul | 52 +++ mailnews/base/src/nsMsgPrintEngine.cpp | 357 ++++++++++++++++++ mailnews/base/src/nsMsgPrintEngine.h | 64 ++++ 5 files changed, 604 insertions(+) create mode 100644 mailnews/base/public/nsIMsgPrintEngine.idl create mode 100644 mailnews/base/resources/content/msgPrintEngine.js create mode 100644 mailnews/base/resources/content/msgPrintEngine.xul create mode 100644 mailnews/base/src/nsMsgPrintEngine.cpp create mode 100644 mailnews/base/src/nsMsgPrintEngine.h diff --git a/mailnews/base/public/nsIMsgPrintEngine.idl b/mailnews/base/public/nsIMsgPrintEngine.idl new file mode 100644 index 00000000000..ce86dedf39f --- /dev/null +++ b/mailnews/base/public/nsIMsgPrintEngine.idl @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsIStreamListener.idl" +#include "nsIDocumentLoaderObserver.idl" +#include "nsrootidl.idl" +#include "domstubs.idl" + +%{C++ +#include "nsIDOMWindow.h" +%} + +[scriptable, uuid(91FD6B10-E0BC-11d3-8F97-000064657374)] +interface nsIMsgPrintEngine : nsIDocumentLoaderObserver { + + void SetWindow(in nsIDOMWindow ptr); + + void SetPrintURICount(in PRInt32 aCount); + void AddPrintURI(in wstring aURI); + void StartPrintOperation(); +}; + diff --git a/mailnews/base/resources/content/msgPrintEngine.js b/mailnews/base/resources/content/msgPrintEngine.js new file mode 100644 index 00000000000..0f3f050284e --- /dev/null +++ b/mailnews/base/resources/content/msgPrintEngine.js @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + */ + +/* This is where functions related to the print engine are kept */ + +/* globals for a particular window */ +var printEngineProgID = "component://netscape/messenger/msgPrintEngine"; +var printEngineWindow; +var printEngine; + +/* Functions related to startup */ +function OnLoadPrintEngine() +{ + PrintEngineCreateGlobals(); + InitPrintEngineWindow(); + printEngine.StartPrintOperation(); +} + +function OnUnloadPrintEngine() +{ +} + +function PrintEngineCreateGlobals() +{ + /* get the print engine instance */ + printEngine = Components.classes[printEngineProgID].createInstance(); + printEngine = printEngine.QueryInterface(Components.interfaces.nsIMsgPrintEngine); +} + +function InitPrintEngineWindow() +{ + /* Tell the nsIPrintEngine object what window is rendering the email */ + printEngine.SetWindow(window); + + // See if we got arguments. + // Window was opened via window.openDialog. Copy argument + // and perform compose initialization + // + if ( window.arguments && window.arguments[0] != null ) + { + var numSelected = window.arguments[0]; + var uriArray = window.arguments[1]; + + if (numSelected > 0) + { + printEngine.SetPrintURICount(numSelected); + for(var i = 0; i < numSelected; i++) + { + dump(uriArray[i]); + printEngine.AddPrintURI(uriArray[i]); + dump("\n"); + } + } + } +} + +function ClearPrintEnginePane() +{ + if (window.frames["printengine"].location != "about:blank") + window.frames["printengine"].location = "about:blank"; +} + +function StopUrls() +{ + printEngine.StopUrls(); +} + +function PrintEnginePrint() +{ + printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", + "", + "chrome,dialog=no,all"); +} diff --git a/mailnews/base/resources/content/msgPrintEngine.xul b/mailnews/base/resources/content/msgPrintEngine.xul new file mode 100644 index 00000000000..e1f0e36400e --- /dev/null +++ b/mailnews/base/resources/content/msgPrintEngine.xul @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + diff --git a/mailnews/base/src/nsMsgPrintEngine.cpp b/mailnews/base/src/nsMsgPrintEngine.cpp new file mode 100644 index 00000000000..8c2edd7d97c --- /dev/null +++ b/mailnews/base/src/nsMsgPrintEngine.cpp @@ -0,0 +1,357 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "MPL"); you may not use this file + * except in compliance with the MPL. You may obtain a copy of + * the MPL at http://www.mozilla.org/MPL/ + * + * Software distributed under the MPL is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the MPL for the specific language governing + * rights and limitations under the MPL. + * + */ + +// nsMsgPrintEngine.cpp: provides a WebShell container for use +// in printing + +#include "nscore.h" +#include "nsCOMPtr.h" + +#include "nsRepository.h" + +#include "nsISupports.h" + +#include "nsIURI.h" +#include "nsEscape.h" +#include "nsIWebShell.h" +#include "nsIBaseWindow.h" +#include "nsIDOMDocument.h" +#include "nsIDocumentViewer.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsIDocument.h" +#include "nsIContentViewerFile.h" +#include "nsIContentViewer.h" +#include "nsIMsgMessageService.h" +#include "nsMsgUtils.h" +#include "nsIDocumentLoader.h" +#include "nsIDocumentLoaderObserver.h" +#include "nsIMarkupDocumentViewer.h" + +#include "nsMsgPrintEngine.h" + +///////////////////////////////////////////////////////////////////////// +// nsMsgPrintEngine implementation +///////////////////////////////////////////////////////////////////////// + +nsMsgPrintEngine::nsMsgPrintEngine() : + mWebShell(nsnull) +{ + mCurrentlyPrintingURI = -1; + mWindow = nsnull; + NS_INIT_REFCNT(); +} + + +nsMsgPrintEngine::~nsMsgPrintEngine() +{ + mWebShell = nsnull; +} + +// Implement AddRef and Release +NS_IMPL_ADDREF(nsMsgPrintEngine) +NS_IMPL_RELEASE(nsMsgPrintEngine) +NS_IMPL_QUERY_INTERFACE2(nsMsgPrintEngine,nsIMsgPrintEngine, nsIDocumentLoaderObserver); + +nsresult nsMsgPrintEngine::Init() +{ + return NS_OK; +} + +/** Initializes simple container for native window widget + * @param aNativeWidget native window widget (e.g., GtkWidget) + * @param width window width (pixels) + * @param height window height (pixels) + * @param aPref preferences object + */ +/** RICHIE +NS_IMETHODIMP nsMsgPrintEngine::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason) +{ + return NS_OK; +} + +NS_IMETHODIMP nsMsgPrintEngine::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL) +{ + return NS_OK; +} + + +NS_IMETHODIMP nsMsgPrintEngine::ProgressLoadURL(nsIWebShell* aShell, + const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax) +{ + return NS_OK; +} + + +NS_IMETHODIMP nsMsgPrintEngine::EndLoadURL(nsIWebShell* aShell, + const PRUnichar* aURL, + nsresult aStatus) +{ + + return NS_OK; +} +***/ + +NS_IMETHODIMP +nsMsgPrintEngine::OnStartDocumentLoad(nsIDocumentLoader *aLoader, nsIURI *aURL, const char *aCommand) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::OnEndDocumentLoad(nsIDocumentLoader *loader, nsIChannel *aChannel, PRUint32 aStatus) +{ + // Now, fire off the print operation! + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr viewer; + + + NS_ASSERTION(mWebShell,"can't print, there is no webshell"); + if ( (!mWebShell) || (!aChannel) ) + { + return StartNextPrintOperation(); + } + + // Make sure this isn't just "about:blank" finishing.... + nsIURI *aOriginalURI = nsnull; + if (NS_SUCCEEDED(aChannel->GetOriginalURI(&aOriginalURI))) + { + char *spec = nsnull; + + if (NS_SUCCEEDED(aOriginalURI->GetSpec(&spec)) && spec) + { + if (!nsCRT::strcasecmp(spec, "about:blank")) + { + return StartNextPrintOperation(); + } + } + } + + mWebShell->GetContentViewer(getter_AddRefs(viewer)); + if (viewer) + { + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) + { + rv = viewerFile->Print(PR_FALSE, nsnull); + } + } + + return StartNextPrintOperation(); +} + +NS_IMETHODIMP +nsMsgPrintEngine::OnStartURLLoad(nsIDocumentLoader *aLoader, nsIChannel *channel) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::OnProgressURLLoad(nsIDocumentLoader *aLoader, nsIChannel *aChannel, PRUint32 aProgress, PRUint32 aProgressMax) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::OnStatusURLLoad(nsIDocumentLoader *loader, nsIChannel *channel, nsString & aMsg) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::OnEndURLLoad(nsIDocumentLoader *aLoader, nsIChannel *aChannel, PRUint32 aStatus) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::HandleUnknownContentType(nsIDocumentLoader *aLoader, nsIChannel *aChannel, const char *aContentType, const char *aCommand) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::SetWindow(nsIDOMWindow *aWin) +{ + if (!aWin) + { + // It isn't an error to pass in null for aWin, in fact it means we are shutting + // down and we should start cleaning things up... + return NS_OK; + } + + nsAutoString webShellName("printengine"); + NS_IF_RELEASE(mWindow); + mWindow = aWin; + NS_ADDREF(aWin); + + nsCOMPtr globalObj( do_QueryInterface(aWin) ); + NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE); + + nsCOMPtr docShell; + globalObj->GetDocShell(getter_AddRefs(docShell)); + nsCOMPtr webShell(do_QueryInterface(docShell)); + if (!webShell) + { + return NS_ERROR_FAILURE; + } + + nsCOMPtr rootWebShell; + webShell->GetRootWebShell(*getter_AddRefs(rootWebShell)); + if (nsnull != rootWebShell) + { + nsresult rv = rootWebShell->FindChildWithName(webShellName.GetUnicode(), *getter_AddRefs(mWebShell)); + if (NS_SUCCEEDED(rv) && mWebShell) + { + nsCOMPtr docLoader = nsnull; + mWebShell->GetDocumentLoader(*getter_AddRefs(docLoader)); + if (docLoader) + { + nsCOMPtr observer = do_QueryInterface(this); + if (observer) + docLoader->AddObserver(observer); + + + nsIWebShell *mRootWebShell; + mWebShell->GetRootWebShell(mRootWebShell); + nsIWebShell *root = mRootWebShell; + NS_RELEASE(root); // don't hold reference + if (mRootWebShell) + { + nsCOMPtr docShell(do_QueryInterface(mRootWebShell)); + if (docShell) + docShell->SetDocLoaderObserver(observer); + } + + } + + +//RICHIE nsCOMPtr observer = do_QueryInterface(this); +// if (observer) +// mWebShell->SetDocLoaderObserver(observer); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::AddPrintURI(const PRUnichar *aMsgURI) +{ + mURIArray.AppendString(aMsgURI); + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::SetPrintURICount(PRInt32 aCount) +{ + mURICount = aCount; + return NS_OK; +} + +NS_IMETHODIMP +nsMsgPrintEngine::StartPrintOperation() +{ + return NS_OK; + return StartNextPrintOperation(); +} + +NS_IMETHODIMP +nsMsgPrintEngine::StartNextPrintOperation() +{ + nsresult rv; + + // Only do this the first time through... + if (mCurrentlyPrintingURI == -1) + InitializeDisplayCharset(); + + // First, check if we are at the end of this stuff! + if ( (mCurrentlyPrintingURI+1) >= mURIArray.Count() ) + { + Release(); + return NS_OK; + } + + mCurrentlyPrintingURI++; + if (!mWebShell) + return StartNextPrintOperation(); + + // SetWindow(mWindow); + nsString *uri = mURIArray.StringAt(mCurrentlyPrintingURI); + rv = FireThatLoadOperation(uri); + if (NS_FAILED(rv)) + return StartNextPrintOperation(); + else + return rv; +} + +NS_IMETHODIMP +nsMsgPrintEngine::FireThatLoadOperation(nsString *uri) +{ + nsresult rv = NS_OK; + + char *tString = uri->ToNewCString(); + if (!tString) + return NS_ERROR_OUT_OF_MEMORY; + + nsIMsgMessageService * messageService = nsnull; + rv = GetMessageServiceFromURI(tString, &messageService); + + if (NS_SUCCEEDED(rv) && messageService) + { + rv = messageService->DisplayMessageForPrinting(tString, mWebShell, nsnull, nsnull, nsnull); + ReleaseMessageServiceFromURI(tString, messageService); + } + //If it's not something we know about, then just load try loading it directly. + else + { + if (mWebShell) + mWebShell->LoadURL(uri->GetUnicode(), nsnull, nsIChannel::LOAD_DOCUMENT_URI); + } + + // Force add an observer! + nsCOMPtr docLoader = nsnull; + mWebShell->GetDocumentLoader(*getter_AddRefs(docLoader)); + if (docLoader) + { + nsCOMPtr observer = do_QueryInterface(this); + if (observer) + { + docLoader->RemoveObserver(observer); + docLoader->AddObserver(observer); + } + } + + PR_FREEIF(tString); + return rv; +} + +void +nsMsgPrintEngine::InitializeDisplayCharset() +{ + // libmime always converts to UTF-8 (both HTML and XML) + if (mWebShell) + { + nsAutoString aForceCharacterSet("UTF-8"); + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) + { + muDV->SetForceCharacterSet(aForceCharacterSet.GetUnicode()); + } + } + } +} diff --git a/mailnews/base/src/nsMsgPrintEngine.h b/mailnews/base/src/nsMsgPrintEngine.h new file mode 100644 index 00000000000..56056e41612 --- /dev/null +++ b/mailnews/base/src/nsMsgPrintEngine.h @@ -0,0 +1,64 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "MPL"); you may not use this file + * except in compliance with the MPL. You may obtain a copy of + * the MPL at http://www.mozilla.org/MPL/ + * + * Software distributed under the MPL is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the MPL for the specific language governing + * rights and limitations under the MPL. + * + * The Original Code is XMLterm. + * + * The Initial Developer of the Original Code is Ramalingam Saravanan. + * Portions created by Ramalingam Saravanan are + * Copyright (C) 1999 Ramalingam Saravanan. All Rights Reserved. + * + * Contributor(s): + */ + +// nsMsgPrintEngine.h: declaration of nsMsgPrintEngine class +// implementing mozISimpleContainer, +// which provides a WebShell container for use in simple programs +// using the layout engine + +#include "nscore.h" +#include "nsCOMPtr.h" + +#include "nsIWebShell.h" +#include "nsVoidArray.h" +#include "nsIDocShell.h" +#include "nsIMsgPrintEngine.h" +#include "nsIScriptGlobalObject.h" +#include "nsIStreamListener.h" + +class nsMsgPrintEngine : public nsIMsgPrintEngine { + +public: + nsMsgPrintEngine(); + virtual ~nsMsgPrintEngine(); + + // nsISupports + NS_DECL_ISUPPORTS + + NS_IMETHOD Init(); + + // nsIMsgPrintEngine interface + NS_DECL_NSIMSGPRINTENGINE + + // For nsIDocumentLoaderObserver... + NS_DECL_NSIDOCUMENTLOADEROBSERVER + +protected: + + NS_IMETHOD FireThatLoadOperation(nsString *uri); + NS_IMETHOD StartNextPrintOperation(); + void InitializeDisplayCharset(); + + nsIDOMWindow *mWindow; + nsCOMPtr mWebShell; + PRInt32 mURICount; + nsStringArray mURIArray; + PRInt32 mCurrentlyPrintingURI; +};