From 57638ea34cf4697cd4a01003b6cba0355d32c13a Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Wed, 10 Mar 1999 22:46:15 +0000 Subject: [PATCH] Implement editor cut/copy/paste --- editor/base/nsEditor.cpp | 61 ++++++++++++++++++- editor/base/nsEditorEventListeners.cpp | 31 ++++++++++ editor/libeditor/base/nsEditor.cpp | 61 ++++++++++++++++++- .../libeditor/text/nsEditorEventListeners.cpp | 31 ++++++++++ widget/src/gtk/nsSelectionMgr.cpp | 2 +- widget/src/mac/nsSelectionMgr.cpp | 2 +- widget/src/windows/nsSelectionMgr.cpp | 2 +- 7 files changed, 181 insertions(+), 9 deletions(-) diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 4ef25a8e338b..f6550133e043 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -40,6 +40,7 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsICaret.h" +#include "nsISelectionMgr.h" #include "nsIContent.h" #include "nsIContentIterator.h" @@ -779,17 +780,71 @@ NS_IMETHODIMP nsEditor::SelectAll() NS_IMETHODIMP nsEditor::Cut() { - return NS_ERROR_NOT_IMPLEMENTED; + printf("nsEditor::Cut\n"); + nsresult res = Copy(); + if (NS_SUCCEEDED(res)) + res = DeleteSelection(eLTR); + return res; } NS_IMETHODIMP nsEditor::Copy() { - return NS_ERROR_NOT_IMPLEMENTED; + printf("nsEditor::Copy\n"); + + // Get the nsSelectionMgr: + // XXX BWEEP BWEEP TEMPORARY! + // The selection mgr needs to be a service. + // See http://bugzilla.mozilla.org/show_bug.cgi?id=3509. + // In the meantime, so I'm not blocked on writing the rest of the code, + // nsSelectionMgr uses the egregious hack of a global variable: +#define EXTERNAL_SELECTION_MGR 1 +#ifdef EXTERNAL_SELECTION_MGR + extern nsISelectionMgr* theSelectionMgr; + nsISelectionMgr* selectionMgr = theSelectionMgr; +#else /* EXTERNAL_SELECTION_MGR */ + nsISelectionMgr* selectionMgr = 0; +#endif /* EXTERNAL_SELECTION_MGR */ + if (!selectionMgr) + { + printf("Can't get selection mgr!\n"); + return NS_ERROR_FAILURE; + } + + //NS_ADD_REF(theSelectionMgr); + return mPresShell->DoCopy(selectionMgr); } NS_IMETHODIMP nsEditor::Paste() { - return NS_ERROR_NOT_IMPLEMENTED; + printf("nsEditor::Paste\n"); + + // Get the nsSelectionMgr: + // XXX BWEEP BWEEP TEMPORARY! + // The selection mgr needs to be a service. + // See http://bugzilla.mozilla.org/show_bug.cgi?id=3509. + // In the meantime, so I'm not blocked on writing the rest of the code, + // nsSelectionMgr uses the egregious hack of a global variable: +#ifdef EXTERNAL_SELECTION_MGR + extern nsISelectionMgr* theSelectionMgr; + nsISelectionMgr* selectionMgr = theSelectionMgr; +#else /* EXTERNAL_SELECTION_MGR */ + nsISelectionMgr* selectionMgr = 0; +#endif /* EXTERNAL_SELECTION_MGR */ + if (!selectionMgr) + { + printf("Can't get selection mgr!\n"); + return NS_ERROR_FAILURE; + } + //NS_ADD_REF(theSelectionMgr); + + nsString stuffToPaste; + // Now we have the selection mgr. Get its contents as text (for now): + selectionMgr->PasteTextBlocking(&stuffToPaste); + + printf("Trying to insert '%s'\n", stuffToPaste.ToNewCString()); + + // Now let InsertText handle the hard stuff: + return InsertText(stuffToPaste); } nsString & nsIEditor::GetTextNodeTag() diff --git a/editor/base/nsEditorEventListeners.cpp b/editor/base/nsEditorEventListeners.cpp index 7391ce13f587..4b9e44932f6d 100644 --- a/editor/base/nsEditorEventListeners.cpp +++ b/editor/base/nsEditorEventListeners.cpp @@ -215,6 +215,37 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr } break; + // XXX: hard-coded cut + case nsIDOMEvent::VK_X: + if (PR_TRUE==ctrlKey) + { + aProcessed=PR_TRUE; + if (mEditor) + mEditor->Cut(); + } + break; + + // XXX: hard-coded copy + case nsIDOMEvent::VK_C: + if (PR_TRUE==ctrlKey) + { + aProcessed=PR_TRUE; + if (mEditor) + mEditor->Copy(); + } + break; + + // XXX: hard-coded paste + case nsIDOMEvent::VK_V: + if (PR_TRUE==ctrlKey) + { + printf("control-v\n"); + aProcessed=PR_TRUE; + if (mEditor) + mEditor->Paste(); + } + break; + // XXX: hard-coded undo case nsIDOMEvent::VK_Z: if (PR_TRUE==ctrlKey) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 4ef25a8e338b..f6550133e043 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -40,6 +40,7 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsICaret.h" +#include "nsISelectionMgr.h" #include "nsIContent.h" #include "nsIContentIterator.h" @@ -779,17 +780,71 @@ NS_IMETHODIMP nsEditor::SelectAll() NS_IMETHODIMP nsEditor::Cut() { - return NS_ERROR_NOT_IMPLEMENTED; + printf("nsEditor::Cut\n"); + nsresult res = Copy(); + if (NS_SUCCEEDED(res)) + res = DeleteSelection(eLTR); + return res; } NS_IMETHODIMP nsEditor::Copy() { - return NS_ERROR_NOT_IMPLEMENTED; + printf("nsEditor::Copy\n"); + + // Get the nsSelectionMgr: + // XXX BWEEP BWEEP TEMPORARY! + // The selection mgr needs to be a service. + // See http://bugzilla.mozilla.org/show_bug.cgi?id=3509. + // In the meantime, so I'm not blocked on writing the rest of the code, + // nsSelectionMgr uses the egregious hack of a global variable: +#define EXTERNAL_SELECTION_MGR 1 +#ifdef EXTERNAL_SELECTION_MGR + extern nsISelectionMgr* theSelectionMgr; + nsISelectionMgr* selectionMgr = theSelectionMgr; +#else /* EXTERNAL_SELECTION_MGR */ + nsISelectionMgr* selectionMgr = 0; +#endif /* EXTERNAL_SELECTION_MGR */ + if (!selectionMgr) + { + printf("Can't get selection mgr!\n"); + return NS_ERROR_FAILURE; + } + + //NS_ADD_REF(theSelectionMgr); + return mPresShell->DoCopy(selectionMgr); } NS_IMETHODIMP nsEditor::Paste() { - return NS_ERROR_NOT_IMPLEMENTED; + printf("nsEditor::Paste\n"); + + // Get the nsSelectionMgr: + // XXX BWEEP BWEEP TEMPORARY! + // The selection mgr needs to be a service. + // See http://bugzilla.mozilla.org/show_bug.cgi?id=3509. + // In the meantime, so I'm not blocked on writing the rest of the code, + // nsSelectionMgr uses the egregious hack of a global variable: +#ifdef EXTERNAL_SELECTION_MGR + extern nsISelectionMgr* theSelectionMgr; + nsISelectionMgr* selectionMgr = theSelectionMgr; +#else /* EXTERNAL_SELECTION_MGR */ + nsISelectionMgr* selectionMgr = 0; +#endif /* EXTERNAL_SELECTION_MGR */ + if (!selectionMgr) + { + printf("Can't get selection mgr!\n"); + return NS_ERROR_FAILURE; + } + //NS_ADD_REF(theSelectionMgr); + + nsString stuffToPaste; + // Now we have the selection mgr. Get its contents as text (for now): + selectionMgr->PasteTextBlocking(&stuffToPaste); + + printf("Trying to insert '%s'\n", stuffToPaste.ToNewCString()); + + // Now let InsertText handle the hard stuff: + return InsertText(stuffToPaste); } nsString & nsIEditor::GetTextNodeTag() diff --git a/editor/libeditor/text/nsEditorEventListeners.cpp b/editor/libeditor/text/nsEditorEventListeners.cpp index 7391ce13f587..4b9e44932f6d 100644 --- a/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/editor/libeditor/text/nsEditorEventListeners.cpp @@ -215,6 +215,37 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr } break; + // XXX: hard-coded cut + case nsIDOMEvent::VK_X: + if (PR_TRUE==ctrlKey) + { + aProcessed=PR_TRUE; + if (mEditor) + mEditor->Cut(); + } + break; + + // XXX: hard-coded copy + case nsIDOMEvent::VK_C: + if (PR_TRUE==ctrlKey) + { + aProcessed=PR_TRUE; + if (mEditor) + mEditor->Copy(); + } + break; + + // XXX: hard-coded paste + case nsIDOMEvent::VK_V: + if (PR_TRUE==ctrlKey) + { + printf("control-v\n"); + aProcessed=PR_TRUE; + if (mEditor) + mEditor->Paste(); + } + break; + // XXX: hard-coded undo case nsIDOMEvent::VK_Z: if (PR_TRUE==ctrlKey) diff --git a/widget/src/gtk/nsSelectionMgr.cpp b/widget/src/gtk/nsSelectionMgr.cpp index 1505c39894bb..107980a38d3c 100644 --- a/widget/src/gtk/nsSelectionMgr.cpp +++ b/widget/src/gtk/nsSelectionMgr.cpp @@ -73,7 +73,7 @@ // XXX BWEEP BWEEP This is ONLY TEMPORARY until the service manager // has a way of registering instances // (see http://bugzilla.mozilla.org/show_bug.cgi?id=3509 ). -static nsISelectionMgr* theSelectionMgr = 0; +nsISelectionMgr* theSelectionMgr = 0; // BWEEP BWEEP // diff --git a/widget/src/mac/nsSelectionMgr.cpp b/widget/src/mac/nsSelectionMgr.cpp index 369d2f6608dd..31ecef570250 100644 --- a/widget/src/mac/nsSelectionMgr.cpp +++ b/widget/src/mac/nsSelectionMgr.cpp @@ -30,7 +30,7 @@ NS_IMPL_RELEASE(nsSelectionMgr) // XXX BWEEP BWEEP This is ONLY TEMPORARY until the service manager // has a way of registering instances // (see http://bugzilla.mozilla.org/show_bug.cgi?id=3509 ). -static nsISelectionMgr* theSelectionMgr = 0; +nsISelectionMgr* theSelectionMgr = 0; // BWEEP BWEEP nsSelectionMgr::nsSelectionMgr() diff --git a/widget/src/windows/nsSelectionMgr.cpp b/widget/src/windows/nsSelectionMgr.cpp index ba1fe40a1637..177bc4416f6d 100644 --- a/widget/src/windows/nsSelectionMgr.cpp +++ b/widget/src/windows/nsSelectionMgr.cpp @@ -25,7 +25,7 @@ // XXX BWEEP BWEEP This is ONLY TEMPORARY until the service manager // has a way of registering instances // (see http://bugzilla.mozilla.org/show_bug.cgi?id=3509 ). -static nsISelectionMgr* theSelectionMgr = 0; +nsISelectionMgr* theSelectionMgr = 0; // BWEEP BWEEP /**