1999-01-21 04:51:09 +03:00
|
|
|
/* -*- 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 "EditAggregateTxn.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
|
|
|
|
EditAggregateTxn::EditAggregateTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
1999-02-15 21:25:30 +03:00
|
|
|
NS_INIT_REFCNT();
|
1999-01-21 04:51:09 +03:00
|
|
|
mChildren = new nsVoidArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditAggregateTxn::~EditAggregateTxn()
|
|
|
|
{
|
|
|
|
if (nsnull!=mChildren)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 count = mChildren->Count();
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
|
|
|
NS_IF_RELEASE(txn);
|
|
|
|
}
|
|
|
|
delete mChildren;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Do(void)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
|
|
|
if (nsnull!=mChildren)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 count = mChildren->Count();
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
|
|
|
result = txn->Do();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Undo(void)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
|
|
|
if (nsnull!=mChildren)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 count = mChildren->Count();
|
|
|
|
// undo goes through children backwards
|
|
|
|
for (i=count-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
|
|
|
result = txn->Undo();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Redo(void)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
|
|
|
if (nsnull!=mChildren)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 count = mChildren->Count();
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(i));
|
|
|
|
result = txn->Redo();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetIsTransient(PRBool *aIsTransient)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
if (nsnull!=aIsTransient)
|
1999-01-22 18:40:31 +03:00
|
|
|
*aIsTransient = PR_FALSE;
|
1999-01-21 04:51:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
1999-02-15 21:25:30 +03:00
|
|
|
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
|
|
|
|
if (nsnull!=aDidMerge)
|
|
|
|
*aDidMerge=PR_FALSE;
|
|
|
|
if (nsnull!=mChildren)
|
|
|
|
{
|
|
|
|
PRInt32 count = mChildren->Count();
|
1999-02-22 18:53:31 +03:00
|
|
|
NS_ASSERTION(count>0, "bad count");
|
|
|
|
if (0<count)
|
|
|
|
{
|
|
|
|
EditTxn *txn = (EditTxn*)(mChildren->ElementAt(count-1));
|
|
|
|
result = txn->Merge(aDidMerge, aTransaction);
|
|
|
|
}
|
1999-02-15 21:25:30 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Write(nsIOutputStream *aOutputStream)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetUndoString(nsString **aString)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
|
|
|
*aString=nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetRedoString(nsString **aString)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
|
|
|
*aString=nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::AppendChild(EditTxn *aTxn)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
if ((nsnull!=mChildren) && (nsnull!=aTxn))
|
|
|
|
{
|
|
|
|
mChildren->AppendElement(aTxn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::SetName(nsIAtom *aName)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
1999-02-19 14:30:31 +03:00
|
|
|
mName = do_QueryInterface(aName);
|
1999-02-15 21:25:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetName(nsIAtom **aName)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
|
|
|
if (aName)
|
|
|
|
{
|
|
|
|
if (mName)
|
|
|
|
{
|
|
|
|
*aName = mName;
|
|
|
|
NS_ADDREF(*aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetCount(PRInt32 *aCount)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
|
|
|
if (!aCount) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aCount=0;
|
|
|
|
if (mChildren) {
|
|
|
|
*aCount = mChildren->Count();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:30:53 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetTxnAt(PRInt32 aIndex, EditTxn **aTxn)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
|
|
|
if (!aTxn) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (!mChildren) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
const PRInt32 txnCount = mChildren->Count();
|
|
|
|
if (0>aIndex || txnCount<=aIndex) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
*aTxn = (EditTxn *)(mChildren->ElementAt(aIndex));
|
|
|
|
if (!*aTxn)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
NS_ADDREF(*aTxn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|