From 2338eaf156e178570833870aa57cb18c9bc4aa34 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Wed, 21 Apr 1999 18:52:54 +0000 Subject: [PATCH] Added editor property methods --- xpfe/AppCores/public/nsIDOMEditorAppCore.h | 13 +++ xpfe/AppCores/src/nsEditorAppCore.cpp | 97 ++++++++++++++++++---- xpfe/AppCores/src/nsEditorAppCore.h | 8 +- 3 files changed, 102 insertions(+), 16 deletions(-) diff --git a/xpfe/AppCores/public/nsIDOMEditorAppCore.h b/xpfe/AppCores/public/nsIDOMEditorAppCore.h index 6ce2d70effd9..1c18d9639a3f 100755 --- a/xpfe/AppCores/public/nsIDOMEditorAppCore.h +++ b/xpfe/AppCores/public/nsIDOMEditorAppCore.h @@ -25,6 +25,7 @@ #include "nsIScriptContext.h" #include "nsIDOMBaseAppCore.h" +class nsIDOMElement; class nsIDOMDocument; class nsIDOMSelection; class nsIDOMWindow; @@ -77,6 +78,12 @@ public: NS_IMETHOD InsertImage()=0; + NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn)=0; + + NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn)=0; + + NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn)=0; + NS_IMETHOD Exit()=0; NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin)=0; @@ -108,6 +115,9 @@ public: NS_IMETHOD InsertText(const nsString& aTextToInsert); \ NS_IMETHOD InsertLink(); \ NS_IMETHOD InsertImage(); \ + NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); \ + NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); \ + NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn); \ NS_IMETHOD Exit(); \ NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \ NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \ @@ -136,6 +146,9 @@ public: NS_IMETHOD InsertText(const nsString& aTextToInsert) { return _to##InsertText(aTextToInsert); } \ NS_IMETHOD InsertLink() { return _to##InsertLink(); } \ NS_IMETHOD InsertImage() { return _to##InsertImage(); } \ + NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { return _to##GetSelectedElement(aTagName, aReturn); } \ + NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) { return _to##CreateElementWithDefaults(aTagName, aReturn); } \ + NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) { return _to##InsertElement(aElement, aDeleteSelection, aReturn); } \ NS_IMETHOD Exit() { return _to##Exit(); } \ NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to##SetToolbarWindow(aWin); } \ NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to##SetContentWindow(aWin); } \ diff --git a/xpfe/AppCores/src/nsEditorAppCore.cpp b/xpfe/AppCores/src/nsEditorAppCore.cpp index 6bb436df23c3..882306bff7ba 100755 --- a/xpfe/AppCores/src/nsEditorAppCore.cpp +++ b/xpfe/AppCores/src/nsEditorAppCore.cpp @@ -54,6 +54,7 @@ #include "nsIPresShell.h" #include "nsIPresContext.h" #include "nsEditorMode.h" +#include "nsIDOMSelection.h" /////////////////////////////////////// // Editor Includes @@ -668,7 +669,7 @@ nsEditorAppCore::SetWebShellWindow(nsIDOMWindow* aWin) #ifdef APP_DEBUG char* cstr = str.ToNewCString(); - printf("Attaching to WebShellWindow[%s]\n", str.ToNewCString()); + printf("Attaching to WebShellWindow[%s]\n", cstr); delete[] cstr; #endif @@ -944,21 +945,18 @@ nsEditorAppCore::GetContentsAsHTML(nsString& aContentsAsHTML) return err; } - -NS_IMETHODIMP +NS_METHOD nsEditorAppCore::GetEditorDocument(nsIDOMDocument** aEditorDocument) { - - if (mEditor) - { + if (mEditor) + { nsCOMPtr editor = do_QueryInterface(mEditor); if (editor) - { - return editor->GetDocument(aEditorDocument); - } - } - - return NS_NOINTERFACE; + { + return editor->GetDocument(aEditorDocument); + } + } + return NS_NOINTERFACE; } NS_IMETHODIMP @@ -1000,7 +998,6 @@ nsEditorAppCore::InsertLink() return err; } - // Pop up the image dialog once we have dialogs ... for now, hardwire it NS_IMETHODIMP nsEditorAppCore::InsertImage() @@ -1032,6 +1029,78 @@ nsEditorAppCore::InsertImage() return err; } +NS_IMETHODIMP +nsEditorAppCore::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) +{ + if (!aReturn) + return NS_ERROR_NULL_POINTER; + + nsresult err = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + return htmlEditor->GetSelectedElement(aTagName, aReturn); + } + break; + case ePlainTextEditorType: + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} + +NS_IMETHODIMP +nsEditorAppCore::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) +{ + if (!aReturn) + return NS_ERROR_NULL_POINTER; + + nsresult err = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + return htmlEditor->CreateElementWithDefaults(aTagName, aReturn); + } + break; + case ePlainTextEditorType: + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} + + +NS_IMETHODIMP +nsEditorAppCore::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) +{ + if (!aElement || !aReturn) + return NS_ERROR_NULL_POINTER; + + nsresult err = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + err = htmlEditor->InsertElement(aElement, aDeleteSelection, aReturn); + } + break; + case ePlainTextEditorType: + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + + return err; +} NS_IMETHODIMP nsEditorAppCore::BeginBatchChanges() @@ -1356,7 +1425,7 @@ nsEditorAppCore::ExecuteScript(nsIScriptContext * aContext, const nsString& aScr #ifdef APP_DEBUG char* script_str = aScript.ToNewCString(); - printf("Executing [%s]\n", aScript.ToNewCString()); + printf("Executing [%s]\n", script_str); delete[] script_str; #endif diff --git a/xpfe/AppCores/src/nsEditorAppCore.h b/xpfe/AppCores/src/nsEditorAppCore.h index 1fbac3ccead8..4118965fc94b 100755 --- a/xpfe/AppCores/src/nsEditorAppCore.h +++ b/xpfe/AppCores/src/nsEditorAppCore.h @@ -60,6 +60,10 @@ class nsEditorAppCore : public nsBaseAppCore, NS_IMETHOD GetId(nsString& aId) { return nsBaseAppCore::GetId(aId); } NS_IMETHOD SetDocumentCharset(const nsString& aCharset) { return nsBaseAppCore::SetDocumentCharset(aCharset); } + NS_IMETHOD GetEditorDocument(nsIDOMDocument** aEditorDocument); + NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); + NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); + NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn); NS_IMETHOD SetEditorType(const nsString& aEditorType); NS_IMETHOD SetTextProperty(const nsString& aProp, const nsString& aAttr, @@ -71,7 +75,6 @@ class nsEditorAppCore : public nsBaseAppCore, PRBool* aFirstHas, PRBool* aAnyHas, PRBool* aAllHas); NS_IMETHOD GetContentsAsText(nsString& aContentsAsText); NS_IMETHOD GetContentsAsHTML(nsString& aContentsAsHTML); - NS_IMETHOD GetEditorDocument(nsIDOMDocument** aEditorDocument); NS_IMETHOD GetEditorSelection(nsIDOMSelection** aEditorSelection); NS_IMETHOD Undo(); @@ -95,9 +98,10 @@ class nsEditorAppCore : public nsBaseAppCore, NS_IMETHOD InsertText(const nsString& textToInsert); + // These next two will be replaced with the SetElementProperties NS_IMETHOD InsertLink(); NS_IMETHOD InsertImage(); - + NS_IMETHOD BeginBatchChanges(); NS_IMETHOD EndBatchChanges();