changes for printing from addressbook

This commit is contained in:
sspitzer%netscape.com 1999-08-06 07:42:20 +00:00
Родитель b1484ea0ab
Коммит 20e4a07aa6
5 изменённых файлов: 99 добавлений и 3 удалений

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

@ -27,11 +27,16 @@
#include "nsIDOMXULElement.h"
%}
interface nsIDOMWindow;
[scriptable, uuid(D60B84F1-2A8C-11d3-9E07-00A0C92B5F0D)]
interface nsIAddressBook : nsISupports {
void DeleteCards(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node);
void NewAddressBook(in nsIRDFCompositeDataSource db, in nsIDOMXULElement srcDir, in string name);
void DeleteAddressBook(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node);
void PrintCard();
void PrintAddressbook();
void SetWebShellWindow(in nsIDOMWindow win);
};

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

@ -9,6 +9,13 @@ function OnLoadAddressBook()
top.addressbook = Components.classes["component://netscape/addressbook"].createInstance();
top.addressbook = top.addressbook.QueryInterface(Components.interfaces.nsIAddressBook);
try {
top.addressbook.SetWebShellWindow(window)
}
catch (ex) {
dump("failed to set webshell window\n");
}
}
@ -56,4 +63,24 @@ function AbCreateNewAddressBook(name)
top.addressbook.NewAddressBook(document.getElementById('dirTree').database, document.getElementById('resultsTree'), name);
}
function AbPrintCard()
{
dump("print card\n");
try {
addressbook.PrintCard();
}
catch (ex) {
dump("failed to print card\n");
}
}
function AbPrintAddressBook()
{
dump("print address book \n");
try {
addressbook.PrintAddressbook();
}
catch (ex) {
dump("failed to print address book\n");
}
}

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

@ -65,7 +65,7 @@ Rights Reserved.
<menuseparator/>
<menuitem id="pageSetup"/>
<menuitem value="&printPreviewCmd.label;" onaction="AbPrintPreview()"/>
<menuitem value="&printCardViewCmd.label;" onaction="AbCardView()"/>
<menuitem value="&printCardViewCmd.label;" onaction="AbPrintCard()"/>
<menuitem value="&printAddressBook.label;" onaction="AbPrintAddressBook()"/>
<menuseparator/>
<menuitem value="&closeCmd.label;" onaction="AbClose()"/>

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

@ -37,6 +37,8 @@
#include "nsFileLocations.h"
#include "nsAppShellCIDs.h"
#include "nsIAppShellService.h"
#include "nsIDOMWindow.h"
#include "nsIContentViewer.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
@ -264,3 +266,61 @@ nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, char *command,
}
nsresult nsAddressBook::PrintCard()
{
#ifdef DEBUG_seth
printf("nsAddressBook::PrintCard()\n");
#endif
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIContentViewer> viewer;
if (!mWebShell) {
#ifdef DEBUG_seth
printf("can't print, there is no webshell\n");
#endif
return rv;
}
mWebShell->GetContentViewer(getter_AddRefs(viewer));
if (viewer) {
rv = viewer->Print();
}
#ifdef DEBUG_seth
else {
printf("failed to get the viewer for printing\n");
}
#endif
return rv;
}
nsresult nsAddressBook::PrintAddressbook()
{
#ifdef DEBUG_seth
printf("nsAddressBook::PrintAddressbook()\n");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsAddressBook::SetWebShellWindow(nsIDOMWindow *aWin)
{
NS_PRECONDITION(aWin != nsnull, "null ptr");
if (!aWin)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
if (!webShell)
return NS_ERROR_NOT_INITIALIZED;
mWebShell = webShell;
return NS_OK;
}

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

@ -23,7 +23,8 @@
#include "nsIAbCard.h"
#include "nsCOMPtr.h"
#include "nsIAddrDatabase.h"
#include "nsIWebShell.h"
#include "nsIScriptGlobalObject.h"
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewCard"
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
@ -42,12 +43,15 @@ public:
NS_IMETHOD DeleteCards(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList);
NS_IMETHOD NewAddressBook(nsIRDFCompositeDataSource* db, nsIDOMXULElement *srcDirectory, const char *name);
NS_IMETHOD DeleteAddressBook(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList);
NS_IMETHOD PrintCard();
NS_IMETHOD PrintAddressbook();
NS_IMETHOD SetWebShellWindow(nsIDOMWindow *win);
protected:
nsresult DoCommand(nsIRDFCompositeDataSource *db, char * command, nsISupportsArray *srcArray,
nsISupportsArray *arguments);
private:
nsIWebShell *mWebShell; // weak reference
};
#endif