From 19263c16218e10f1acb87c82147fdeddb44bd30b Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Sat, 28 Nov 1998 01:19:53 +0000 Subject: [PATCH] just broke the mac build. I will tell jfrancis! git-svn-id: svn://10.0.0.236/trunk@15381 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/Makefile.in | 1 + mozilla/editor/base/editor.cpp | 165 ++++++++++++++++------- mozilla/editor/base/editor.h | 9 +- mozilla/editor/base/editorInterfaces.cpp | 2 +- mozilla/editor/base/makefile.win | 4 +- mozilla/editor/base/nsEditFactory.cpp | 135 +++++++++++++++++++ mozilla/editor/base/nsEditFactory.h | 63 +++++++++ mozilla/editor/core/Makefile.in | 1 + mozilla/editor/core/editor.cpp | 165 ++++++++++++++++------- mozilla/editor/core/editor.h | 9 +- mozilla/editor/core/editorInterfaces.cpp | 2 +- mozilla/editor/core/makefile.win | 4 +- mozilla/editor/core/nsEditFactory.cpp | 135 +++++++++++++++++++ mozilla/editor/core/nsEditFactory.h | 63 +++++++++ 14 files changed, 648 insertions(+), 110 deletions(-) create mode 100644 mozilla/editor/base/nsEditFactory.cpp create mode 100644 mozilla/editor/base/nsEditFactory.h create mode 100644 mozilla/editor/core/nsEditFactory.cpp create mode 100644 mozilla/editor/core/nsEditFactory.h diff --git a/mozilla/editor/base/Makefile.in b/mozilla/editor/base/Makefile.in index 544bb08b7df..96492ca8be5 100644 --- a/mozilla/editor/base/Makefile.in +++ b/mozilla/editor/base/Makefile.in @@ -29,6 +29,7 @@ LIBRARY_NAME = ender CPPSRCS = \ editor.cpp \ editorInterfaces.cpp \ + nsEditFactory.cpp \ $(NULL) MODULE = editor diff --git a/mozilla/editor/base/editor.cpp b/mozilla/editor/base/editor.cpp index ffc5b76295c..fb7f7237da3 100644 --- a/mozilla/editor/base/editor.cpp +++ b/mozilla/editor/base/editor.cpp @@ -22,6 +22,103 @@ #include "nsIDOMText.h" #include "nsIDOMElement.h" #include "nsIDocument.h" +#include "nsRepository.h" +#include "nsEditFactory.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); + + +//monitor for the editor + + + +PRMonitor *getEditorMonitor() //if more than one person asks for the monitor at the same time for the FIRST time, we are screwed +{ + static PRMonitor *ns_editlock = nsnull; + if (nsnull == ns_editlock) + { + ns_editlock = (PRMonitor *)1; //how long will the next line take? lets cut down on the chance of reentrancy + ns_editlock = PR_NewMonitor(); + } + else if ((PRMonitor *)1 == ns_editlock) + return getEditorMonitor(); + return ns_editlock; +} + + + +/* +we must be good providers of factories ect. this is where to put ALL editor exports +*/ +//BEGIN EXPORTS +// dont ask! +#ifdef MAC_STATIC +extern "C" NS_EXPORT nsresult NSGetFactory_LAYOUT_DLL(const nsCID &aClass, +nsIFactory **aFactory) +#elif defined(MAC_SHARED) +#pragma export on +extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory +**aFactory) +#pragma export off +// for non-mac platforms: +#else +extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory +**aFactory) +#endif +{ + if (nsnull == aFactory) { + return NS_ERROR_NULL_POINTER; + } + + *aFactory = nsnull; + + if (aClass.Equals(kIEditFactoryIID)) { + return getEditFactory(aFactory); + } + return NS_NOINTERFACE; +} + + + +extern "C" NS_EXPORT PRBool +NSCanUnload(void) +{ + return PR_FALSE; //I have no idea. I am copying code here +} + + + +extern "C" NS_EXPORT nsresult +NSRegisterSelf(const char *path) +{ + return nsRepository::RegisterFactory(kIEditFactoryIID, path, + PR_TRUE, PR_TRUE); //this will register the factory with the xpcom dll. +} + + + +extern "C" NS_EXPORT nsresult +NSUnregisterSelf(const char *path) +{ + return nsRepository::UnregisterFactory(kIEditFactoryIID, path);//this will unregister the factory with the xpcom dll. +} + + + +//END EXPORTS + //class implementations are in order they are declared in editor.h @@ -32,21 +129,13 @@ nsEditor::nsEditor() } -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); - nsEditor::~nsEditor() { //the autopointers will clear themselves up. //but we need to also remove the listeners or we have a leak COM_auto_ptr erP; - nsresult t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, func_AddRefs(erP)); + nsresult t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); if (NS_SUCCEEDED( t_result )) { erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID); @@ -73,8 +162,6 @@ nsEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } - static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); if (aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*)(nsISupports*)this; NS_ADDREF_THIS(); @@ -106,13 +193,13 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) mDomInterfaceP = aDomInterface; - nsresult t_result = NS_NewEditorKeyListener(func_AddRefs(mKeyListenerP), this); + nsresult t_result = NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this); if (NS_OK != t_result) { NS_NOTREACHED("Init Failed"); return t_result; } - t_result = NS_NewEditorMouseListener(func_AddRefs(mMouseListenerP), this); + t_result = NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this); if (NS_OK != t_result) { mKeyListenerP = 0; //dont keep the key listener if the mouse listener fails. @@ -120,7 +207,7 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) return t_result; } COM_auto_ptr erP; - t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, func_AddRefs(erP)); + t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); if (NS_OK != t_result) { mKeyListenerP = 0; @@ -134,10 +221,11 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) /* now to handle selection */ + /* COM_auto_ptr document; - if (NS_SUCCEEDED(t_result = mDomInterfaceP->QueryInterface(kIDocumentIID, func_AddRefs(document)))) + if (NS_SUCCEEDED(t_result = mDomInterfaceP->QueryInterface(kIDocumentIID, getter_AddRefs(document)))) { - if (!NS_SUCCEEDED(t_result = document->GetSelection(*func_AddRefs(mSelectionP)))) + if (!NS_SUCCEEDED(t_result = document->GetSelection(*getter_AddRefs(mSelectionP)))) { NS_NOTREACHED("query interface"); return t_result; @@ -148,7 +236,7 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) NS_NOTREACHED("query interface"); return t_result; } - +*/ return NS_OK; } @@ -184,6 +272,8 @@ nsEditor::Commit(PRBool aCtrlKey) { if (aCtrlKey) { +// nsSelectionRange range; + //mSelectionP->GetRange(&range); } else { @@ -229,9 +319,9 @@ nsEditor::AppendText(nsString *aStr) COM_auto_ptr text; if (!aStr) return NS_ERROR_NULL_POINTER; - if (NS_SUCCEEDED(GetCurrentNode(func_AddRefs(currentNode))) && - NS_SUCCEEDED(GetFirstTextNode(currentNode,func_AddRefs(textNode))) && - NS_SUCCEEDED(textNode->QueryInterface(kIDOMTextIID, func_AddRefs(text)))) { + if (NS_SUCCEEDED(GetCurrentNode(getter_AddRefs(currentNode))) && + NS_SUCCEEDED(GetFirstTextNode(currentNode,getter_AddRefs(textNode))) && + NS_SUCCEEDED(textNode->QueryInterface(kIDOMTextIID, getter_AddRefs(text)))) { text->AppendData(*aStr); } @@ -248,7 +338,7 @@ nsEditor::GetCurrentNode(nsIDOMNode ** aNode) /* If no node set, get first text node */ COM_auto_ptr docNode; - if (NS_SUCCEEDED(mDomInterfaceP->GetDocumentElement(func_AddRefs(docNode)))) + if (NS_SUCCEEDED(mDomInterfaceP->GetDocumentElement(getter_AddRefs(docNode)))) { return docNode->QueryInterface(kIDOMNodeIID,(void **) aNode); } @@ -279,14 +369,14 @@ nsEditor::GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode) COM_auto_ptr node1; COM_auto_ptr node2; - if (!NS_SUCCEEDED(aNode->GetFirstChild(func_AddRefs(node1)))) + if (!NS_SUCCEEDED(aNode->GetFirstChild(getter_AddRefs(node1)))) { NS_NOTREACHED("GetFirstTextNode Failed"); } while(!answer && node1) { - GetFirstTextNode(node1, func_AddRefs(answer)); - node1->GetNextSibling(func_AddRefs(node2)); + GetFirstTextNode(node1, getter_AddRefs(answer)); + node1->GetNextSibling(getter_AddRefs(node2)); node1 = node2; } } @@ -309,30 +399,3 @@ nsEditor::GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode) -//BEGIN FACTORY METHODS - - - -nsresult -NS_InitEditor(nsIEditor ** aInstancePtrResult, nsIDOMDocument *aDomDoc) -{ - if (!aInstancePtrResult || !aDomDoc) - return NS_ERROR_NULL_POINTER; - nsEditor* editor = new nsEditor(); - if (NULL == editor) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsresult result = editor->Init(aDomDoc); - if (NS_SUCCEEDED(result)) - { - static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); - - return editor->QueryInterface(kIEditorIID, (void **) aInstancePtrResult); - } - else - return result; -} - - - -//END FACTORY METHODS diff --git a/mozilla/editor/base/editor.h b/mozilla/editor/base/editor.h index 22c0bb88f11..847ef3da58d 100644 --- a/mozilla/editor/base/editor.h +++ b/mozilla/editor/base/editor.h @@ -20,7 +20,12 @@ #include "nsIContextLoader.h" #include "COM_auto_ptr.h" #include "editorInterfaces.h" -#include "nsISelection.h" +//#include "nsISelection.h" + + +//This is the monitor for the editor. +PRMonitor *getEditorMonitor(); + /** implementation of an editor object. it will be the controler/focal point * for the main editor services. i.e. the GUIControler, publishing, transaction @@ -33,7 +38,7 @@ private: COM_auto_ptr mDomInterfaceP; COM_auto_ptr mKeyListenerP; COM_auto_ptr mMouseListenerP; - COM_auto_ptr mSelectionP; +// COM_auto_ptr mSelectionP; public: /** The default constructor. This should suffice. the setting of the interfaces is done * after the construction of the editor class. diff --git a/mozilla/editor/base/editorInterfaces.cpp b/mozilla/editor/base/editorInterfaces.cpp index 59b0c6ea931..4c12f670fa8 100644 --- a/mozilla/editor/base/editorInterfaces.cpp +++ b/mozilla/editor/base/editorInterfaces.cpp @@ -220,7 +220,7 @@ nsresult nsEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) { COM_auto_ptr target; - if (NS_OK == aMouseEvent->GetTarget(func_AddRefs(target))) { + if (NS_OK == aMouseEvent->GetTarget(getter_AddRefs(target))) { // nsSetCurrentNode(aTarget); } //Should not be error. Need a new way to do return values diff --git a/mozilla/editor/base/makefile.win b/mozilla/editor/base/makefile.win index bffabd04c48..7ca36f98c8b 100644 --- a/mozilla/editor/base/makefile.win +++ b/mozilla/editor/base/makefile.win @@ -22,11 +22,13 @@ LIBRARY_NAME=ender CPPSRCS = \ editor.cpp \ - editorInterfaces.cpp \ + editorInterfaces.cpp \ + nsEditFactory.cpp \ $(NULL) CPP_OBJS = \ .\$(OBJDIR)\editor.obj \ + .\$(OBJDIR)\nsEditFactory.obj \ .\$(OBJDIR)\editorInterfaces.obj \ $(NULL) diff --git a/mozilla/editor/base/nsEditFactory.cpp b/mozilla/editor/base/nsEditFactory.cpp new file mode 100644 index 00000000000..94291d2681b --- /dev/null +++ b/mozilla/editor/base/nsEditFactory.cpp @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://wwwt.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsEditFactory.h" +#include "nsIEditor.h" +#include "editor.h" +#include "nsRepository.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); + + + +nsresult +getEditFactory(nsIFactory **aFactory) +{ + static COM_auto_ptr g_pNSIFactory; + PR_EnterMonitor(getEditorMonitor()); + nsresult result = NS_ERROR_FAILURE; + if (!g_pNSIFactory) + { + nsEditFactory *factory = new nsEditFactory(getter_AddRefs(g_pNSIFactory)); + *aFactory = g_pNSIFactory; + } + else + result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory); + PR_ExitMonitor(getEditorMonitor()); + return NS_ERROR_FAILURE; +} + +//////////////////////////////////////////////////////////////////////////// +// from nsISupports + +NS_METHOD +nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + NS_NOTREACHED("!nsEditor"); + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIFactoryIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +NS_IMPL_ADDREF(nsEditFactory) +NS_IMPL_RELEASE(nsEditFactory) + + +//////////////////////////////////////////////////////////////////////////// +// from nsIFactory: + +NS_METHOD +nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsEditor *editor = NULL; + *aResult = NULL; + + 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; + } + return NS_OK; +} + + + +NS_METHOD +nsEditFactory::LockFactory(PRBool aLock) +{ + return NS_OK; +} + + + +//////////////////////////////////////////////////////////////////////////// +// from nsEditFactory: + +nsEditFactory::nsEditFactory(nsIFactory **aFactory) +{ + NS_INIT_REFCNT(); + nsresult err = NS_OK; + NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + if (aFactory) + { + err = this->QueryInterface(kIFactoryIID, (void**)aFactory); + //this is to be sure we have at least one + //reference to the factory + if ( (err == NS_OK) && (*aFactory != NULL) ) + { + nsRepository::RegisterFactory(kIEditFactoryIID, *aFactory, + PR_TRUE); + } + } +} + +nsEditFactory::~nsEditFactory() +{ + nsRepository::UnregisterFactory(kIEditFactoryIID, (nsIFactory *)this); //we are out of ref counts anyway +} + + + + + + + diff --git a/mozilla/editor/base/nsEditFactory.h b/mozilla/editor/base/nsEditFactory.h new file mode 100644 index 00000000000..73bfb3e2072 --- /dev/null +++ b/mozilla/editor/base/nsEditFactory.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://wwwt.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsIEditFactory_h___ +#define nsIEditFactory_h___ + +#include "nsISupports.h" +#include "nsIFactory.h" +class nsEditor; + +/* +EditFactory that can make an editor +*/ + +/** + * This supplies the neccessary entrance to the edit module. it will return any + * instantiations that we need. + */ +class nsEditFactory; + +nsresult getEditFactory(nsIFactory **); + +class nsEditFactory : public nsIFactory { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports and AggregatedQueryInterface: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIFactory: + + NS_IMETHOD + CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult); + + NS_IMETHOD + LockFactory(PRBool aLock); + + + //////////////////////////////////////////////////////////////////////////// + // from nsEditFactory: + + virtual ~nsEditFactory(void); +private: + nsEditFactory(nsIFactory **aFactory); //will fill the aFactory with the result from queryinterface + friend nsresult getEditFactory(nsIFactory **); +}; + +#endif //nsIEditFactory_h___ diff --git a/mozilla/editor/core/Makefile.in b/mozilla/editor/core/Makefile.in index 544bb08b7df..96492ca8be5 100644 --- a/mozilla/editor/core/Makefile.in +++ b/mozilla/editor/core/Makefile.in @@ -29,6 +29,7 @@ LIBRARY_NAME = ender CPPSRCS = \ editor.cpp \ editorInterfaces.cpp \ + nsEditFactory.cpp \ $(NULL) MODULE = editor diff --git a/mozilla/editor/core/editor.cpp b/mozilla/editor/core/editor.cpp index ffc5b76295c..fb7f7237da3 100644 --- a/mozilla/editor/core/editor.cpp +++ b/mozilla/editor/core/editor.cpp @@ -22,6 +22,103 @@ #include "nsIDOMText.h" #include "nsIDOMElement.h" #include "nsIDocument.h" +#include "nsRepository.h" +#include "nsEditFactory.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); + + +//monitor for the editor + + + +PRMonitor *getEditorMonitor() //if more than one person asks for the monitor at the same time for the FIRST time, we are screwed +{ + static PRMonitor *ns_editlock = nsnull; + if (nsnull == ns_editlock) + { + ns_editlock = (PRMonitor *)1; //how long will the next line take? lets cut down on the chance of reentrancy + ns_editlock = PR_NewMonitor(); + } + else if ((PRMonitor *)1 == ns_editlock) + return getEditorMonitor(); + return ns_editlock; +} + + + +/* +we must be good providers of factories ect. this is where to put ALL editor exports +*/ +//BEGIN EXPORTS +// dont ask! +#ifdef MAC_STATIC +extern "C" NS_EXPORT nsresult NSGetFactory_LAYOUT_DLL(const nsCID &aClass, +nsIFactory **aFactory) +#elif defined(MAC_SHARED) +#pragma export on +extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory +**aFactory) +#pragma export off +// for non-mac platforms: +#else +extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory +**aFactory) +#endif +{ + if (nsnull == aFactory) { + return NS_ERROR_NULL_POINTER; + } + + *aFactory = nsnull; + + if (aClass.Equals(kIEditFactoryIID)) { + return getEditFactory(aFactory); + } + return NS_NOINTERFACE; +} + + + +extern "C" NS_EXPORT PRBool +NSCanUnload(void) +{ + return PR_FALSE; //I have no idea. I am copying code here +} + + + +extern "C" NS_EXPORT nsresult +NSRegisterSelf(const char *path) +{ + return nsRepository::RegisterFactory(kIEditFactoryIID, path, + PR_TRUE, PR_TRUE); //this will register the factory with the xpcom dll. +} + + + +extern "C" NS_EXPORT nsresult +NSUnregisterSelf(const char *path) +{ + return nsRepository::UnregisterFactory(kIEditFactoryIID, path);//this will unregister the factory with the xpcom dll. +} + + + +//END EXPORTS + //class implementations are in order they are declared in editor.h @@ -32,21 +129,13 @@ nsEditor::nsEditor() } -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); - nsEditor::~nsEditor() { //the autopointers will clear themselves up. //but we need to also remove the listeners or we have a leak COM_auto_ptr erP; - nsresult t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, func_AddRefs(erP)); + nsresult t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); if (NS_SUCCEEDED( t_result )) { erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID); @@ -73,8 +162,6 @@ nsEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } - static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); if (aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*)(nsISupports*)this; NS_ADDREF_THIS(); @@ -106,13 +193,13 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) mDomInterfaceP = aDomInterface; - nsresult t_result = NS_NewEditorKeyListener(func_AddRefs(mKeyListenerP), this); + nsresult t_result = NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this); if (NS_OK != t_result) { NS_NOTREACHED("Init Failed"); return t_result; } - t_result = NS_NewEditorMouseListener(func_AddRefs(mMouseListenerP), this); + t_result = NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this); if (NS_OK != t_result) { mKeyListenerP = 0; //dont keep the key listener if the mouse listener fails. @@ -120,7 +207,7 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) return t_result; } COM_auto_ptr erP; - t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, func_AddRefs(erP)); + t_result = mDomInterfaceP->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); if (NS_OK != t_result) { mKeyListenerP = 0; @@ -134,10 +221,11 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) /* now to handle selection */ + /* COM_auto_ptr document; - if (NS_SUCCEEDED(t_result = mDomInterfaceP->QueryInterface(kIDocumentIID, func_AddRefs(document)))) + if (NS_SUCCEEDED(t_result = mDomInterfaceP->QueryInterface(kIDocumentIID, getter_AddRefs(document)))) { - if (!NS_SUCCEEDED(t_result = document->GetSelection(*func_AddRefs(mSelectionP)))) + if (!NS_SUCCEEDED(t_result = document->GetSelection(*getter_AddRefs(mSelectionP)))) { NS_NOTREACHED("query interface"); return t_result; @@ -148,7 +236,7 @@ nsEditor::Init(nsIDOMDocument *aDomInterface) NS_NOTREACHED("query interface"); return t_result; } - +*/ return NS_OK; } @@ -184,6 +272,8 @@ nsEditor::Commit(PRBool aCtrlKey) { if (aCtrlKey) { +// nsSelectionRange range; + //mSelectionP->GetRange(&range); } else { @@ -229,9 +319,9 @@ nsEditor::AppendText(nsString *aStr) COM_auto_ptr text; if (!aStr) return NS_ERROR_NULL_POINTER; - if (NS_SUCCEEDED(GetCurrentNode(func_AddRefs(currentNode))) && - NS_SUCCEEDED(GetFirstTextNode(currentNode,func_AddRefs(textNode))) && - NS_SUCCEEDED(textNode->QueryInterface(kIDOMTextIID, func_AddRefs(text)))) { + if (NS_SUCCEEDED(GetCurrentNode(getter_AddRefs(currentNode))) && + NS_SUCCEEDED(GetFirstTextNode(currentNode,getter_AddRefs(textNode))) && + NS_SUCCEEDED(textNode->QueryInterface(kIDOMTextIID, getter_AddRefs(text)))) { text->AppendData(*aStr); } @@ -248,7 +338,7 @@ nsEditor::GetCurrentNode(nsIDOMNode ** aNode) /* If no node set, get first text node */ COM_auto_ptr docNode; - if (NS_SUCCEEDED(mDomInterfaceP->GetDocumentElement(func_AddRefs(docNode)))) + if (NS_SUCCEEDED(mDomInterfaceP->GetDocumentElement(getter_AddRefs(docNode)))) { return docNode->QueryInterface(kIDOMNodeIID,(void **) aNode); } @@ -279,14 +369,14 @@ nsEditor::GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode) COM_auto_ptr node1; COM_auto_ptr node2; - if (!NS_SUCCEEDED(aNode->GetFirstChild(func_AddRefs(node1)))) + if (!NS_SUCCEEDED(aNode->GetFirstChild(getter_AddRefs(node1)))) { NS_NOTREACHED("GetFirstTextNode Failed"); } while(!answer && node1) { - GetFirstTextNode(node1, func_AddRefs(answer)); - node1->GetNextSibling(func_AddRefs(node2)); + GetFirstTextNode(node1, getter_AddRefs(answer)); + node1->GetNextSibling(getter_AddRefs(node2)); node1 = node2; } } @@ -309,30 +399,3 @@ nsEditor::GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode) -//BEGIN FACTORY METHODS - - - -nsresult -NS_InitEditor(nsIEditor ** aInstancePtrResult, nsIDOMDocument *aDomDoc) -{ - if (!aInstancePtrResult || !aDomDoc) - return NS_ERROR_NULL_POINTER; - nsEditor* editor = new nsEditor(); - if (NULL == editor) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsresult result = editor->Init(aDomDoc); - if (NS_SUCCEEDED(result)) - { - static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); - - return editor->QueryInterface(kIEditorIID, (void **) aInstancePtrResult); - } - else - return result; -} - - - -//END FACTORY METHODS diff --git a/mozilla/editor/core/editor.h b/mozilla/editor/core/editor.h index 22c0bb88f11..847ef3da58d 100644 --- a/mozilla/editor/core/editor.h +++ b/mozilla/editor/core/editor.h @@ -20,7 +20,12 @@ #include "nsIContextLoader.h" #include "COM_auto_ptr.h" #include "editorInterfaces.h" -#include "nsISelection.h" +//#include "nsISelection.h" + + +//This is the monitor for the editor. +PRMonitor *getEditorMonitor(); + /** implementation of an editor object. it will be the controler/focal point * for the main editor services. i.e. the GUIControler, publishing, transaction @@ -33,7 +38,7 @@ private: COM_auto_ptr mDomInterfaceP; COM_auto_ptr mKeyListenerP; COM_auto_ptr mMouseListenerP; - COM_auto_ptr mSelectionP; +// COM_auto_ptr mSelectionP; public: /** The default constructor. This should suffice. the setting of the interfaces is done * after the construction of the editor class. diff --git a/mozilla/editor/core/editorInterfaces.cpp b/mozilla/editor/core/editorInterfaces.cpp index 59b0c6ea931..4c12f670fa8 100644 --- a/mozilla/editor/core/editorInterfaces.cpp +++ b/mozilla/editor/core/editorInterfaces.cpp @@ -220,7 +220,7 @@ nsresult nsEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) { COM_auto_ptr target; - if (NS_OK == aMouseEvent->GetTarget(func_AddRefs(target))) { + if (NS_OK == aMouseEvent->GetTarget(getter_AddRefs(target))) { // nsSetCurrentNode(aTarget); } //Should not be error. Need a new way to do return values diff --git a/mozilla/editor/core/makefile.win b/mozilla/editor/core/makefile.win index bffabd04c48..7ca36f98c8b 100644 --- a/mozilla/editor/core/makefile.win +++ b/mozilla/editor/core/makefile.win @@ -22,11 +22,13 @@ LIBRARY_NAME=ender CPPSRCS = \ editor.cpp \ - editorInterfaces.cpp \ + editorInterfaces.cpp \ + nsEditFactory.cpp \ $(NULL) CPP_OBJS = \ .\$(OBJDIR)\editor.obj \ + .\$(OBJDIR)\nsEditFactory.obj \ .\$(OBJDIR)\editorInterfaces.obj \ $(NULL) diff --git a/mozilla/editor/core/nsEditFactory.cpp b/mozilla/editor/core/nsEditFactory.cpp new file mode 100644 index 00000000000..94291d2681b --- /dev/null +++ b/mozilla/editor/core/nsEditFactory.cpp @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://wwwt.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsEditFactory.h" +#include "nsIEditor.h" +#include "editor.h" +#include "nsRepository.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); + + + +nsresult +getEditFactory(nsIFactory **aFactory) +{ + static COM_auto_ptr g_pNSIFactory; + PR_EnterMonitor(getEditorMonitor()); + nsresult result = NS_ERROR_FAILURE; + if (!g_pNSIFactory) + { + nsEditFactory *factory = new nsEditFactory(getter_AddRefs(g_pNSIFactory)); + *aFactory = g_pNSIFactory; + } + else + result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory); + PR_ExitMonitor(getEditorMonitor()); + return NS_ERROR_FAILURE; +} + +//////////////////////////////////////////////////////////////////////////// +// from nsISupports + +NS_METHOD +nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + NS_NOTREACHED("!nsEditor"); + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIFactoryIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +NS_IMPL_ADDREF(nsEditFactory) +NS_IMPL_RELEASE(nsEditFactory) + + +//////////////////////////////////////////////////////////////////////////// +// from nsIFactory: + +NS_METHOD +nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsEditor *editor = NULL; + *aResult = NULL; + + 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; + } + return NS_OK; +} + + + +NS_METHOD +nsEditFactory::LockFactory(PRBool aLock) +{ + return NS_OK; +} + + + +//////////////////////////////////////////////////////////////////////////// +// from nsEditFactory: + +nsEditFactory::nsEditFactory(nsIFactory **aFactory) +{ + NS_INIT_REFCNT(); + nsresult err = NS_OK; + NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + if (aFactory) + { + err = this->QueryInterface(kIFactoryIID, (void**)aFactory); + //this is to be sure we have at least one + //reference to the factory + if ( (err == NS_OK) && (*aFactory != NULL) ) + { + nsRepository::RegisterFactory(kIEditFactoryIID, *aFactory, + PR_TRUE); + } + } +} + +nsEditFactory::~nsEditFactory() +{ + nsRepository::UnregisterFactory(kIEditFactoryIID, (nsIFactory *)this); //we are out of ref counts anyway +} + + + + + + + diff --git a/mozilla/editor/core/nsEditFactory.h b/mozilla/editor/core/nsEditFactory.h new file mode 100644 index 00000000000..73bfb3e2072 --- /dev/null +++ b/mozilla/editor/core/nsEditFactory.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://wwwt.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsIEditFactory_h___ +#define nsIEditFactory_h___ + +#include "nsISupports.h" +#include "nsIFactory.h" +class nsEditor; + +/* +EditFactory that can make an editor +*/ + +/** + * This supplies the neccessary entrance to the edit module. it will return any + * instantiations that we need. + */ +class nsEditFactory; + +nsresult getEditFactory(nsIFactory **); + +class nsEditFactory : public nsIFactory { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports and AggregatedQueryInterface: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIFactory: + + NS_IMETHOD + CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult); + + NS_IMETHOD + LockFactory(PRBool aLock); + + + //////////////////////////////////////////////////////////////////////////// + // from nsEditFactory: + + virtual ~nsEditFactory(void); +private: + nsEditFactory(nsIFactory **aFactory); //will fill the aFactory with the result from queryinterface + friend nsresult getEditFactory(nsIFactory **); +}; + +#endif //nsIEditFactory_h___