Added editor property methods

This commit is contained in:
cmanske%netscape.com 1999-04-21 18:52:54 +00:00
parent f16044cdd0
commit 2338eaf156
3 changed files with 102 additions and 16 deletions

View File

@ -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); } \

View File

@ -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<nsIEditor> 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<nsIHTMLEditor> 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<nsIHTMLEditor> 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<nsIHTMLEditor> 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

View File

@ -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();