Changes to implement printing correctly - Buf #12505 - r: jefft

This commit is contained in:
rhp%netscape.com 2000-02-15 23:05:06 +00:00
Родитель f2bcbbadcf
Коммит 0d5876b1d2
24 изменённых файлов: 198 добавлений и 25 удалений

Просмотреть файл

@ -285,6 +285,19 @@
#define NS_MSGVIEWNAVIGATIONSERVICE_CID \
{ 0x60d34fb4, 0xd031, 0x11d3, \
{ 0x8b, 0x2e, 0x0, 0x60, 0xb0, 0xfc, 0x4, 0xd2}}
//
// Print Engine...
//
#define NS_MSGPRINTENGINE_PROGID \
"component://netscape/messenger/msgPrintEngine"
#define NS_MSG_PRINTENGINE_CID \
{ /* 91FD6B19-E0BC-11d3-8F97-000064657374 */ \
0x91fd6b19, 0xe0bc, 0x11d3, \
{ 0x8f, 0x97, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } };
#endif // nsMessageBaseCID_h__
//

Просмотреть файл

@ -74,6 +74,8 @@
#include "nsMsgServiceProvider.h"
#include "nsMsgPrintEngine.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
@ -132,6 +134,9 @@ static NS_DEFINE_CID(kMsgViewNavigationServiceCID, NS_MSGVIEWNAVIGATIONSERVICE_C
//MsgServiceProviderService
static NS_DEFINE_CID(kMsgServiceProviderServiceCID, NS_MSGSERVICEPROVIDERSERVICE_CID);
// Print Engine
static NS_DEFINE_CID(kMsgPrintEngineCID, NS_MSG_PRINTENGINE_CID);
// private factory declarations for each component we know how to produce
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessengerBootstrap)
@ -156,6 +161,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMessageView,Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgWindow,Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgViewNavigationService,Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgServiceProviderService, Init);
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgPrintEngine, Init)
// Module implementation for the sample library
class nsMsgBaseModule : public nsIModule
{
@ -196,6 +202,7 @@ protected:
nsCOMPtr<nsIGenericFactory> mMsgWindowFactory;
nsCOMPtr<nsIGenericFactory> mMsgViewNavigationServiceFactory;
nsCOMPtr<nsIGenericFactory> mMsgServiceProviderServiceFactory;
nsCOMPtr<nsIGenericFactory> mMsgPrintEngineFactory;
};
nsMsgBaseModule::nsMsgBaseModule()
@ -408,6 +415,13 @@ NS_IMETHODIMP nsMsgBaseModule::GetClassObject(nsIComponentManager *aCompMgr,
rv = NS_NewGenericFactory(getter_AddRefs(mMsgServiceProviderServiceFactory), &nsMsgServiceProviderServiceConstructor);
fact = mMsgServiceProviderServiceFactory;
}
else if (aClass.Equals(kMsgPrintEngineCID))
{
if (!mMsgPrintEngineFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMsgPrintEngineFactory), &nsMsgPrintEngineConstructor);
fact = mMsgPrintEngineFactory;
}
if (fact)
rv = fact->QueryInterface(aIID, r_classObj);
@ -469,6 +483,8 @@ static Components gComponents[] = {
NS_MSGWINDOW_PROGID},
{ "Mail/News Message Navigation Service", &kMsgViewNavigationServiceCID,
NS_MSGVIEWNAVIGATIONSERVICE_PROGID},
{ "Mail/News Print Engine", &kMsgPrintEngineCID,
NS_MSGPRINTENGINE_PROGID},
{ "Mail/News Service Provider Service", &kMsgServiceProviderServiceCID,
NS_MSGSERVICEPROVIDERSERVICE_PROGID}

Просмотреть файл

@ -38,4 +38,5 @@ nsIIncomingServerListener.idl
nsIMsgHdr.idl
nsIMsgStringService.idl
nsIMsgViewNavigationService.idl
nsIMsgPrintEngine.idl

Просмотреть файл

@ -74,6 +74,7 @@ XPIDLSRCS = \
nsIMessengerMigrator.idl \
nsIMsgStringService.idl \
nsIMsgViewNavigationService.idl \
nsIMsgPrintEngine.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -59,6 +59,7 @@ XPIDLSRCS = \
.\nsIMsgHdr.idl \
.\nsIMsgStringService.idl \
.\nsIMsgViewNavigationService.idl \
.\nsIMsgPrintEngine.idl \
$(NULL)
################################################################################

Просмотреть файл

@ -99,4 +99,17 @@ interface nsIMsgMessageService : nsISupports {
/////////////////////////////////////////////////////////////////////
void GetUrlForUri(in string aMessageURI, out nsIURI aURL);
/////////////////////////////////////////////////////////////////////
// DisplayMessageForPrinting: When you want a message displayed in a
// format that is suitable for printing....
// aMessageURI is a uri representing the message to display.
// aDisplayConsumer is (for now) a nsIWebshell which we'll use to load
// the message into.
///////////////////////////////////////////////////////////////////
void DisplayMessageForPrinting(in string aMessageURI, in nsISupports aDisplayConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener,
out nsIURI aURL);
};

Просмотреть файл

@ -41,3 +41,5 @@ msgFolderPickerOverlay.xul
msgFolderPickerOverlay.js
messengerdnd.js
mailContextMenus.js
msgPrintEngine.js
msgPrintEngine.xul

Просмотреть файл

@ -50,6 +50,8 @@ EXPORT_RESOURCE_SAMPLES = \
renameFolderNameDialog.xul \
messengerdnd.js \
mailContextMenus.js \
msgPrintEngine.js \
msgPrintEngine.xul \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -776,3 +776,29 @@ function Redo()
{
messenger.Redo(msgWindow);
}
function PrintEnginePrint()
{
var tree = GetThreadTree();
var selectedItems = tree.selectedItems;
var numSelected = selectedItems.length;
if (numSelected == 0)
{
dump("PrintEnginePrint(): No messages selected.\n");
return false;
}
var selectionArray = new Array(numSelected);
for(var i = 0; i < numSelected; i++)
{
selectionArray[i] = selectedItems[i].getAttribute("id");
}
printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul",
"",
"chrome,dialog=no,all",
numSelected, selectionArray);
return true;
}

Просмотреть файл

@ -45,6 +45,8 @@ install::
$(MAKE_INSTALL) renameFolderNameDialog.xul $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) messengerdnd.js $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) mailContextMenus.js $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) msgPrintEngine.js $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) msgPrintEngine.xul $(DIST)\bin\chrome\messenger\content\default
clobber::
rm -f $(DIST)\chrome\messenger\content\default\messenger.xul
@ -68,5 +70,7 @@ clobber::
rm -f $(DIST)\chrome\messenger\content\default\renameFolderNameDialog.xul
rm -f $(DIST)\chrome\messenger\content\default\messengerdnd.js
rm -f $(DIST)\chrome\messenger\content\default\mailContextMenus.js
rm -f $(DIST)\chrome\messenger\content\default\msgPrintEngine.js
rm -f $(DIST)\chrome\messenger\content\default\msgPrintEngine.xul

Просмотреть файл

@ -48,15 +48,6 @@ function MessengerSetDefaultCharacterSet(aCharset)
MsgReload();
}
function Print() {
dump("Print()\n");
try {
messenger.DoPrint();
}
catch (ex) {
dump("failed to print\n");
}
}
function PrintPreview() {
dump("PrintPreview()\n");
try {
@ -66,3 +57,13 @@ function PrintPreview() {
dump("failed to print preview\n");
}
}
function Print() {
dump("Print()\n");
try {
messenger.DoPrint();
}
catch (ex) {
dump("failed to print\n");
}
}

Просмотреть файл

@ -296,3 +296,6 @@ Rights Reserved.
<!-- Message Header View Popup -->
<!ENTITY AddToAddressBook.label "Add Address To Address Book">
<!ENTITY SendMailTo.label "Send Mail To">
<!-- Print Engine -->
<!ENTITY printEngine.title "Printing...">

Просмотреть файл

@ -41,6 +41,7 @@ nsMessageView.h
nsMsgWindow.h
nsMsgViewNavigationService.h
nsMsgServiceProvider.h
nsMsgPrintEngine.h

Просмотреть файл

@ -56,6 +56,7 @@ CPPSRCS = \
nsMessengerMigrator.cpp \
nsMsgViewNavigationService.cpp \
nsMsgServiceProvider.cpp \
nsMsgPrintEngine.cpp \
$(NULL)
EXPORTS = \
@ -82,6 +83,7 @@ EXPORTS = \
nsMessengerMigrator.h \
nsMsgViewNavigationService.h \
nsMsgServiceProvider.h \
nsMsgPrintEngine.h \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

Просмотреть файл

@ -52,6 +52,7 @@ EXPORTS= \
nsMessengerMigrator.h \
nsMsgViewNavigationService.h \
nsMsgServiceProvider.h \
nsMsgPrintEngine.h \
$(NULL)
@ -86,6 +87,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsMessengerMigrator.obj \
.\$(OBJDIR)\nsMsgViewNavigationService.obj \
.\$(OBJDIR)\nsMsgServiceProvider.obj \
.\$(OBJDIR)\nsMsgPrintEngine.obj \
$(NULL)

Просмотреть файл

@ -96,11 +96,15 @@
#include "nsMsgMimeCID.h"
#include "nsIMimeConverter.h"
// Printing
#include "nsMsgPrintEngine.h"
static NS_DEFINE_CID(kIStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kMsgSendLaterCID, NS_MSGSENDLATER_CID);
static NS_DEFINE_CID(kMsgCopyServiceCID, NS_MSGCOPYSERVICE_CID);
static NS_DEFINE_CID(kMsgPrintEngineCID, NS_MSG_PRINTENGINE_CID);
#if defined(DEBUG_seth_) || defined(DEBUG_sspitzer_) || defined(DEBUG_jefft)
#define DEBUG_MESSENGER

Просмотреть файл

@ -74,6 +74,7 @@ NS_IMPL_QUERY_INTERFACE4(nsImapService,
nsImapService::nsImapService()
{
NS_INIT_REFCNT();
mPrintingOperation = PR_FALSE;
}
nsImapService::~nsImapService()
@ -299,6 +300,22 @@ NS_IMETHODIMP nsImapService::DisplayMessage(const char* aMessageURI,
return rv;
}
//
// rhp: Right now, this is the same as simple DisplayMessage, but it will change
// to support print rendering.
//
NS_IMETHODIMP nsImapService::DisplayMessageForPrinting(const char* aMessageURI,
nsISupports * aDisplayConsumer,
nsIMsgWindow * aMsgWindow,
nsIUrlListener * aUrlListener,
nsIURI ** aURL)
{
mPrintingOperation = PR_TRUE;
nsresult rv = DisplayMessage(aMessageURI, aDisplayConsumer, aMsgWindow, aUrlListener, aURL);
mPrintingOperation = PR_FALSE;
return rv;
}
NS_IMETHODIMP
nsImapService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListener *
aMailboxCopy, PRBool moveMessage,
@ -510,6 +527,12 @@ nsImapService::FetchMessage(nsIImapUrl * aImapUrl,
urlSpec.Append(messageIdentifierList);
// rhp: If we are displaying this message for the purpose of printing, we
// need to append the header=print option.
//
if (mPrintingOperation)
urlSpec.Append("?header=print");
// mscott - this cast to a char * is okay...there's a bug in the XPIDL
// compiler that is preventing in string parameters from showing up as
// const char *. hopefully they will fix it soon.

Просмотреть файл

@ -229,6 +229,8 @@ protected:
// into the folder and message key equivalents
nsresult DecomposeImapURI(const char * aMessageURI, nsIMsgFolder ** aFolder, char ** msgKey);
PRBool mPrintingOperation; // Flag for printing operations
};
#endif /* nsImapService_h___ */

Просмотреть файл

@ -43,6 +43,7 @@ static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
nsMailboxService::nsMailboxService()
{
mPrintingOperation = PR_FALSE;
NS_INIT_REFCNT();
}
@ -96,8 +97,7 @@ nsresult nsMailboxService::CopyMessage(const char * aSrcMailboxURI,
nsMailboxAction mailboxAction = nsIMailboxUrl::ActionMoveMessage;
if (!moveMessage)
mailboxAction = nsIMailboxUrl::ActionCopyMessage;
return FetchMessage(aSrcMailboxURI, aMailboxCopyHandler, nsnull, aUrlListener, mailboxAction,
aURL);
return FetchMessage(aSrcMailboxURI, aMailboxCopyHandler, nsnull, aUrlListener, mailboxAction, aURL);
}
nsresult nsMailboxService::CopyMessages(nsMsgKeyArray *msgKeys,
@ -121,7 +121,7 @@ nsresult nsMailboxService::FetchMessage(const char* aMessageURI,
nsresult rv = NS_OK;
nsCOMPtr<nsIMailboxUrl> mailboxurl;
rv = PrepareMessageUrl(aMessageURI, aUrlListener, mailboxAction, getter_AddRefs(mailboxurl));
rv = PrepareMessageUrl(aMessageURI, aUrlListener, mailboxAction, getter_AddRefs(mailboxurl));
if (NS_SUCCEEDED(rv))
{
@ -253,7 +253,12 @@ nsresult nsMailboxService::PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsI
{
// set up the url spec and initialize the url with it.
nsFilePath filePath(folderPath); // convert to file url representation...
urlSpec = PR_smprintf("mailbox://%s?number=%d", (const char *) filePath, msgKey);
if (mPrintingOperation)
urlSpec = PR_smprintf("mailbox://%s?number=%d&header=print", (const char *) filePath, msgKey);
else
urlSpec = PR_smprintf("mailbox://%s?number=%d", (const char *) filePath, msgKey);
nsCOMPtr <nsIMsgMailNewsUrl> url = do_QueryInterface(*aMailboxUrl);
url->SetSpec(urlSpec);
PR_FREEIF(urlSpec);
@ -347,3 +352,15 @@ NS_IMETHODIMP nsMailboxService::NewChannel(const char *verb,
return rv;
}
nsresult nsMailboxService::DisplayMessageForPrinting(const char* aMessageURI,
nsISupports * aDisplayConsumer,
nsIMsgWindow * aMsgWindow,
nsIUrlListener * aUrlListener,
nsIURI ** aURL)
{
mPrintingOperation = PR_TRUE;
nsresult rv = FetchMessage(aMessageURI, aDisplayConsumer, aMsgWindow,aUrlListener,
nsIMailboxUrl::ActionDisplayMessage, aURL);
mPrintingOperation = PR_FALSE;
return rv;
}

Просмотреть файл

@ -49,10 +49,15 @@ public:
NS_DECL_NSIPROTOCOLHANDLER
protected:
PRBool mPrintingOperation;
// helper functions used by the service
nsresult PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsIUrlListener * aUrlListener,
nsMailboxAction aMailboxAction, nsIMailboxUrl ** aMailboxUrl);
nsresult nsMailboxService::PreparePrintUrl(const char * aSrcMsgMailboxURI, nsIUrlListener * aUrlListener,
nsMailboxAction aMailboxAction, nsIMailboxUrl ** aMailboxUrl);
nsresult RunMailboxUrl(nsIURI * aMailboxUrl, nsISupports * aDisplayConsumer = nsnull);
nsresult FetchMessage(const char* aMessageURI,

Просмотреть файл

@ -655,11 +655,13 @@ nsMimeBaseEmitter::WriteHeaderFieldHTML(const char *field, const char *value)
nsresult
nsMimeBaseEmitter::WriteHeaderFieldHTMLPrefix()
{
// This mess is for Save As operations...
if ( ( (mFormat == nsMimeOutput::nsMimeMessageSaveAs) && (!mFirstHeaders) ) || // RICHIE: Goes away when we have the
( (mFormat == nsMimeOutput::nsMimeMessageQuoting) && (!mFirstHeaders) ) || // HTML-TEXT stream converter interface
( (mFormat != nsMimeOutput::nsMimeMessageSaveAs) && (mFormat != nsMimeOutput::nsMimeMessageQuoting) )
if (
( (mFormat == nsMimeOutput::nsMimeMessageSaveAs) && (mFirstHeaders) ) ||
( (mFormat == nsMimeOutput::nsMimeMessagePrintOutput) && (mFirstHeaders) )
)
/* DO NOTHING */ ; // rhp: Do nothing...leaving the conditional like this so its
// easier to see the logic of what is going on.
else
mHTMLHeaders.Append("<BR><HR WIDTH=\"90%\" SIZE=4><BR>");
mFirstHeaders = PR_FALSE;

Просмотреть файл

@ -81,7 +81,7 @@ PRBool nsMimeHtmlDisplayEmitter::BroadCastHeadersAndAttachments()
nsresult
nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTMLPrefix()
{
if (!BroadCastHeadersAndAttachments())
if (!BroadCastHeadersAndAttachments() || nsMimeOutput::nsMimeMessagePrintOutput)
return nsMimeBaseEmitter::WriteHeaderFieldHTMLPrefix();
else
return NS_OK;
@ -90,7 +90,7 @@ nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTMLPrefix()
nsresult
nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTML(const char *field, const char *value)
{
if (!BroadCastHeadersAndAttachments())
if (!BroadCastHeadersAndAttachments() || nsMimeOutput::nsMimeMessagePrintOutput)
return nsMimeBaseEmitter::WriteHeaderFieldHTML(field, value);
else
return NS_OK;
@ -99,7 +99,7 @@ nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTML(const char *field, const char *va
nsresult
nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTMLPostfix()
{
if (!BroadCastHeadersAndAttachments())
if (!BroadCastHeadersAndAttachments() || nsMimeOutput::nsMimeMessagePrintOutput)
return nsMimeBaseEmitter::WriteHeaderFieldHTMLPostfix();
else
return NS_OK;
@ -147,12 +147,23 @@ nsresult nsMimeHtmlDisplayEmitter::WriteHTMLHeaders()
UtilityWriteCRLF("<BODY>");
}
// if we aren't broadcasting headers...just do whatever
// if we aren't broadcasting headers OR printing...just do whatever
// our base class does...
if (!BroadCastHeadersAndAttachments() || !mDocHeader)
if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
{
return nsMimeBaseEmitter::WriteHTMLHeaders();
return nsMimeBaseEmitter::WriteHTMLHeaders();
}
else if (!BroadCastHeadersAndAttachments() || !mDocHeader)
{
// This needs to be here to correct the output format if we are
// not going to broadcast headers to the XUL document.
if (mFormat == nsMimeOutput::nsMimeMessageBodyDisplay)
mFormat = nsMimeOutput::nsMimeMessagePrintOutput;
return nsMimeBaseEmitter::WriteHTMLHeaders();
}
else
mFirstHeaders = PR_FALSE;
// try to get a header sink if there is one....
nsCOMPtr<nsIMsgHeaderSink> headerSink;

Просмотреть файл

@ -71,6 +71,7 @@ static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
nsNntpService::nsNntpService()
{
NS_INIT_REFCNT();
mPrintingOperation = PR_FALSE;
}
nsNntpService::~nsNntpService()
@ -161,7 +162,7 @@ nsresult nsNntpService::DisplayMessage(const char* aMessageURI, nsISupports * aD
nsCAutoString uri(aMessageURI);
nsCAutoString newsgroupName;
nsMsgKey key = nsMsgKey_None;
if (PL_strncmp(aMessageURI, kNewsMessageRootURI, kNewsMessageRootURILen) == 0)
rv = ConvertNewsMessageURI2NewsURI(aMessageURI, uri, newsgroupName, &key);
else
@ -170,6 +171,11 @@ nsresult nsNntpService::DisplayMessage(const char* aMessageURI, nsISupports * aD
// now create a url with this uri spec
nsCOMPtr<nsIURI> myuri;
// rhp: If we are displaying this message for the purposes of printing, append
// the magic operand.
if (mPrintingOperation)
uri.Append("?header=print");
rv = ConstructNntpUrl(uri, newsgroupName, key, aUrlListener, getter_AddRefs(myuri));
if (NS_SUCCEEDED(rv))
{
@ -1146,4 +1152,17 @@ nsNntpService::GetDefaultCopiesAndFoldersPrefsToServer(PRBool *aDefaultCopiesAnd
return NS_OK;
}
//
// rhp: Right now, this is the same as simple DisplayMessage, but it will change
// to support print rendering.
//
nsresult nsNntpService::DisplayMessageForPrinting(const char* aMessageURI, nsISupports * aDisplayConsumer,
nsIMsgWindow *aMsgWindow, nsIUrlListener * aUrlListener, nsIURI ** aURL)
{
mPrintingOperation = PR_TRUE;
nsresult rv = DisplayMessage(aMessageURI, aDisplayConsumer, aMsgWindow, aUrlListener, aURL);
mPrintingOperation = PR_FALSE;
return rv;
}
CMDLINEHANDLER_IMPL(nsNntpService,"-news","general.startup.news","chrome://messenger/content/","Start with news window.",NS_NNTPSERVICE_PROGID,"News Cmd Line Handler", PR_FALSE,"", PR_TRUE)

Просмотреть файл

@ -73,6 +73,8 @@ protected:
// a convience routine to run news urls
nsresult RunNewsUrl (nsIURI * aUrl, nsIMsgWindow *aMsgWindow, nsISupports * aConsumer);
static PRBool findNewsServerWithGroup(nsISupports *aElement, void *data);
PRBool mPrintingOperation; // Flag for printing operations
};
#endif /* nsNntpService_h___ */