diff --git a/mozilla/editor/base/nsEditorEventListeners.cpp b/mozilla/editor/base/nsEditorEventListeners.cpp
index 7b026d90f5b..8ada50ad02e 100644
--- a/mozilla/editor/base/nsEditorEventListeners.cpp
+++ b/mozilla/editor/base/nsEditorEventListeners.cpp
@@ -322,17 +322,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
if (mEditor)
{
nsString nsstr ("This is bold and emphasized");
- nsCOMPtr supp;
- nsresult res = NS_NewStringInputStream(getter_AddRefs(supp),
- nsstr);
- if (NS_SUCCEEDED(res))
- {
- nsCOMPtr stream = do_QueryInterface(supp);
- res = mEditor->Insert(stream);
- if (!NS_SUCCEEDED(res))
- printf("nsTextEditor::Insert(stream) failed\n");
- }
- else printf("Couldn't create the input stream\n");
+ nsresult res = mEditor->Insert(nsstr);
+ if (!NS_SUCCEEDED(res))
+ printf("nsTextEditor::Insert(string) failed\n");
}
}
break;
diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp
index 04d5ab81dba..1255cda6236 100644
--- a/mozilla/editor/base/nsHTMLEditor.cpp
+++ b/mozilla/editor/base/nsHTMLEditor.cpp
@@ -25,6 +25,8 @@
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMSelection.h"
+#include "nsIDOMHTMLAnchorElement.h"
+#include "nsIDOMHTMLImageElement.h"
#include "nsEditorCID.h"
#include "nsIComponentManager.h"
@@ -311,9 +313,9 @@ NS_IMETHODIMP nsHTMLEditor::Paste()
return nsTextEditor::Paste();
}
-NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
+NS_IMETHODIMP nsHTMLEditor::Insert(nsString& aInputString)
{
- return nsTextEditor::Insert(aInputStream);
+ return nsTextEditor::Insert(aInputString);
}
NS_IMETHODIMP nsHTMLEditor::OutputText(nsString& aOutputString)
@@ -331,3 +333,149 @@ NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsString& aOutputString)
//
// Note: Table Editing methods are implemented in EditTable.cpp
//
+
+NS_IMETHODIMP
+nsHTMLEditor::InsertLink(nsString& aURL)
+{
+ nsresult res = nsEditor::BeginTransaction();
+
+ // Find out if the selection is collapsed:
+ nsCOMPtr selection;
+ res = GetSelection(getter_AddRefs(selection));
+ if (!NS_SUCCEEDED(res) || !selection)
+ {
+#ifdef DEBUG_akkana
+ printf("Can't get selection!");
+#endif
+ return res;
+ }
+ PRBool isCollapsed;
+ res = selection->IsCollapsed(&isCollapsed);
+ if (!NS_SUCCEEDED(res))
+ isCollapsed = PR_TRUE;
+
+ // Temporary: we need to save the contents of the selection,
+ // then insert them back in as the child of the newly created
+ // anchor node in order to put the link around the selection.
+ // This will require copying the selection into a document fragment,
+ // then splicing the document fragment back into the tree after the
+ // new anchor node has been put in place. As a temporary solution,
+ // Copy/Paste does this for us in the text case
+ // (and eventually in all cases).
+ if (!isCollapsed)
+ (void)Copy();
+
+ nsCOMPtr newNode;
+ nsAutoString tag("A");
+ res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
+ if (!NS_SUCCEEDED(res) || !newNode)
+ return res;
+
+ nsCOMPtr anchor (do_QueryInterface(newNode));
+ if (!anchor)
+ {
+#ifdef DEBUG_akkana
+ printf("Not an anchor element\n");
+#endif
+ return NS_NOINTERFACE;
+ }
+
+ res = anchor->SetHref(aURL);
+ if (!NS_SUCCEEDED(res))
+ {
+#ifdef DEBUG_akkana
+ printf("SetHref failed");
+#endif
+ return res;
+ }
+
+ // Set the selection to the node we just inserted:
+ res = GetSelection(getter_AddRefs(selection));
+ if (!NS_SUCCEEDED(res) || !selection)
+ {
+#ifdef DEBUG_akkana
+ printf("Can't get selection!");
+#endif
+ return res;
+ }
+ res = selection->Collapse(newNode, 0);
+ if (!NS_SUCCEEDED(res))
+ {
+#ifdef DEBUG_akkana
+ printf("Couldn't collapse");
+#endif
+ return res;
+ }
+
+ // If we weren't collapsed, paste the old selection back in under the link:
+ if (!isCollapsed)
+ (void)Paste();
+ // Otherwise (we were collapsed) insert some bogus text in
+ // so the link will be visible
+ else
+ {
+ nsString link("[***]");
+ (void) InsertText(link); // ignore return value -- we don't care
+ }
+
+ nsEditor::EndTransaction(); // don't return this result!
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHTMLEditor::InsertImage(nsString& aURL,
+ nsString& aWidth, nsString& aHeight,
+ nsString& aHspace, nsString& aVspace,
+ nsString& aBorder,
+ nsString& aAlt,
+ nsString& aAlignment)
+{
+ nsresult res = nsEditor::BeginTransaction();
+
+ nsCOMPtr newNode;
+ nsAutoString tag("IMG");
+ res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
+ if (!NS_SUCCEEDED(res) || !newNode)
+ return res;
+
+ nsCOMPtr image (do_QueryInterface(newNode));
+ if (!image)
+ {
+#ifdef DEBUG_akkana
+ printf("Not an image element\n");
+#endif
+ return NS_NOINTERFACE;
+ }
+
+ res = image->SetSrc(aURL);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetWidth(aWidth);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetHeight(aHeight);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetHspace(aHspace);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetVspace(aVspace);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetBorder(aBorder);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetAlt(aAlt);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetAlign(aAlignment);
+ if (!NS_SUCCEEDED(res))
+ return res;
+
+ nsEditor::EndTransaction(); // don't return this result!
+
+ return NS_OK;
+}
+
+
diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h
index fdcdc17ed6d..dae03c1308f 100644
--- a/mozilla/editor/base/nsHTMLEditor.h
+++ b/mozilla/editor/base/nsHTMLEditor.h
@@ -84,12 +84,18 @@ public:
NS_IMETHOD Paste();
// Input/Output
- NS_IMETHOD Insert(nsIInputStream *aInputStream);
+ NS_IMETHOD Insert(nsString& aInputString);
NS_IMETHOD OutputText(nsString& aOutputString);
NS_IMETHOD OutputHTML(nsString& aOutputString);
//=====================================
// HTML Editing methods
+ NS_IMETHOD InsertLink(nsString& aURL);
+ NS_IMETHOD InsertImage(nsString& aURL,
+ nsString& aWidth, nsString& aHeight,
+ nsString& aHspace, nsString& aVspace,
+ nsString& aBorder,
+ nsString& aAlt, nsString& aAlignment);
// Table Editing (implemented in EditTable.cpp)
NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn);
diff --git a/mozilla/editor/base/nsTextEditRules.cpp b/mozilla/editor/base/nsTextEditRules.cpp
index b2922bd7bcd..4ad59e1a040 100644
--- a/mozilla/editor/base/nsTextEditRules.cpp
+++ b/mozilla/editor/base/nsTextEditRules.cpp
@@ -64,7 +64,7 @@ PRBool nsTextEditRules::IsEditable(nsIDOMNode *aNode)
{
nsAutoString att(kMOZEditorBogusNodeAttr);
nsAutoString val;
- nsresult result = element->GetAttribute(att, val);
+ (void)element->GetAttribute(att, val);
if (val.Equals(kMOZEditorBogusNodeValue)) {
return PR_FALSE;
}
@@ -392,7 +392,7 @@ nsTextEditRules:: DidUndo(nsIDOMSelection *aSelection, nsresult aResult)
{
nsAutoString att(kMOZEditorBogusNodeAttr);
nsAutoString val;
- nsresult result = element->GetAttribute(att, val);
+ (void)element->GetAttribute(att, val);
if (val.Equals(kMOZEditorBogusNodeValue)) {
mBogusNode = do_QueryInterface(element);
}
@@ -438,7 +438,7 @@ nsTextEditRules::DidRedo(nsIDOMSelection *aSelection, nsresult aResult)
{
nsAutoString att(kMOZEditorBogusNodeAttr);
nsAutoString val;
- nsresult result = element->GetAttribute(att, val);
+ (void)element->GetAttribute(att, val);
if (val.Equals(kMOZEditorBogusNodeValue)) {
mBogusNode = do_QueryInterface(element);
}
diff --git a/mozilla/editor/base/nsTextEditor.cpp b/mozilla/editor/base/nsTextEditor.cpp
index a1ad04c16b2..e35b3bf62a1 100644
--- a/mozilla/editor/base/nsTextEditor.cpp
+++ b/mozilla/editor/base/nsTextEditor.cpp
@@ -625,8 +625,9 @@ NS_IMETHODIMP nsTextEditor::Paste()
return nsEditor::Paste();
}
-NS_IMETHODIMP nsTextEditor::Insert(nsIInputStream *aInputStream)
+NS_IMETHODIMP nsTextEditor::Insert(nsString& aInputString)
{
+ printf("nsTextEditor::Insert not yet implemented\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
diff --git a/mozilla/editor/base/nsTextEditor.h b/mozilla/editor/base/nsTextEditor.h
index d2d39209db3..01faa2fbf04 100644
--- a/mozilla/editor/base/nsTextEditor.h
+++ b/mozilla/editor/base/nsTextEditor.h
@@ -84,7 +84,7 @@ public:
NS_IMETHOD Paste();
// Input/Output
- NS_IMETHOD Insert(nsIInputStream *aInputStream);
+ NS_IMETHOD Insert(nsString& aInputString);
NS_IMETHOD OutputText(nsString& aOutputString);
NS_IMETHOD OutputHTML(nsString& aOutputString);
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
index 04d5ab81dba..1255cda6236 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
@@ -25,6 +25,8 @@
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMSelection.h"
+#include "nsIDOMHTMLAnchorElement.h"
+#include "nsIDOMHTMLImageElement.h"
#include "nsEditorCID.h"
#include "nsIComponentManager.h"
@@ -311,9 +313,9 @@ NS_IMETHODIMP nsHTMLEditor::Paste()
return nsTextEditor::Paste();
}
-NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
+NS_IMETHODIMP nsHTMLEditor::Insert(nsString& aInputString)
{
- return nsTextEditor::Insert(aInputStream);
+ return nsTextEditor::Insert(aInputString);
}
NS_IMETHODIMP nsHTMLEditor::OutputText(nsString& aOutputString)
@@ -331,3 +333,149 @@ NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsString& aOutputString)
//
// Note: Table Editing methods are implemented in EditTable.cpp
//
+
+NS_IMETHODIMP
+nsHTMLEditor::InsertLink(nsString& aURL)
+{
+ nsresult res = nsEditor::BeginTransaction();
+
+ // Find out if the selection is collapsed:
+ nsCOMPtr selection;
+ res = GetSelection(getter_AddRefs(selection));
+ if (!NS_SUCCEEDED(res) || !selection)
+ {
+#ifdef DEBUG_akkana
+ printf("Can't get selection!");
+#endif
+ return res;
+ }
+ PRBool isCollapsed;
+ res = selection->IsCollapsed(&isCollapsed);
+ if (!NS_SUCCEEDED(res))
+ isCollapsed = PR_TRUE;
+
+ // Temporary: we need to save the contents of the selection,
+ // then insert them back in as the child of the newly created
+ // anchor node in order to put the link around the selection.
+ // This will require copying the selection into a document fragment,
+ // then splicing the document fragment back into the tree after the
+ // new anchor node has been put in place. As a temporary solution,
+ // Copy/Paste does this for us in the text case
+ // (and eventually in all cases).
+ if (!isCollapsed)
+ (void)Copy();
+
+ nsCOMPtr newNode;
+ nsAutoString tag("A");
+ res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
+ if (!NS_SUCCEEDED(res) || !newNode)
+ return res;
+
+ nsCOMPtr anchor (do_QueryInterface(newNode));
+ if (!anchor)
+ {
+#ifdef DEBUG_akkana
+ printf("Not an anchor element\n");
+#endif
+ return NS_NOINTERFACE;
+ }
+
+ res = anchor->SetHref(aURL);
+ if (!NS_SUCCEEDED(res))
+ {
+#ifdef DEBUG_akkana
+ printf("SetHref failed");
+#endif
+ return res;
+ }
+
+ // Set the selection to the node we just inserted:
+ res = GetSelection(getter_AddRefs(selection));
+ if (!NS_SUCCEEDED(res) || !selection)
+ {
+#ifdef DEBUG_akkana
+ printf("Can't get selection!");
+#endif
+ return res;
+ }
+ res = selection->Collapse(newNode, 0);
+ if (!NS_SUCCEEDED(res))
+ {
+#ifdef DEBUG_akkana
+ printf("Couldn't collapse");
+#endif
+ return res;
+ }
+
+ // If we weren't collapsed, paste the old selection back in under the link:
+ if (!isCollapsed)
+ (void)Paste();
+ // Otherwise (we were collapsed) insert some bogus text in
+ // so the link will be visible
+ else
+ {
+ nsString link("[***]");
+ (void) InsertText(link); // ignore return value -- we don't care
+ }
+
+ nsEditor::EndTransaction(); // don't return this result!
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHTMLEditor::InsertImage(nsString& aURL,
+ nsString& aWidth, nsString& aHeight,
+ nsString& aHspace, nsString& aVspace,
+ nsString& aBorder,
+ nsString& aAlt,
+ nsString& aAlignment)
+{
+ nsresult res = nsEditor::BeginTransaction();
+
+ nsCOMPtr newNode;
+ nsAutoString tag("IMG");
+ res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
+ if (!NS_SUCCEEDED(res) || !newNode)
+ return res;
+
+ nsCOMPtr image (do_QueryInterface(newNode));
+ if (!image)
+ {
+#ifdef DEBUG_akkana
+ printf("Not an image element\n");
+#endif
+ return NS_NOINTERFACE;
+ }
+
+ res = image->SetSrc(aURL);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetWidth(aWidth);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetHeight(aHeight);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetHspace(aHspace);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetVspace(aVspace);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetBorder(aBorder);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetAlt(aAlt);
+ if (!NS_SUCCEEDED(res))
+ return res;
+ res = image->SetAlign(aAlignment);
+ if (!NS_SUCCEEDED(res))
+ return res;
+
+ nsEditor::EndTransaction(); // don't return this result!
+
+ return NS_OK;
+}
+
+
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h
index fdcdc17ed6d..dae03c1308f 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.h
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h
@@ -84,12 +84,18 @@ public:
NS_IMETHOD Paste();
// Input/Output
- NS_IMETHOD Insert(nsIInputStream *aInputStream);
+ NS_IMETHOD Insert(nsString& aInputString);
NS_IMETHOD OutputText(nsString& aOutputString);
NS_IMETHOD OutputHTML(nsString& aOutputString);
//=====================================
// HTML Editing methods
+ NS_IMETHOD InsertLink(nsString& aURL);
+ NS_IMETHOD InsertImage(nsString& aURL,
+ nsString& aWidth, nsString& aHeight,
+ nsString& aHspace, nsString& aVspace,
+ nsString& aBorder,
+ nsString& aAlt, nsString& aAlignment);
// Table Editing (implemented in EditTable.cpp)
NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn);
diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp
index 7b026d90f5b..8ada50ad02e 100644
--- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp
+++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp
@@ -322,17 +322,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
if (mEditor)
{
nsString nsstr ("This is bold and emphasized");
- nsCOMPtr supp;
- nsresult res = NS_NewStringInputStream(getter_AddRefs(supp),
- nsstr);
- if (NS_SUCCEEDED(res))
- {
- nsCOMPtr stream = do_QueryInterface(supp);
- res = mEditor->Insert(stream);
- if (!NS_SUCCEEDED(res))
- printf("nsTextEditor::Insert(stream) failed\n");
- }
- else printf("Couldn't create the input stream\n");
+ nsresult res = mEditor->Insert(nsstr);
+ if (!NS_SUCCEEDED(res))
+ printf("nsTextEditor::Insert(string) failed\n");
}
}
break;
diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.cpp b/mozilla/editor/libeditor/text/nsTextEditRules.cpp
index b2922bd7bcd..4ad59e1a040 100644
--- a/mozilla/editor/libeditor/text/nsTextEditRules.cpp
+++ b/mozilla/editor/libeditor/text/nsTextEditRules.cpp
@@ -64,7 +64,7 @@ PRBool nsTextEditRules::IsEditable(nsIDOMNode *aNode)
{
nsAutoString att(kMOZEditorBogusNodeAttr);
nsAutoString val;
- nsresult result = element->GetAttribute(att, val);
+ (void)element->GetAttribute(att, val);
if (val.Equals(kMOZEditorBogusNodeValue)) {
return PR_FALSE;
}
@@ -392,7 +392,7 @@ nsTextEditRules:: DidUndo(nsIDOMSelection *aSelection, nsresult aResult)
{
nsAutoString att(kMOZEditorBogusNodeAttr);
nsAutoString val;
- nsresult result = element->GetAttribute(att, val);
+ (void)element->GetAttribute(att, val);
if (val.Equals(kMOZEditorBogusNodeValue)) {
mBogusNode = do_QueryInterface(element);
}
@@ -438,7 +438,7 @@ nsTextEditRules::DidRedo(nsIDOMSelection *aSelection, nsresult aResult)
{
nsAutoString att(kMOZEditorBogusNodeAttr);
nsAutoString val;
- nsresult result = element->GetAttribute(att, val);
+ (void)element->GetAttribute(att, val);
if (val.Equals(kMOZEditorBogusNodeValue)) {
mBogusNode = do_QueryInterface(element);
}
diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h
index 83c0e56d017..98bebfac5f0 100644
--- a/mozilla/editor/public/nsIHTMLEditor.h
+++ b/mozilla/editor/public/nsIHTMLEditor.h
@@ -76,7 +76,7 @@ public:
NS_IMETHOD Copy()=0;
NS_IMETHOD Paste()=0;
- NS_IMETHOD Insert(nsIInputStream *aInputStream)=0;
+ NS_IMETHOD Insert(nsString &aInputString)=0;
NS_IMETHOD OutputText(nsString& aOutputString)=0;
NS_IMETHOD OutputHTML(nsString& aOutputString)=0;
@@ -92,6 +92,12 @@ public:
* trigger off of ContentChanged notifications.
*/
+ NS_IMETHOD InsertLink(nsString& aURL)=0;
+ NS_IMETHOD InsertImage(nsString& aURL,
+ nsString& aWidth, nsString& aHeight,
+ nsString& aHspace, nsString& aVspace,
+ nsString& aBorder,
+ nsString& aAlt, nsString& aAlignment)=0;
// Table editing Methods
NS_IMETHOD InsertTable()=0;
diff --git a/mozilla/editor/public/nsITextEditor.h b/mozilla/editor/public/nsITextEditor.h
index 5ba93b3a105..2c110c49d16 100644
--- a/mozilla/editor/public/nsITextEditor.h
+++ b/mozilla/editor/public/nsITextEditor.h
@@ -254,7 +254,7 @@ public:
// Input/Output
// nsString will be a stream, as soon as I can figure out what kind of stream we should be using
- NS_IMETHOD Insert(nsIInputStream *aInputStream)=0;
+ NS_IMETHOD Insert(nsString& aInputString)=0;
NS_IMETHOD OutputText(nsString& aOutputString)=0;
NS_IMETHOD OutputHTML(nsString& aOutputString)=0;
diff --git a/mozilla/xpfe/AppCores/idl/EditorAppCore.idl b/mozilla/xpfe/AppCores/idl/EditorAppCore.idl
index 234bc5b5814..cabb8443fe3 100755
--- a/mozilla/xpfe/AppCores/idl/EditorAppCore.idl
+++ b/mozilla/xpfe/AppCores/idl/EditorAppCore.idl
@@ -21,6 +21,9 @@ interface EditorAppCore : BaseAppCore
void showClipboard();
void insertText(in wstring textToInsert);
+
+ void insertLink();
+ void insertImage();
void exit();
diff --git a/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h b/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h
index d027204fefb..c90721dcee2 100755
--- a/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h
+++ b/mozilla/xpfe/AppCores/public/nsIDOMEditorAppCore.h
@@ -57,6 +57,10 @@ public:
NS_IMETHOD InsertText(const nsString& aTextToInsert)=0;
+ NS_IMETHOD InsertLink()=0;
+
+ NS_IMETHOD InsertImage()=0;
+
NS_IMETHOD Exit()=0;
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin)=0;
@@ -79,6 +83,8 @@ public:
NS_IMETHOD SelectAll(); \
NS_IMETHOD ShowClipboard(); \
NS_IMETHOD InsertText(const nsString& aTextToInsert); \
+ NS_IMETHOD InsertLink(); \
+ NS_IMETHOD InsertImage(); \
NS_IMETHOD Exit(); \
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \
@@ -98,6 +104,8 @@ public:
NS_IMETHOD SelectAll() { return _to##SelectAll(); } \
NS_IMETHOD ShowClipboard() { return _to##ShowClipboard(); } \
NS_IMETHOD InsertText(const nsString& aTextToInsert) { return _to##InsertText(aTextToInsert); } \
+ NS_IMETHOD InsertLink() { return _to##InsertLink(); } \
+ NS_IMETHOD InsertImage() { return _to##InsertImage(); } \
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/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp b/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp
index b7adbb5b4cc..a07acdf9d8d 100755
--- a/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp
+++ b/mozilla/xpfe/AppCores/src/nsEditorAppCore.cpp
@@ -482,9 +482,9 @@ newWindow(char* urlName) {
nsString controllerCID;
char * urlstr=nsnull;
- char * progname = nsnull;
- char * width=nsnull, *height=nsnull;
- char * iconic_state=nsnull;
+ //char * progname = nsnull;
+ //char * width=nsnull, *height=nsnull;
+ //char * iconic_state=nsnull;
nsIAppShellService* appShell = nsnull;
urlstr = urlName;
@@ -730,6 +730,35 @@ nsEditorAppCore::GetContentsAsHTML(nsString& aContentsAsHTML)
return err;
}
+// Pop up the link dialog once we have dialogs ... for now, hardwire it
+NS_IMETHODIMP
+nsEditorAppCore::InsertLink()
+{
+ if (!mEditor)
+ return NS_ERROR_FAILURE;
+
+ nsString tmpString ("http://www.mozilla.org/editor/");
+ return mEditor->InsertLink(tmpString);
+}
+
+// Pop up the image dialog once we have dialogs ... for now, hardwire it
+NS_IMETHODIMP
+nsEditorAppCore::InsertImage()
+{
+ if (!mEditor)
+ return NS_ERROR_FAILURE;
+
+ nsString url ("http://www.mozilla.org/editor/images/pensplat.gif");
+ nsString width("100");
+ nsString height("138");
+ nsString hspace("0");
+ nsString border("1");
+ nsString alt ("[pen splat]");
+ nsString align ("left");
+ return mEditor->InsertImage(url, width, height, hspace, hspace, border,
+ alt, align);
+}
+
//----------------------------------------
void nsEditorAppCore::SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName)
{
diff --git a/mozilla/xpfe/AppCores/src/nsEditorAppCore.h b/mozilla/xpfe/AppCores/src/nsEditorAppCore.h
index 1e79a931365..f95cd84f835 100755
--- a/mozilla/xpfe/AppCores/src/nsEditorAppCore.h
+++ b/mozilla/xpfe/AppCores/src/nsEditorAppCore.h
@@ -79,6 +79,9 @@ class nsEditorAppCore : public nsBaseAppCore,
NS_IMETHOD ShowClipboard();
NS_IMETHOD InsertText(const nsString& textToInsert);
+
+ NS_IMETHOD InsertLink();
+ NS_IMETHOD InsertImage();
NS_IMETHOD NewWindow();
NS_IMETHOD PrintPreview();
diff --git a/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp b/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp
index 2f31e74b6bf..fbfb407da9b 100755
--- a/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp
+++ b/mozilla/xpfe/AppCores/src/nsJSEditorAppCore.cpp
@@ -464,6 +464,72 @@ EditorAppCoreInsertText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
}
+//
+// Native method InsertLink
+//
+PR_STATIC_CALLBACK(JSBool)
+EditorAppCoreInsertLink(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+ nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
+ JSBool rBool = JS_FALSE;
+
+ *rval = JSVAL_NULL;
+
+ // If there's no private data, this must be the prototype, so ignore
+ if (nsnull == nativeThis) {
+ return JS_TRUE;
+ }
+
+ if (argc >= 0) {
+
+ if (NS_OK != nativeThis->InsertLink()) {
+ return JS_FALSE;
+ }
+
+ *rval = JSVAL_VOID;
+ }
+ else {
+ JS_ReportError(cx, "Function insertLink requires 0 parameters");
+ return JS_FALSE;
+ }
+
+ return JS_TRUE;
+}
+
+
+//
+// Native method InsertImage
+//
+PR_STATIC_CALLBACK(JSBool)
+EditorAppCoreInsertImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+ nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
+ JSBool rBool = JS_FALSE;
+
+ *rval = JSVAL_NULL;
+
+ // If there's no private data, this must be the prototype, so ignore
+ if (nsnull == nativeThis) {
+ return JS_TRUE;
+ }
+
+ if (argc >= 0) {
+
+ if (NS_OK != nativeThis->InsertImage()) {
+ return JS_FALSE;
+ }
+
+ *rval = JSVAL_VOID;
+ }
+ else {
+ JS_ReportError(cx, "Function insertImage requires 0 parameters");
+ return JS_FALSE;
+ }
+
+ return JS_TRUE;
+}
+
+
//
// Native method Exit
//
@@ -666,6 +732,8 @@ static JSFunctionSpec EditorAppCoreMethods[] =
{"selectAll", EditorAppCoreSelectAll, 0},
{"showClipboard", EditorAppCoreShowClipboard, 0},
{"insertText", EditorAppCoreInsertText, 1},
+ {"insertLink", EditorAppCoreInsertLink, 0},
+ {"insertImage", EditorAppCoreInsertImage, 0},
{"exit", EditorAppCoreExit, 0},
{"setToolbarWindow", EditorAppCoreSetToolbarWindow, 1},
{"setContentWindow", EditorAppCoreSetContentWindow, 1},
diff --git a/mozilla/xpfe/AppCores/xul/EditorAppShell.xul b/mozilla/xpfe/AppCores/xul/EditorAppShell.xul
index 5cf72c91c0e..347ac06b90c 100755
--- a/mozilla/xpfe/AppCores/xul/EditorAppShell.xul
+++ b/mozilla/xpfe/AppCores/xul/EditorAppShell.xul
@@ -180,6 +180,28 @@
}
}
+ function EditorInsertLink()
+ {
+ appCore = XPAppCoresManager.Find("EditorAppCore");
+ if (appCore != null) {
+ dump("Inserting link\n");
+ appCore.insertLink();
+ } else {
+ dump("EditorAppCore has not been created!\n");
+ }
+ }
+
+ function EditorInsertImage()
+ {
+ appCore = XPAppCoresManager.Find("EditorAppCore");
+ if (appCore != null) {
+ dump("Inserting image\n");
+ appCore.insertImage();
+ } else {
+ dump("EditorAppCore has not been created!\n");
+ }
+ }
+
function EditorExit()
{
appCore = XPAppCoresManager.Find("EditorAppCore");
@@ -243,9 +265,9 @@