2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-21 04:51:09 +03:00
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-01-21 04:51:09 +03:00
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-01-21 04:51:09 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
#include "EditAggregateTxn.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
|
|
|
|
EditAggregateTxn::EditAggregateTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
1999-11-01 18:15:35 +03:00
|
|
|
nsresult res = NS_NewISupportsArray(getter_AddRefs(mChildren));
|
|
|
|
NS_POSTCONDITION(NS_SUCCEEDED(res), "EditAggregateTxn failed in constructor");
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EditAggregateTxn::~EditAggregateTxn()
|
|
|
|
{
|
1999-11-01 18:15:35 +03:00
|
|
|
// nsISupportsArray cleans up array for us at destruct time
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::DoTransaction(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
|
1999-11-01 18:15:35 +03:00
|
|
|
if (mChildren)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
1999-11-01 18:15:35 +03:00
|
|
|
PRUint32 count;
|
|
|
|
mChildren->Count(&count);
|
1999-12-01 18:29:52 +03:00
|
|
|
for (i=0; i<((PRInt32)count); i++)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2002-11-12 22:40:11 +03:00
|
|
|
nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
|
1999-10-07 00:27:41 +04:00
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
2001-03-09 17:23:59 +03:00
|
|
|
result = txn->DoTransaction();
|
1999-01-21 04:51:09 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::UndoTransaction(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
|
1999-11-01 18:15:35 +03:00
|
|
|
if (mChildren)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
1999-11-01 18:15:35 +03:00
|
|
|
PRUint32 count;
|
|
|
|
mChildren->Count(&count);
|
1999-01-21 04:51:09 +03:00
|
|
|
// undo goes through children backwards
|
|
|
|
for (i=count-1; i>=0; i--)
|
|
|
|
{
|
2002-11-12 22:40:11 +03:00
|
|
|
nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
|
1999-11-01 18:15:35 +03:00
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
2001-03-09 17:23:59 +03:00
|
|
|
result = txn->UndoTransaction();
|
1999-01-21 04:51:09 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::RedoTransaction(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
|
1999-11-01 18:15:35 +03:00
|
|
|
if (mChildren)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
1999-11-01 18:15:35 +03:00
|
|
|
PRUint32 count;
|
|
|
|
mChildren->Count(&count);
|
1999-12-01 18:29:52 +03:00
|
|
|
for (i=0; i<((PRInt32)count); i++)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2002-11-12 22:40:11 +03:00
|
|
|
nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
|
1999-11-01 18:15:35 +03:00
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
2001-03-09 17:23:59 +03:00
|
|
|
result = txn->RedoTransaction();
|
1999-01-21 04:51:09 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
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;
|
1999-11-01 18:15:35 +03:00
|
|
|
if (mChildren)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
1999-12-01 18:29:52 +03:00
|
|
|
PRInt32 i=0;
|
1999-11-01 18:15:35 +03:00
|
|
|
PRUint32 count;
|
|
|
|
mChildren->Count(&count);
|
1999-02-22 18:53:31 +03:00
|
|
|
NS_ASSERTION(count>0, "bad count");
|
|
|
|
if (0<count)
|
|
|
|
{
|
2002-11-12 22:40:11 +03:00
|
|
|
nsCOMPtr<nsITransaction> txn (do_QueryElementAt(mChildren, i));
|
1999-11-01 18:15:35 +03:00
|
|
|
if (!txn) { return NS_ERROR_NULL_POINTER; }
|
2001-03-09 17:23:59 +03:00
|
|
|
result = txn->Merge(aTransaction, aDidMerge);
|
1999-02-22 18:53:31 +03:00
|
|
|
}
|
1999-02-15 21:25:30 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
1999-01-21 04:51:09 +03:00
|
|
|
}
|
|
|
|
|
2002-03-24 01:16:54 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetTxnDescription(nsAString& aString)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
2001-03-09 17:23:59 +03:00
|
|
|
aString.Assign(NS_LITERAL_STRING("EditAggregateTxn: "));
|
1999-01-21 04:51:09 +03:00
|
|
|
|
2001-03-09 17:23:59 +03:00
|
|
|
if (mName)
|
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
mName->ToString(name);
|
|
|
|
aString += name;
|
|
|
|
}
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
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
|
|
|
{
|
1999-11-01 18:15:35 +03:00
|
|
|
if (mChildren && aTxn)
|
1999-01-21 04:51:09 +03:00
|
|
|
{
|
1999-11-01 18:15:35 +03:00
|
|
|
// aaahhhh! broken interfaces drive me crazy!!!
|
|
|
|
nsCOMPtr<nsISupports> isupports;
|
|
|
|
aTxn->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(isupports));
|
|
|
|
mChildren->AppendElement(isupports);
|
1999-01-21 04:51:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-11-01 18:15:35 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetCount(PRUint32 *aCount)
|
1999-02-15 21:25:30 +03:00
|
|
|
{
|
|
|
|
if (!aCount) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aCount=0;
|
|
|
|
if (mChildren) {
|
1999-11-01 18:15:35 +03:00
|
|
|
mChildren->Count(aCount);
|
1999-02-15 21:25:30 +03:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
1999-09-20 03:47:04 +04:00
|
|
|
// preconditions
|
|
|
|
NS_PRECONDITION(aTxn, "null out param");
|
|
|
|
NS_PRECONDITION(mChildren, "bad internal state");
|
|
|
|
|
1999-02-15 21:25:30 +03:00
|
|
|
if (!aTxn) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-09-20 03:47:04 +04:00
|
|
|
*aTxn = nsnull; // initialize out param as soon as we know it's a valid pointer
|
1999-02-15 21:25:30 +03:00
|
|
|
if (!mChildren) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
1999-09-20 03:47:04 +04:00
|
|
|
|
|
|
|
// get the transaction at aIndex
|
1999-11-01 18:15:35 +03:00
|
|
|
PRUint32 txnCount;
|
|
|
|
mChildren->Count(&txnCount);
|
1999-12-01 18:29:52 +03:00
|
|
|
if (0>aIndex || ((PRInt32)txnCount)<=aIndex) {
|
1999-02-15 21:25:30 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
1999-11-01 18:15:35 +03:00
|
|
|
// ugh, this is all wrong - what a mess we have with editor transaction interfaces
|
2002-11-12 22:40:11 +03:00
|
|
|
mChildren->QueryElementAt(aIndex, EditTxn::GetCID(), (void**)aTxn);
|
1999-02-15 21:25:30 +03:00
|
|
|
if (!*aTxn)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
|
1999-03-15 03:57:32 +03:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::SetName(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
mName = do_QueryInterface(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP EditAggregateTxn::GetName(nsIAtom **aName)
|
|
|
|
{
|
|
|
|
if (aName)
|
|
|
|
{
|
|
|
|
if (mName)
|
|
|
|
{
|
|
|
|
*aName = mName;
|
|
|
|
NS_ADDREF(*aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt) EditAggregateTxn::AddRef(void)
|
|
|
|
{
|
|
|
|
return EditTxn::AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
//NS_IMPL_RELEASE_INHERITED(Class, Super)
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) EditAggregateTxn::Release(void)
|
|
|
|
{
|
|
|
|
return EditTxn::Release();
|
|
|
|
}
|
|
|
|
|
2001-10-02 07:18:08 +04:00
|
|
|
//NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, AdditionalInterface)
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
NS_IMETHODIMP EditAggregateTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-06-25 03:33:18 +04:00
|
|
|
if (aIID.Equals(EditAggregateTxn::GetCID())) {
|
1999-09-22 02:29:44 +04:00
|
|
|
*aInstancePtr = NS_STATIC_CAST(EditAggregateTxn*, this);
|
|
|
|
// *aInstancePtr = (nsISupports*)(EditAggregateTxn*)(this);
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return EditTxn::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
1999-03-15 03:57:32 +03:00
|
|
|
|
|
|
|
|
1999-01-21 04:51:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
|