This commit is contained in:
mjudge%netscape.com 1998-12-11 01:03:12 +00:00
Родитель aa1aa005f0
Коммит c894debbc8
6 изменённых файлов: 84 добавлений и 72 удалений

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

@ -25,20 +25,22 @@
#include "nsIDocument.h"
#include "nsRepository.h"
#include "nsEditFactory.h"
#include "nsEditorCID.h"
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID);
//monitor for the editor
@ -73,7 +75,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory
*aFactory = nsnull;
if (aClass.Equals(kIEditFactoryIID)) {
if (aClass.Equals(kEditorCID)) {
return getEditFactory(aFactory);
}
return NS_NOINTERFACE;
@ -115,6 +117,7 @@ NSUnregisterSelf(const char *path)
nsEditor::nsEditor()
{
//initialize member variables here
NS_INIT_REFCNT();
}

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

@ -20,12 +20,13 @@
#include "nsIEditor.h"
#include "editor.h"
#include "nsRepository.h"
#include "nsEditorCID.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID);
@ -37,14 +38,12 @@ getEditFactory(nsIFactory **aFactory)
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsEditFactory *factory = new nsEditFactory(getter_AddRefs(g_pNSIFactory));
*aFactory = g_pNSIFactory;
NS_IF_ADDREF(*aFactory);
nsEditFactory *factory = new nsEditFactory(kEditorCID);
g_pNSIFactory = factory;
if (factory)
result = NS_OK;
}
else
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
PR_ExitMonitor(getEditorMonitor());
return result;
}
@ -62,7 +61,7 @@ nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
if (aIID.Equals(kIFactoryIID) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) this;
AddRef();
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
@ -78,18 +77,23 @@ NS_IMPL_RELEASE(nsEditFactory)
NS_METHOD
nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsEditor *editor = nsnull;
*aResult = nsnull;
nsISupports *obj = nsnull;
if (!aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
editor = new nsEditor();
if (editor->QueryInterface(aIID,
(void**)aResult) != NS_OK) {
// then we're trying get a interface other than nsISupports and
// nsIEditor
delete editor;
return NS_ERROR_FAILURE;
if (mCID.Equals(kEditorCID))
obj = (nsISupports *)new nsEditor();
//more class ids to support. here
if (NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
{
delete obj;
return NS_NOINTERFACE;
}
return NS_OK;
}
@ -107,20 +111,15 @@ nsEditFactory::LockFactory(PRBool aLock)
////////////////////////////////////////////////////////////////////////////
// from nsEditFactory:
nsEditFactory::nsEditFactory(nsIFactory **aFactory)
nsEditFactory::nsEditFactory(const nsCID &aClass)
:mCID(aClass)
{
NS_INIT_REFCNT();
nsresult err = NS_OK;
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
if (aFactory)
{
err = this->QueryInterface(kIFactoryIID, (void**)aFactory);
}
}
nsEditFactory::~nsEditFactory()
{
nsRepository::UnregisterFactory(kIEditFactoryIID, (nsIFactory *)this); //we are out of ref counts anyway
nsRepository::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
}

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

@ -20,7 +20,6 @@
#include "nsISupports.h"
#include "nsIFactory.h"
class nsEditor;
/*
EditFactory that can make an editor
@ -56,8 +55,13 @@ public:
virtual ~nsEditFactory(void);
private:
nsEditFactory(nsIFactory **aFactory); //will fill the aFactory with the result from queryinterface
nsEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
/** getEditFactory
* creates an edit factory other CSID supported friend functions here.
*/
friend nsresult getEditFactory(nsIFactory **);
const nsCID &mCID;
};
#endif //nsIEditFactory_h___

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

@ -25,20 +25,22 @@
#include "nsIDocument.h"
#include "nsRepository.h"
#include "nsEditFactory.h"
#include "nsEditorCID.h"
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID);
//monitor for the editor
@ -73,7 +75,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory
*aFactory = nsnull;
if (aClass.Equals(kIEditFactoryIID)) {
if (aClass.Equals(kEditorCID)) {
return getEditFactory(aFactory);
}
return NS_NOINTERFACE;
@ -115,6 +117,7 @@ NSUnregisterSelf(const char *path)
nsEditor::nsEditor()
{
//initialize member variables here
NS_INIT_REFCNT();
}

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

@ -20,12 +20,13 @@
#include "nsIEditor.h"
#include "editor.h"
#include "nsRepository.h"
#include "nsEditorCID.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID);
@ -37,14 +38,12 @@ getEditFactory(nsIFactory **aFactory)
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsEditFactory *factory = new nsEditFactory(getter_AddRefs(g_pNSIFactory));
*aFactory = g_pNSIFactory;
NS_IF_ADDREF(*aFactory);
nsEditFactory *factory = new nsEditFactory(kEditorCID);
g_pNSIFactory = factory;
if (factory)
result = NS_OK;
}
else
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
PR_ExitMonitor(getEditorMonitor());
return result;
}
@ -62,7 +61,7 @@ nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
if (aIID.Equals(kIFactoryIID) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) this;
AddRef();
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
@ -78,18 +77,23 @@ NS_IMPL_RELEASE(nsEditFactory)
NS_METHOD
nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsEditor *editor = nsnull;
*aResult = nsnull;
nsISupports *obj = nsnull;
if (!aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
editor = new nsEditor();
if (editor->QueryInterface(aIID,
(void**)aResult) != NS_OK) {
// then we're trying get a interface other than nsISupports and
// nsIEditor
delete editor;
return NS_ERROR_FAILURE;
if (mCID.Equals(kEditorCID))
obj = (nsISupports *)new nsEditor();
//more class ids to support. here
if (NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
{
delete obj;
return NS_NOINTERFACE;
}
return NS_OK;
}
@ -107,20 +111,15 @@ nsEditFactory::LockFactory(PRBool aLock)
////////////////////////////////////////////////////////////////////////////
// from nsEditFactory:
nsEditFactory::nsEditFactory(nsIFactory **aFactory)
nsEditFactory::nsEditFactory(const nsCID &aClass)
:mCID(aClass)
{
NS_INIT_REFCNT();
nsresult err = NS_OK;
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
if (aFactory)
{
err = this->QueryInterface(kIFactoryIID, (void**)aFactory);
}
}
nsEditFactory::~nsEditFactory()
{
nsRepository::UnregisterFactory(kIEditFactoryIID, (nsIFactory *)this); //we are out of ref counts anyway
nsRepository::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
}

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

@ -20,7 +20,6 @@
#include "nsISupports.h"
#include "nsIFactory.h"
class nsEditor;
/*
EditFactory that can make an editor
@ -56,8 +55,13 @@ public:
virtual ~nsEditFactory(void);
private:
nsEditFactory(nsIFactory **aFactory); //will fill the aFactory with the result from queryinterface
nsEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
/** getEditFactory
* creates an edit factory other CSID supported friend functions here.
*/
friend nsresult getEditFactory(nsIFactory **);
const nsCID &mCID;
};
#endif //nsIEditFactory_h___