New files for nsHTMLEditor and table editing transactions (not working yet)

git-svn-id: svn://10.0.0.236/trunk@22463 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cmanske%netscape.com
1999-03-01 19:54:47 +00:00
parent 3837aaafce
commit e768f77e73
25 changed files with 4068 additions and 0 deletions

View File

@@ -0,0 +1,175 @@
/* -*- 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://www.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 "DeleteTableCellTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kDeleteTableCellTxnIID, DELETE_CELL_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *DeleteTableCellTxn::gDeleteTableCellTxnName;
nsresult DeleteTableCellTxn::ClassInit()
{
if (nsnull==gDeleteTableCellTxnName)
gDeleteTableCellTxnName = NS_NewAtom("NS_DeleteTableCellTxn");
return NS_OK;
}
DeleteTableCellTxn::DeleteTableCellTxn()
: EditTxn()
{
}
nsresult DeleteTableCellTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult DeleteTableCellTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, 0 /*mOffset+1*/ /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult DeleteTableCellTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
#if 0
nsresult DeleteTableCellTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa DeleteTableCellTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<DeleteTableCellTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next DeleteTableCellTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gDeleteTableCellTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single DeleteTableCellTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<DeleteTableCellTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
return NS_OK;
}
#endif
nsresult DeleteTableCellTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult DeleteTableCellTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult DeleteTableCellTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
DeleteTableCellTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kDeleteTableCellTxnIID)) {
*aInstancePtr = (void*)(DeleteTableCellTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,105 @@
/* -*- 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://www.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 DeleteTableCell_h__
#define DeleteTableCell_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define DELETE_CELL_TXN_IID \
{/*50956DE5-C843-11d2-B1C3-004095E27A10*/ \
0x50956de5, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class DeleteTableCellTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single DeleteTableCellTxn,
* or a DeleteSelection followed by an DeleteTableCellTxn.
*/
static nsIAtom *gDeleteTableCellTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
DeleteTableCellTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle DeleteTableCellTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = DELETE_CELL_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any DeleteTableCellTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(DeleteTableCellTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,175 @@
/* -*- 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://www.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 "DeleteTableColumnTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kDeleteTableColumnTxnIID, DELETE_COLUMN_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *DeleteTableColumnTxn::gDeleteTableColumnTxnName;
nsresult DeleteTableColumnTxn::ClassInit()
{
if (nsnull==gDeleteTableColumnTxnName)
gDeleteTableColumnTxnName = NS_NewAtom("NS_DeleteTableColumnTxn");
return NS_OK;
}
DeleteTableColumnTxn::DeleteTableColumnTxn()
: EditTxn()
{
}
nsresult DeleteTableColumnTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult DeleteTableColumnTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, 0 /*mOffset+1*/ /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult DeleteTableColumnTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
#if 0
nsresult DeleteTableColumnTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa DeleteTableColumnTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<DeleteTableColumnTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next DeleteTableColumnTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gDeleteTableColumnTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single DeleteTableColumnTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<DeleteTableColumnTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
return NS_OK;
}
#endif
nsresult DeleteTableColumnTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult DeleteTableColumnTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult DeleteTableColumnTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
DeleteTableColumnTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kDeleteTableColumnTxnIID)) {
*aInstancePtr = (void*)(DeleteTableColumnTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,106 @@
/* -*- 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://www.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 DeleteTableColumn_h__
#define DeleteTableColumn_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define DELETE_COLUMN_TXN_IID \
{/*50956DE4-C843-11d2-B1C3-004095E27A10*/ \
0x50956de4, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class DeleteTableColumnTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single DeleteTableColumnTxn,
* or a DeleteSelection followed by an DeleteTableColumnTxn.
*/
static nsIAtom *gDeleteTableColumnTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
DeleteTableColumnTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle DeleteTableColumnTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = DELETE_COLUMN_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any DeleteTableColumnTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(DeleteTableColumnTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
/** the element to insert into mElement */
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,175 @@
/* -*- 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://www.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 "DeleteTableRowTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kDeleteTableRowTxnIID, DELETE_ROW_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *DeleteTableRowTxn::gDeleteTableRowTxnName;
nsresult DeleteTableRowTxn::ClassInit()
{
if (nsnull==gDeleteTableRowTxnName)
gDeleteTableRowTxnName = NS_NewAtom("NS_DeleteTableRowTxn");
return NS_OK;
}
DeleteTableRowTxn::DeleteTableRowTxn()
: EditTxn()
{
}
nsresult DeleteTableRowTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult DeleteTableRowTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, 0 /*mOffset+1*/ /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult DeleteTableRowTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
#if 0
nsresult DeleteTableRowTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa DeleteTableRowTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<DeleteTableRowTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next DeleteTableRowTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gDeleteTableRowTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single DeleteTableRowTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<DeleteTableRowTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
return NS_OK;
}
#endif
nsresult DeleteTableRowTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult DeleteTableRowTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult DeleteTableRowTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
DeleteTableRowTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kDeleteTableRowTxnIID)) {
*aInstancePtr = (void*)(DeleteTableRowTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,110 @@
/* -*- 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://www.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 DeleteTableRow_h__
#define DeleteTableRow_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define DELETE_ROW_TXN_IID \
{/*50956DE3-C843-11d2-B1C3-004095E27A10*/ \
0x50956de3, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class DeleteTableRowTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single DeleteTableRowTxn,
* or a DeleteSelection followed by an DeleteTableRowTxn.
*/
static nsIAtom *gDeleteTableRowTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
DeleteTableRowTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle DeleteTableRowTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = DELETE_ROW_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any DeleteTableRowTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(DeleteTableRowTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
/** the offset into mElement where the insertion is to take place */
PRUint32 mOffset;
/** the element to insert into mElement at mOffset */
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,123 @@
/* -*- 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://www.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 "DeleteTableTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kDeleteTableTxnIID, DELETE_TABLE_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *DeleteTableTxn::gDeleteTableTxnName;
nsresult DeleteTableTxn::ClassInit()
{
if (nsnull==gDeleteTableTxnName)
gDeleteTableTxnName = NS_NewAtom("NS_DeleteTableTxn");
return NS_OK;
}
DeleteTableTxn::DeleteTableTxn()
: EditTxn()
{
}
nsresult DeleteTableTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult DeleteTableTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, 0 /*mOffset+1*/ /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult DeleteTableTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
nsresult DeleteTableTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult DeleteTableTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult DeleteTableTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
DeleteTableTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kDeleteTableTxnIID)) {
*aInstancePtr = (void*)(DeleteTableTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,105 @@
/* -*- 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://www.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 DeleteTable_h__
#define DeleteTable_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define DELETE_TABLE_TXN_IID \
{/*50956DE7-C843-11d2-B1C3-004095E27A10*/ \
0x50956de7, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class DeleteTableTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single DeleteTableTxn,
* or a DeleteSelection followed by an DeleteTableTxn.
*/
static nsIAtom *gDeleteTableTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
DeleteTableTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle DeleteTableTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = DELETE_TABLE_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any DeleteTableTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(DeleteTableTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,351 @@
/* -*- 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://www.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 "nsIDOMDocument.h"
#include "nsEditor.h"
#include "nsIDOMText.h"
#include "nsIDOMElement.h"
#include "nsIDOMAttr.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMRange.h"
#include "nsIDOMSelection.h"
#include "nsIAtom.h"
/*
#include "nsIDocument.h"
#include "nsIServiceManager.h"
#include "nsEditFactory.h"
#include "nsTextEditFactory.h"
#include "nsEditorCID.h"
#include "nsTransactionManagerCID.h"
#include "nsITransactionManager.h"
#include "nsIPresShell.h"
#include "nsIViewManager.h"
#include "nsICollection.h"
#include "nsIEnumerator.h"
#include "nsVoidArray.h"
#include "nsICaret.h"
*/
#include "nsITableCellLayout.h" // for temp method GetColIndexForCell, to be removed
// transactions the editor knows how to build
#include "TransactionFactory.h"
#include "EditAggregateTxn.h"
#include "InsertTableTxn.h"
#include "InsertTableCellTxn.h"
#include "InsertTableColumnTxn.h"
#include "InsertTableRowTxn.h"
#include "DeleteTableTxn.h"
#include "DeleteTableCellTxn.h"
#include "DeleteTableColumnTxn.h"
#include "DeleteTableRowTxn.h"
#include "JoinTableCellsTxn.h"
// Include after above so Transaction types are defined first
#include "nsHTMLEditor.h"
static NS_DEFINE_IID(kITransactionManagerIID, NS_ITRANSACTIONMANAGER_IID);
static NS_DEFINE_IID(kEditAggregateTxnIID, EDIT_AGGREGATE_TXN_IID);
static NS_DEFINE_IID(kInsertTableTxnIID, INSERT_TABLE_TXN_IID);
static NS_DEFINE_IID(kInsertTableCellTxnIID, INSERT_CELL_TXN_IID);
static NS_DEFINE_IID(kInsertTableColumnTxnIID, INSERT_COLUMN_TXN_IID);
static NS_DEFINE_IID(kInsertTableRowTxnIID, INSERT_ROW_TXN_IID);
static NS_DEFINE_IID(kDeleteTableTxnIID, DELETE_TABLE_TXN_IID);
static NS_DEFINE_IID(kDeleteTableCellTxnIID, DELETE_CELL_TXN_IID);
static NS_DEFINE_IID(kDeleteTableColumnTxnIID, DELETE_COLUMN_TXN_IID);
static NS_DEFINE_IID(kDeleteTableRowTxnIID, DELETE_ROW_TXN_IID);
static NS_DEFINE_IID(kJoinTableCellsTxnIID, JOIN_CELLS_TXN_IID);
// Table Editing methods -- for testing, hooked up to Tool Menu items
// Modeled after nsEditor::InsertText()
nsresult nsHTMLEditor::InsertTable()
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
#if 0
if (mEditor)
{
// Note: Code that does most of the deletion work was
// moved to nsEditor::DeleteSelectionAndCreateNode
// Only difference is we now do BeginTransaction()/EndTransaction()
// even if we fail to get a selection
result = mEditor->BeginTransaction();
nsCOMPtr<nsIDOMNode> newNode;
nsAutoString tag("td");
result = mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
if( NS_SUCCEEDED(result))
{
nsAutoString tag("tr");
nsCOMPtr<nsIDOMNode> ParentNode;
ParentNode = newNode;
result = mEditor->CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode));
if( NS_SUCCEEDED(result))
{
ParentNode = newNode;
nsAutoString tag("td");
ParentNode = newNode;
result = mEditor->CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode));
}
}
result = mEditor->EndTransaction();
}
#endif
return result;
#if 0
EditAggregateTxn *aggTxn;
result = mEditor->CreateAggregateTxnForDeleteSelection(InsertTableTxn::gInsertTableTxnName, (nsISupports**)&aggTxn);
if ((NS_FAILED(result)) || (nsnull==aggTxn)) {
return NS_ERROR_OUT_OF_MEMORY;
}
// CREATE A NEW TABLE HERE -- INCLUDE 1 ROW, CELL, AND DEFAULT PARAGRAPH WITH 1 SPACE
nsIDOMElement *aTableNode = nsnull;
InsertTableTxn *txn;
result = CreateTxnForInsertTable(aTableNode, &txn);
if ((NS_SUCCEEDED(result)) && txn) {
aggTxn->AppendChild(txn);
result = mEditor->Do(aggTxn);
}
}
return result;
#endif
}
nsresult nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn)
{
if (mEditor==nsnull)
{
return NS_ERROR_NOT_INITIALIZED;
}
if( aTableNode == nsnull || aTxn == nsnull )
{
return NS_ERROR_NULL_POINTER;
}
// DELETE THIS AFTER IMPLEMENTING METHOD
nsresult result = NS_ERROR_NOT_IMPLEMENTED;
#if 0
nsresult result = NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
{
nsCOMPtr<nsIEnumerator> enumerator;
enumerator = selection;
if (enumerator)
{
enumerator->First();
nsISupports *currentItem;
result = enumerator->CurrentItem(&currentItem);
if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
{
result = NS_ERROR_UNEXPECTED;
// XXX: we'll want to deleteRange if the selection isn't just an insertion point
// for now, just insert text after the start of the first node
nsCOMPtr<nsIDOMRange> range(currentItem);
if (range)
{
nsCOMPtr<nsIDOMNode> node;
result = range->GetStartParent(getter_AddRefs(node));
if ((NS_SUCCEEDED(result)) && (node))
{
result = NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDOMCharacterData> nodeAsText(node);
if (nodeAsText)
{
PRInt32 offset;
range->GetStartOffset(&offset);
result = TransactionFactory::GetNewTransaction(kInsertTableTxnIID, (EditTxn **)aTxn);
if (nsnull!=*aTxn) {
result = (*aTxn)->Init(nodeAsText, offset, aTableNode, mPresShell);
}
else
result = NS_ERROR_OUT_OF_MEMORY;
}
}
}
}
}
}
#endif
return result;
}
nsresult nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::DeleteTable()
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::DeleteTableCell(PRInt32 aNumber)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::DeleteTableRow(PRInt32 aNumber)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::JoinTableCells(PRBool aCellToRight)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
aCellIndex=0; // initialize out param
result = NS_ERROR_FAILURE; // we return an error unless we get the index
nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr
result = mEditor->GetLayoutObject(aCellNode, &layoutObject);
if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject))
{ // get the table cell interface from the frame
nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted
result = layoutObject->QueryInterface(nsITableCellLayout::IID(), (void**)(&cellLayoutObject));
if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject))
{ // get the index
result = cellLayoutObject->GetColIndex(aCellIndex);
}
}
}
return result;
}
nsresult nsHTMLEditor::GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}
nsresult nsHTMLEditor::GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = NS_ERROR_NOT_IMPLEMENTED;
}
return result;
}

View File

@@ -0,0 +1,177 @@
/* -*- 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://www.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 "InsertTableCellTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kInsertTableCellTxnIID, INSERT_CELL_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *InsertTableCellTxn::gInsertTableCellTxnName;
nsresult InsertTableCellTxn::ClassInit()
{
if (nsnull==gInsertTableCellTxnName)
gInsertTableCellTxnName = NS_NewAtom("NS_InsertTableCellTxn");
return NS_OK;
}
InsertTableCellTxn::InsertTableCellTxn()
: EditTxn()
{
}
nsresult InsertTableCellTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mOffset = aOffset;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult InsertTableCellTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, mOffset+1 /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult InsertTableCellTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
#if 0
nsresult InsertTableCellTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa InsertTableCellTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<InsertTableCellTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next InsertTableCellTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gInsertTableCellTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single InsertTableCellTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<InsertTableCellTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
return NS_OK;
}
#endif
nsresult InsertTableCellTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult InsertTableCellTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult InsertTableCellTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
InsertTableCellTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kInsertTableCellTxnIID)) {
*aInstancePtr = (void*)(InsertTableCellTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,111 @@
/* -*- 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://www.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 InsertTableCell_h__
#define InsertTableCell_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define INSERT_CELL_TXN_IID \
{/* 12D65E50-C6CA-11d2-9839-00805F8AA8B8*/ \
0x12d65e50, 0xc6ca, 0x11d2, \
{ 0x98, 0x39, 0x0, 0x80, 0x5f, 0x8a, 0xa8, 0xb8} }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class InsertTableCellTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single InsertTableCellTxn,
* or a DeleteSelection followed by an InsertTableCellTxn.
*/
static nsIAtom *gInsertTableCellTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
InsertTableCellTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle InsertTableCellTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = INSERT_CELL_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any InsertTableCellTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(InsertTableCellTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
/** the offset into mElement where the insertion is to take place */
PRUint32 mOffset;
/** the element to insert into mElement at mOffset */
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,177 @@
/* -*- 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://www.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 "InsertTableColumnTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kInsertTableColumnTxnIID, INSERT_COLUMN_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *InsertTableColumnTxn::gInsertTableColumnTxnName;
nsresult InsertTableColumnTxn::ClassInit()
{
if (nsnull==gInsertTableColumnTxnName)
gInsertTableColumnTxnName = NS_NewAtom("NS_InsertTableColumnTxn");
return NS_OK;
}
InsertTableColumnTxn::InsertTableColumnTxn()
: EditTxn()
{
}
nsresult InsertTableColumnTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mOffset = aOffset;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult InsertTableColumnTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, mOffset+1 /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult InsertTableColumnTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
#if 0
nsresult InsertTableColumnTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa InsertTableColumnTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<InsertTableColumnTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next InsertTableColumnTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gInsertTableColumnTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single InsertTableColumnTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<InsertTableColumnTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
return NS_OK;
}
#endif
nsresult InsertTableColumnTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult InsertTableColumnTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult InsertTableColumnTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
InsertTableColumnTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kInsertTableColumnTxnIID)) {
*aInstancePtr = (void*)(InsertTableColumnTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,112 @@
/* -*- 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://www.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 InsertTableColumn_h__
#define InsertTableColumn_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define INSERT_COLUMN_TXN_IID \
{/* 50956DE1-C843-11d2-B1C3-004095E27A10*/ \
0x50956de1, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class InsertTableColumnTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single InsertTableColumnTxn,
* or a DeleteSelection followed by an InsertTableColumnTxn.
*/
static nsIAtom *gInsertTableColumnTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
InsertTableColumnTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle InsertTableColumnTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = INSERT_COLUMN_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any InsertTableColumnTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(InsertTableColumnTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
/** the offset into mElement where the insertion is to take place */
PRUint32 mOffset;
/** the element to insert into mElement at mOffset */
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,177 @@
/* -*- 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://www.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 "InsertTableRowTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kInsertTableRowTxnIID, INSERT_ROW_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *InsertTableRowTxn::gInsertTableRowTxnName;
nsresult InsertTableRowTxn::ClassInit()
{
if (nsnull==gInsertTableRowTxnName)
gInsertTableRowTxnName = NS_NewAtom("NS_InsertTableRowTxn");
return NS_OK;
}
InsertTableRowTxn::InsertTableRowTxn()
: EditTxn()
{
}
nsresult InsertTableRowTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mOffset = aOffset;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult InsertTableRowTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, mOffset+1 /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult InsertTableRowTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
#if 0
nsresult InsertTableRowTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa InsertTableRowTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<InsertTableRowTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next InsertTableRowTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gInsertTableRowTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single InsertTableRowTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<InsertTableRowTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
return NS_OK;
}
#endif
nsresult InsertTableRowTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult InsertTableRowTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult InsertTableRowTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
InsertTableRowTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kInsertTableRowTxnIID)) {
*aInstancePtr = (void*)(InsertTableRowTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,112 @@
/* -*- 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://www.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 InsertTableRow_h__
#define InsertTableRow_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define INSERT_ROW_TXN_IID \
{/*50956DE2-C843-11d2-B1C3-004095E27A10*/ \
0x50956de2, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class InsertTableRowTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single InsertTableRowTxn,
* or a DeleteSelection followed by an InsertTableRowTxn.
*/
static nsIAtom *gInsertTableRowTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
InsertTableRowTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle InsertTableRowTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = INSERT_ROW_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any InsertTableRowTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(InsertTableRowTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
/** the offset into mElement where the insertion is to take place */
PRUint32 mOffset;
/** the element to insert into mElement at mOffset */
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,177 @@
/* -*- 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://www.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 "InsertTableTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kInsertTableTxnIID, INSERT_TABLE_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *InsertTableTxn::gInsertTableTxnName;
nsresult InsertTableTxn::ClassInit()
{
if (nsnull==gInsertTableTxnName)
gInsertTableTxnName = NS_NewAtom("NS_InsertTableTxn");
return NS_OK;
}
InsertTableTxn::InsertTableTxn()
: EditTxn()
{
}
nsresult InsertTableTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mOffset = aOffset;
mTableToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult InsertTableTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, mOffset+1 /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult InsertTableTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
nsresult InsertTableTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
{
#if 0
// set out param default value
if (nsnull!=aDidMerge)
*aDidMerge=PR_FALSE;
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
{
// if aTransaction isa InsertTableTxn, and if the selection hasn't changed,
// then absorb it
nsCOMPtr<InsertTableTxn> otherTxn(aTransaction);
if (otherTxn)
{
if (PR_TRUE==IsSequentialInsert(otherTxn))
{
nsAutoString otherData;
otherTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
else
{ // the next InsertTableTxn might be inside an aggregate that we have special knowledge of
nsCOMPtr<EditAggregateTxn> otherTxn(aTransaction);
if (otherTxn)
{
nsCOMPtr<nsIAtom> txnName;
otherTxn->GetName(getter_AddRefs(txnName));
if (txnName==gInsertTableTxnName)
{ // yep, it's one of ours. By definition, it must contain only
// a single InsertTableTxn
nsCOMPtr<EditTxn> childTxn;
otherTxn->GetTxnAt(0, getter_AddRefs(childTxn));
nsCOMPtr<InsertTableTxn> otherInsertTxn(childTxn);
if (otherInsertTxn)
{
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
{
nsAutoString otherData;
otherInsertTxn->GetData(otherData);
mStringToInsert += otherData;
*aDidMerge = PR_TRUE;
}
}
}
}
}
}
#endif
return NS_OK;
}
nsresult InsertTableTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult InsertTableTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult InsertTableTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
InsertTableTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kInsertTableTxnIID)) {
*aInstancePtr = (void*)(InsertTableTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,111 @@
/* -*- 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://www.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 InsertTable_h__
#define InsertTable_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define INSERT_TABLE_TXN_IID \
{/*12D65E51-C6CA-11d2-9839-00805F8AA8B8*/ \
0x12d65e51, 0xc6ca, 0x11d2, \
{ 0x98, 0x39, 0x0, 0x80, 0x5f, 0x8a, 0xa8, 0xb8 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class InsertTableTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single InsertTableTxn,
* or a DeleteSelection followed by an InsertTableTxn.
*/
static nsIAtom *gInsertTableTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aOffset the location in aElement to do the insertion
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
InsertTableTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle InsertTableTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = INSERT_TABLE_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any InsertTableTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(InsertTableTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
/** the offset into mElement where the insertion is to take place */
PRUint32 mOffset;
/** the Table to insert into mElement at mOffset */
nsIDOMNode *mTableToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,123 @@
/* -*- 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://www.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 "JoinTableCellsTxn.h"
#include "nsEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMSelection.h"
#include "nsIPresShell.h"
#include "EditAggregateTxn.h"
static NS_DEFINE_IID(kJoinTableCellsTxnIID, JOIN_CELLS_TXN_IID);
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
nsIAtom *JoinTableCellsTxn::gJoinTableCellsTxnName;
nsresult JoinTableCellsTxn::ClassInit()
{
if (nsnull==gJoinTableCellsTxnName)
gJoinTableCellsTxnName = NS_NewAtom("NS_JoinTableCellsTxn");
return NS_OK;
}
JoinTableCellsTxn::JoinTableCellsTxn()
: EditTxn()
{
}
nsresult JoinTableCellsTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)
{
mElement = aElement;
mNodeToInsert = aNode;
mPresShell = aPresShell;
return NS_OK;
}
nsresult JoinTableCellsTxn::Do(void)
{
//nsresult res = mElement->InsertData(mOffset, mStringToInsert);
// advance caret: This requires the presentation shell to get the selection.
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMSelection> selection;
res = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res)) {
res = selection->Collapse(mElement, 0 /*mOffset+1*/ /*+mStringToInsert.Length()*/);
}
return res;
}
nsresult JoinTableCellsTxn::Undo(void)
{
nsresult result = NS_ERROR_FAILURE;
#if 0
PRUint32 length = mStringToInsert.Length();
result = mElement->DeleteData(mOffset, length);
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsIDOMSelection> selection;
result = mPresShell->GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(result)) {
result = selection->Collapse(mElement, mOffset);
}
}
#endif
return result;
}
nsresult JoinTableCellsTxn::Write(nsIOutputStream *aOutputStream)
{
return NS_OK;
}
nsresult JoinTableCellsTxn::GetUndoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Remove Table";
}
return NS_OK;
}
nsresult JoinTableCellsTxn::GetRedoString(nsString **aString)
{
if (nsnull!=aString)
{
**aString="Insert Table";
}
return NS_OK;
}
/* ============= nsISupports implementation ====================== */
nsresult
JoinTableCellsTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kJoinTableCellsTxnIID)) {
*aInstancePtr = (void*)(JoinTableCellsTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

View File

@@ -0,0 +1,104 @@
/* -*- 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://www.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 JoinTableCells_h__
#define JoinTableCells_h__
#include "EditTxn.h"
#include "nsIEditor.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#define JOIN_CELLS_TXN_IID \
{/*50956DE6-C843-11d2-B1C3-004095E27A10*/ \
0x50956de6, 0xc843, 0x11d2, \
{ 0xb1, 0xc3, 0x0, 0x40, 0x95, 0xe2, 0x7a, 0x10 } }
class nsIPresShell;
/**
* A transaction that inserts Table into a content node.
*/
class JoinTableCellsTxn : public EditTxn
{
public:
/** used to name aggregate transactions that consist only of a single JoinTableCellsTxn,
* or a DeleteSelection followed by an JoinTableCellsTxn.
*/
static nsIAtom *gJoinTableCellsTxnName;
/** initialize the transaction
* @param aElement the current content node
* @param aNode the new Table to insert
* @param aPresShell used to get and set the selection
*/
virtual nsresult Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell);
private:
JoinTableCellsTxn();
public:
virtual nsresult Do(void);
virtual nsresult Undo(void);
//virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
virtual nsresult Write(nsIOutputStream *aOutputStream);
virtual nsresult GetUndoString(nsString **aString);
virtual nsresult GetRedoString(nsString **aString);
// nsISupports declarations
// override QueryInterface to handle JoinTableCellsTxn request
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
static const nsIID& IID() { static nsIID iid = JOIN_CELLS_TXN_IID; return iid; }
/** return the string data associated with this transaction */
// virtual nsresult GetData(nsString& aResult);
/** must be called before any JoinTableCellsTxn is instantiated */
static nsresult ClassInit();
protected:
// /* return PR_TRUE if aOtherTxn immediately follows this txn */
// virtual PRBool IsSequentialInsert(JoinTableCellsTxn *aOtherTxn);
/** the element to operate upon */
nsCOMPtr<nsIDOMCharacterData> mElement;
nsIDOMNode *mNodeToInsert;
/** the presentation shell, which we'll need to get the selection */
nsIPresShell* mPresShell;
friend class TransactionFactory;
};
#endif

View File

@@ -0,0 +1,128 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsHTMLEditFactory.h"
#include "nsIHTMLEditor.h"
#include "nsHTMLEditor.h"
#include "nsEditor.h"
#include "nsEditorCID.h"
#include "nsRepository.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIHTMLEditorIID, NS_IHTMLEDITOR_IID);
static NS_DEFINE_IID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
static NS_DEFINE_IID(kIHTMLEditFactoryIID, NS_IHTMLEDITORFACTORY_IID);
nsresult
GetHTMLEditFactory(nsIFactory **aFactory, const nsCID & aClass)
{
static nsCOMPtr<nsIFactory> g_pNSIFactory;
PR_EnterMonitor(getEditorMonitor());
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsHTMLEditFactory *factory = new nsHTMLEditFactory(aClass);
g_pNSIFactory = do_QueryInterface(factory);
if (factory)
result = NS_OK;
}
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
PR_ExitMonitor(getEditorMonitor());
return result;
}
////////////////////////////////////////////////////////////////////////////
// from nsISupports
NS_METHOD
nsHTMLEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (nsnull == 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(nsHTMLEditFactory)
NS_IMPL_RELEASE(nsHTMLEditFactory)
////////////////////////////////////////////////////////////////////////////
// from nsIFactory:
NS_METHOD
nsHTMLEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
*aResult = nsnull;
nsISupports *obj = nsnull;
if (!aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
if (mCID.Equals(kHTMLEditorCID))
obj = (nsISupports *)new nsHTMLEditor();
//more class ids to support. here
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
{
delete obj;
return NS_NOINTERFACE;
}
return NS_OK;
}
NS_METHOD
nsHTMLEditFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////
nsHTMLEditFactory::nsHTMLEditFactory(const nsCID &aClass)
:mCID(aClass)
{
NS_INIT_REFCNT();
}
nsHTMLEditFactory::~nsHTMLEditFactory()
{
//nsRepository::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway
}

View File

@@ -0,0 +1,66 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsHTMLEditFactory_h___
#define nsHTMLEditFactory_h___
#include "nsISupports.h"
#include "nsIFactory.h"
/*
Factory that can make a text editor
*/
/**
* This supplies the neccessary entrance to the edit module. it will return any
* instantiations that we need.
*/
class nsHTMLEditFactory;
extern nsresult GetHTMLEditFactory(nsIFactory **aFactory, const nsCID & aClass);
class nsHTMLEditFactory : 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);
////////////////////////////////////////////////////////////////////////////
virtual ~nsHTMLEditFactory(void);
private:
nsHTMLEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface
/** GetHTMLEditFactory
* creates an edit factory other CSID supported friend functions here.
*/
friend nsresult GetHTMLEditFactory(nsIFactory **, const nsCID & );
const nsCID &mCID;
};
#endif //nsIEditFactory_h___

View File

@@ -0,0 +1,416 @@
/* -*- 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://www.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 "nsTextEditor.h"
#include "nsHTMLEditor.h"
#include "nsEditorEventListeners.h"
#include "nsIDOMDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsEditorCID.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
#include "nsITableCellLayout.h" //For GetColIndexForCell
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_CID(kEditorCID, NS_EDITOR_CID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITextEditorIID, NS_ITEXTEDITOR_IID);
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
static NS_DEFINE_IID(kIHTMLEditorIID, NS_IHTMLEDITOR_IID);
static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
nsHTMLEditor::nsHTMLEditor()
{
NS_INIT_REFCNT();
}
nsHTMLEditor::~nsHTMLEditor()
{
//the autopointers will clear themselves up.
#if 0
// NO EVENT LISTERNERS YET
//but we need to also remove the listeners or we have a leak
//(This is identical to nsTextEditor code
if (mEditor)
{
nsCOMPtr<nsIDOMDocument> doc;
mEditor->GetDocument(getter_AddRefs(doc));
if (doc)
{
nsCOMPtr<nsIDOMEventReceiver> erP;
nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
if (NS_SUCCEEDED(result) && erP)
{
if (mKeyListenerP) {
erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID);
}
if (mMouseListenerP) {
erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID);
}
}
else
NS_NOTREACHED("~nsHTMLEditor");
}
}
#endif
}
nsresult nsHTMLEditor::InitHTMLEditor(nsIDOMDocument *aDoc,
nsIPresShell *aPresShell,
nsIEditorCallback *aCallback)
{
NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg");
nsresult result=NS_ERROR_NULL_POINTER;
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
{
nsITextEditor *aTextEditor = nsnull;
result = nsRepository::CreateInstance(kTextEditorCID, nsnull,
kITextEditorIID, (void **)&aTextEditor);
if (NS_FAILED(result) || !aTextEditor) {
return NS_ERROR_OUT_OF_MEMORY;
}
mTextEditor = aTextEditor; // CreateInstance did our addRef
// Initialize nsTextEditor -- this will create and initialize the base nsEditor
// Note: nsTextEditor adds its own key, mouse, and DOM listners -- is that OK?
result = mTextEditor->InitTextEditor(aDoc, aPresShell);
if (NS_OK != result) {
return result;
}
mTextEditor->EnableUndo(PR_TRUE);
// Get the pointer to the base editor for easier access
result = mTextEditor->QueryInterface(kIEditorIID, getter_AddRefs(mEditor));
if (NS_OK != result) {
return result;
}
result = NS_OK;
}
return result;
}
nsresult nsHTMLEditor::SetTextProperties(nsISupportsArray *aPropList)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->SetTextProperties(aPropList);
}
return result;
}
nsresult nsHTMLEditor::GetTextProperties(nsISupportsArray *aPropList)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->GetTextProperties(aPropList);
}
return result;
}
nsresult nsHTMLEditor::RemoveTextProperties(nsISupportsArray *aPropList)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->RemoveTextProperties(aPropList);
}
return result;
}
nsresult nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->DeleteSelection(aDir);
}
return result;
}
nsresult nsHTMLEditor::InsertText(const nsString& aStringToInsert)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->InsertText(aStringToInsert);
}
return result;
}
nsresult nsHTMLEditor::InsertBreak(PRBool aCtrlKey)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->InsertBreak(aCtrlKey);
}
return result;
}
// Methods shared with the base editor.
// Note: We could call each of these via nsTextEditor -- is that better?
nsresult nsHTMLEditor::EnableUndo(PRBool aEnable)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->EnableUndo(aEnable);
}
return result;
}
nsresult nsHTMLEditor::Undo(PRUint32 aCount)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->Undo(aCount);
}
return result;
}
nsresult nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->CanUndo(aIsEnabled, aCanUndo);
}
return result;
}
nsresult nsHTMLEditor::Redo(PRUint32 aCount)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->Redo(aCount);
}
return result;
}
nsresult nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->CanRedo(aIsEnabled, aCanRedo);
}
return result;
}
nsresult nsHTMLEditor::BeginTransaction()
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->BeginTransaction();
}
return result;
}
nsresult nsHTMLEditor::EndTransaction()
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->EndTransaction();
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionUp(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionDown(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionNext(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionPrevious(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->SelectNext(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->SelectPrevious(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->ScrollUp(aIncrement);
}
return result;
}
nsresult nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->ScrollDown(aIncrement);
}
return result;
}
nsresult nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->ScrollIntoView(aScrollToBegin);
}
return result;
}
nsresult nsHTMLEditor::Insert(nsIInputStream *aInputStream)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->Insert(aInputStream);
}
return result;
}
nsresult nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->OutputText(aOutputStream);
}
return result;
}
nsresult nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->OutputHTML(aOutputStream);
}
return result;
}
NS_IMPL_ADDREF(nsHTMLEditor)
NS_IMPL_RELEASE(nsHTMLEditor)
nsresult
nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIHTMLEditorIID)) {
*aInstancePtr = (void*)(nsIHTMLEditor*)this;
NS_ADDREF_THIS();
return NS_OK;
}
// If our pointer to nsTextEditor is null, don't bother querying?
if (aIID.Equals(kITextEditorIID) && (mTextEditor)) {
nsCOMPtr<nsIEditor> editor;
nsresult result = mTextEditor->QueryInterface(kITextEditorIID, getter_AddRefs(editor));
if (NS_SUCCEEDED(result) && editor) {
*aInstancePtr = (void*)editor;
return NS_OK;
}
}
if (aIID.Equals(kIEditorIID) && (mEditor)) {
nsCOMPtr<nsIEditor> editor;
nsresult result = mEditor->QueryInterface(kIEditorIID, getter_AddRefs(editor));
if (NS_SUCCEEDED(result) && editor) {
*aInstancePtr = (void*)editor;
return NS_OK;
}
}
return NS_NOINTERFACE;
}
//================================================================
// HTML Editor methods
//
// Note: Table Editing methods are implemented in EditTable.cpp
//

View File

@@ -0,0 +1,118 @@
/* -*- 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://www.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 nsHTMLEditor_h__
#define nsHTMLEditor_h__
#include "nsITextEditor.h"
#include "nsIHTMLEditor.h"
#include "nsCOMPtr.h"
#include "nsIDOMEventListener.h"
#include "InsertTableTxn.h"
/**
* The HTML editor implementation.<br>
* Use to edit HTML document represented as a DOM tree.
*/
class nsHTMLEditor : public nsIHTMLEditor
{
public:
// see nsIHTMLEditor for documentation
//Interfaces for addref and release and queryinterface
NS_DECL_ISUPPORTS
//Initialization
nsHTMLEditor();
virtual nsresult InitHTMLEditor(nsIDOMDocument *aDoc,
nsIPresShell *aPresShell,
nsIEditorCallback *aCallback=nsnull);
virtual ~nsHTMLEditor();
//============================================================================
// Methods that are duplicates of nsTextEditor -- exposed here for convenience
// Editing Operations
virtual nsresult SetTextProperties(nsISupportsArray *aPropList);
virtual nsresult GetTextProperties(nsISupportsArray *aPropList);
virtual nsresult RemoveTextProperties(nsISupportsArray *aPropList);
virtual nsresult DeleteSelection(nsIEditor::Direction aDir);
virtual nsresult InsertText(const nsString& aStringToInsert);
virtual nsresult InsertBreak(PRBool aCtrlKey);
// Transaction control
virtual nsresult EnableUndo(PRBool aEnable);
virtual nsresult Undo(PRUint32 aCount);
virtual nsresult CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
virtual nsresult Redo(PRUint32 aCount);
virtual nsresult CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
virtual nsresult BeginTransaction();
virtual nsresult EndTransaction();
// Selection and navigation -- exposed here for convenience
virtual nsresult MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult ScrollUp(nsIAtom *aIncrement);
virtual nsresult ScrollDown(nsIAtom *aIncrement);
virtual nsresult ScrollIntoView(PRBool aScrollToBegin);
// Input/Output
virtual nsresult Insert(nsIInputStream *aInputStream);
virtual nsresult OutputText(nsIOutputStream *aOutputStream);
virtual nsresult OutputHTML(nsIOutputStream *aOutputStream);
//=====================================
// HTML Editing methods
// Table Editing (implemented in EditTable.cpp)
virtual nsresult CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn);
virtual nsresult GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex);
virtual nsresult GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex);
virtual nsresult GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode);
virtual nsresult GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode);
virtual nsresult GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode);
virtual nsresult GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode);
virtual nsresult InsertTable();
virtual nsresult InsertTableCell(PRInt32 aNumber, PRBool aAfter);
virtual nsresult InsertTableColumn(PRInt32 aNumber, PRBool aAfter);
virtual nsresult InsertTableRow(PRInt32 aNumber, PRBool aAfter);
virtual nsresult DeleteTable();
virtual nsresult DeleteTableCell(PRInt32 aNumber);
virtual nsresult DeleteTableColumn(PRInt32 aNumber);
virtual nsresult DeleteTableRow(PRInt32 aNumber);
virtual nsresult JoinTableCells(PRBool aCellToRight);
// Data members
protected:
nsCOMPtr<nsIEditor> mEditor;
nsCOMPtr<nsITextEditor> mTextEditor;
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
// For now, the listners are tied to the nsTextEditor class
//
// nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
// nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
};
#endif //nsHTMLEditor_h__

View File

@@ -0,0 +1,416 @@
/* -*- 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://www.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 "nsTextEditor.h"
#include "nsHTMLEditor.h"
#include "nsEditorEventListeners.h"
#include "nsIDOMDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsEditorCID.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
#include "nsITableCellLayout.h" //For GetColIndexForCell
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_CID(kEditorCID, NS_EDITOR_CID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITextEditorIID, NS_ITEXTEDITOR_IID);
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
static NS_DEFINE_IID(kIHTMLEditorIID, NS_IHTMLEDITOR_IID);
static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
nsHTMLEditor::nsHTMLEditor()
{
NS_INIT_REFCNT();
}
nsHTMLEditor::~nsHTMLEditor()
{
//the autopointers will clear themselves up.
#if 0
// NO EVENT LISTERNERS YET
//but we need to also remove the listeners or we have a leak
//(This is identical to nsTextEditor code
if (mEditor)
{
nsCOMPtr<nsIDOMDocument> doc;
mEditor->GetDocument(getter_AddRefs(doc));
if (doc)
{
nsCOMPtr<nsIDOMEventReceiver> erP;
nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
if (NS_SUCCEEDED(result) && erP)
{
if (mKeyListenerP) {
erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID);
}
if (mMouseListenerP) {
erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID);
}
}
else
NS_NOTREACHED("~nsHTMLEditor");
}
}
#endif
}
nsresult nsHTMLEditor::InitHTMLEditor(nsIDOMDocument *aDoc,
nsIPresShell *aPresShell,
nsIEditorCallback *aCallback)
{
NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg");
nsresult result=NS_ERROR_NULL_POINTER;
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
{
nsITextEditor *aTextEditor = nsnull;
result = nsRepository::CreateInstance(kTextEditorCID, nsnull,
kITextEditorIID, (void **)&aTextEditor);
if (NS_FAILED(result) || !aTextEditor) {
return NS_ERROR_OUT_OF_MEMORY;
}
mTextEditor = aTextEditor; // CreateInstance did our addRef
// Initialize nsTextEditor -- this will create and initialize the base nsEditor
// Note: nsTextEditor adds its own key, mouse, and DOM listners -- is that OK?
result = mTextEditor->InitTextEditor(aDoc, aPresShell);
if (NS_OK != result) {
return result;
}
mTextEditor->EnableUndo(PR_TRUE);
// Get the pointer to the base editor for easier access
result = mTextEditor->QueryInterface(kIEditorIID, getter_AddRefs(mEditor));
if (NS_OK != result) {
return result;
}
result = NS_OK;
}
return result;
}
nsresult nsHTMLEditor::SetTextProperties(nsISupportsArray *aPropList)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->SetTextProperties(aPropList);
}
return result;
}
nsresult nsHTMLEditor::GetTextProperties(nsISupportsArray *aPropList)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->GetTextProperties(aPropList);
}
return result;
}
nsresult nsHTMLEditor::RemoveTextProperties(nsISupportsArray *aPropList)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->RemoveTextProperties(aPropList);
}
return result;
}
nsresult nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->DeleteSelection(aDir);
}
return result;
}
nsresult nsHTMLEditor::InsertText(const nsString& aStringToInsert)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->InsertText(aStringToInsert);
}
return result;
}
nsresult nsHTMLEditor::InsertBreak(PRBool aCtrlKey)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->InsertBreak(aCtrlKey);
}
return result;
}
// Methods shared with the base editor.
// Note: We could call each of these via nsTextEditor -- is that better?
nsresult nsHTMLEditor::EnableUndo(PRBool aEnable)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->EnableUndo(aEnable);
}
return result;
}
nsresult nsHTMLEditor::Undo(PRUint32 aCount)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->Undo(aCount);
}
return result;
}
nsresult nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->CanUndo(aIsEnabled, aCanUndo);
}
return result;
}
nsresult nsHTMLEditor::Redo(PRUint32 aCount)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->Redo(aCount);
}
return result;
}
nsresult nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->CanRedo(aIsEnabled, aCanRedo);
}
return result;
}
nsresult nsHTMLEditor::BeginTransaction()
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->BeginTransaction();
}
return result;
}
nsresult nsHTMLEditor::EndTransaction()
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mEditor->EndTransaction();
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionUp(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionDown(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionNext(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->MoveSelectionPrevious(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->SelectNext(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->SelectPrevious(aIncrement, aExtendSelection);
}
return result;
}
nsresult nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->ScrollUp(aIncrement);
}
return result;
}
nsresult nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->ScrollDown(aIncrement);
}
return result;
}
nsresult nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->ScrollIntoView(aScrollToBegin);
}
return result;
}
nsresult nsHTMLEditor::Insert(nsIInputStream *aInputStream)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->Insert(aInputStream);
}
return result;
}
nsresult nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->OutputText(aOutputStream);
}
return result;
}
nsresult nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream)
{
nsresult result=NS_ERROR_NOT_INITIALIZED;
if (mEditor)
{
result = mTextEditor->OutputHTML(aOutputStream);
}
return result;
}
NS_IMPL_ADDREF(nsHTMLEditor)
NS_IMPL_RELEASE(nsHTMLEditor)
nsresult
nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIHTMLEditorIID)) {
*aInstancePtr = (void*)(nsIHTMLEditor*)this;
NS_ADDREF_THIS();
return NS_OK;
}
// If our pointer to nsTextEditor is null, don't bother querying?
if (aIID.Equals(kITextEditorIID) && (mTextEditor)) {
nsCOMPtr<nsIEditor> editor;
nsresult result = mTextEditor->QueryInterface(kITextEditorIID, getter_AddRefs(editor));
if (NS_SUCCEEDED(result) && editor) {
*aInstancePtr = (void*)editor;
return NS_OK;
}
}
if (aIID.Equals(kIEditorIID) && (mEditor)) {
nsCOMPtr<nsIEditor> editor;
nsresult result = mEditor->QueryInterface(kIEditorIID, getter_AddRefs(editor));
if (NS_SUCCEEDED(result) && editor) {
*aInstancePtr = (void*)editor;
return NS_OK;
}
}
return NS_NOINTERFACE;
}
//================================================================
// HTML Editor methods
//
// Note: Table Editing methods are implemented in EditTable.cpp
//

View File

@@ -0,0 +1,118 @@
/* -*- 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://www.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 nsHTMLEditor_h__
#define nsHTMLEditor_h__
#include "nsITextEditor.h"
#include "nsIHTMLEditor.h"
#include "nsCOMPtr.h"
#include "nsIDOMEventListener.h"
#include "InsertTableTxn.h"
/**
* The HTML editor implementation.<br>
* Use to edit HTML document represented as a DOM tree.
*/
class nsHTMLEditor : public nsIHTMLEditor
{
public:
// see nsIHTMLEditor for documentation
//Interfaces for addref and release and queryinterface
NS_DECL_ISUPPORTS
//Initialization
nsHTMLEditor();
virtual nsresult InitHTMLEditor(nsIDOMDocument *aDoc,
nsIPresShell *aPresShell,
nsIEditorCallback *aCallback=nsnull);
virtual ~nsHTMLEditor();
//============================================================================
// Methods that are duplicates of nsTextEditor -- exposed here for convenience
// Editing Operations
virtual nsresult SetTextProperties(nsISupportsArray *aPropList);
virtual nsresult GetTextProperties(nsISupportsArray *aPropList);
virtual nsresult RemoveTextProperties(nsISupportsArray *aPropList);
virtual nsresult DeleteSelection(nsIEditor::Direction aDir);
virtual nsresult InsertText(const nsString& aStringToInsert);
virtual nsresult InsertBreak(PRBool aCtrlKey);
// Transaction control
virtual nsresult EnableUndo(PRBool aEnable);
virtual nsresult Undo(PRUint32 aCount);
virtual nsresult CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
virtual nsresult Redo(PRUint32 aCount);
virtual nsresult CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
virtual nsresult BeginTransaction();
virtual nsresult EndTransaction();
// Selection and navigation -- exposed here for convenience
virtual nsresult MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
virtual nsresult ScrollUp(nsIAtom *aIncrement);
virtual nsresult ScrollDown(nsIAtom *aIncrement);
virtual nsresult ScrollIntoView(PRBool aScrollToBegin);
// Input/Output
virtual nsresult Insert(nsIInputStream *aInputStream);
virtual nsresult OutputText(nsIOutputStream *aOutputStream);
virtual nsresult OutputHTML(nsIOutputStream *aOutputStream);
//=====================================
// HTML Editing methods
// Table Editing (implemented in EditTable.cpp)
virtual nsresult CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn);
virtual nsresult GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex);
virtual nsresult GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex);
virtual nsresult GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode);
virtual nsresult GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode);
virtual nsresult GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode);
virtual nsresult GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode);
virtual nsresult InsertTable();
virtual nsresult InsertTableCell(PRInt32 aNumber, PRBool aAfter);
virtual nsresult InsertTableColumn(PRInt32 aNumber, PRBool aAfter);
virtual nsresult InsertTableRow(PRInt32 aNumber, PRBool aAfter);
virtual nsresult DeleteTable();
virtual nsresult DeleteTableCell(PRInt32 aNumber);
virtual nsresult DeleteTableColumn(PRInt32 aNumber);
virtual nsresult DeleteTableRow(PRInt32 aNumber);
virtual nsresult JoinTableCells(PRBool aCellToRight);
// Data members
protected:
nsCOMPtr<nsIEditor> mEditor;
nsCOMPtr<nsITextEditor> mTextEditor;
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
// For now, the listners are tied to the nsTextEditor class
//
// nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
// nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
};
#endif //nsHTMLEditor_h__