1999-01-07 01:02:32 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00: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-07 01:02:32 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00: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-07 01:02:32 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-01-07 01:02:32 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-01-07 01:02:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "InsertTextTxn.h"
|
1999-02-12 17:18:58 +00:00
|
|
|
#include "nsEditor.h"
|
1999-01-07 01:02:32 +00:00
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-01-29 18:57:56 +00:00
|
|
|
#include "nsIDOMSelection.h"
|
1999-02-15 18:24:58 +00:00
|
|
|
#include "EditAggregateTxn.h"
|
1999-01-07 01:02:32 +00:00
|
|
|
|
1999-01-29 18:57:56 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
|
1999-01-14 18:02:45 +00:00
|
|
|
|
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 17:58:07 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-04-11 22:55:40 +00:00
|
|
|
static PRBool gNoisy = PR_FALSE;
|
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 17:58:07 +00:00
|
|
|
#else
|
|
|
|
static const PRBool gNoisy = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
1999-02-15 18:24:58 +00:00
|
|
|
nsIAtom *InsertTextTxn::gInsertTextTxnName;
|
|
|
|
|
|
|
|
nsresult InsertTextTxn::ClassInit()
|
|
|
|
{
|
|
|
|
if (nsnull==gInsertTextTxnName)
|
|
|
|
gInsertTextTxnName = NS_NewAtom("NS_InsertTextTxn");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-21 01:51:09 +00:00
|
|
|
|
1999-10-06 20:27:41 +00:00
|
|
|
nsresult InsertTextTxn::ClassShutdown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(gInsertTextTxnName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-21 01:51:09 +00:00
|
|
|
InsertTextTxn::InsertTextTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
1999-09-21 22:31:27 +00:00
|
|
|
SetTransactionDescriptionID( kTransactionID );
|
|
|
|
/* log description initialized in parent constructor */
|
1999-01-21 01:51:09 +00:00
|
|
|
}
|
|
|
|
|
1999-03-05 21:05:35 +00:00
|
|
|
InsertTextTxn::~InsertTextTxn()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
|
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 17:58:07 +00:00
|
|
|
PRUint32 aOffset,
|
|
|
|
const nsString &aStringToInsert,
|
2000-01-04 03:09:41 +00:00
|
|
|
nsIEditor *aEditor)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
1999-07-14 15:24:33 +00:00
|
|
|
#if 0 //def DEBUG_cmanske
|
1999-09-14 23:40:16 +00:00
|
|
|
nsAutoString text;
|
1999-07-14 15:24:33 +00:00
|
|
|
aElement->GetData(text);
|
|
|
|
printf("InsertTextTxn: Offset to insert at = %d. Text of the node to insert into:\n", aOffset);
|
|
|
|
wprintf(text.GetUnicode());
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2000-01-04 03:09:41 +00:00
|
|
|
NS_ASSERTION(aElement && aEditor, "bad args");
|
|
|
|
if (!aElement || !aEditor) return NS_ERROR_NULL_POINTER;
|
1999-08-19 13:30:48 +00:00
|
|
|
|
1999-02-19 11:30:31 +00:00
|
|
|
mElement = do_QueryInterface(aElement);
|
1999-01-07 01:02:32 +00:00
|
|
|
mOffset = aOffset;
|
|
|
|
mStringToInsert = aStringToInsert;
|
2000-01-04 03:09:41 +00:00
|
|
|
mEditor = aEditor;
|
1999-01-21 01:51:09 +00:00
|
|
|
return NS_OK;
|
1999-01-07 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::Do(void)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
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 17:58:07 +00:00
|
|
|
if (gNoisy) { printf("Do Insert Text element = %p\n", mElement.get()); }
|
2000-01-04 03:09:41 +00:00
|
|
|
NS_ASSERTION(mElement && mEditor, "bad state");
|
|
|
|
if (!mElement || !mEditor) { return NS_ERROR_NOT_INITIALIZED; }
|
|
|
|
|
|
|
|
nsresult result = mElement->InsertData(mOffset, mStringToInsert);
|
1999-08-25 10:51:55 +00:00
|
|
|
if (NS_FAILED(result)) return result;
|
2000-01-04 03:09:41 +00:00
|
|
|
|
|
|
|
// only set selection to insertion point if editor gives permission
|
|
|
|
PRBool bAdjustSelection;
|
|
|
|
mEditor->ShouldTxnSetSelection(&bAdjustSelection);
|
|
|
|
if (bAdjustSelection)
|
1999-08-25 10:51:55 +00:00
|
|
|
{
|
2000-01-04 03:09:41 +00:00
|
|
|
nsCOMPtr<nsIDOMSelection> selection;
|
|
|
|
result = mEditor->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!selection) return NS_ERROR_NULL_POINTER;
|
1999-08-19 13:30:48 +00:00
|
|
|
result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
|
|
|
|
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
|
1999-01-29 18:57:56 +00:00
|
|
|
}
|
2000-01-04 03:09:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// do nothing - dom range gravity will adjust selection
|
|
|
|
}
|
|
|
|
|
1999-02-22 15:53:31 +00:00
|
|
|
return result;
|
1999-01-07 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::Undo(void)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
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 17:58:07 +00:00
|
|
|
if (gNoisy) { printf("Undo Insert Text element = %p\n", mElement.get()); }
|
2000-01-04 03:09:41 +00:00
|
|
|
NS_ASSERTION(mElement && mEditor, "bad state");
|
|
|
|
if (!mElement || !mEditor) { return NS_ERROR_NOT_INITIALIZED; }
|
1999-08-19 13:30:48 +00:00
|
|
|
|
1999-01-28 19:00:14 +00:00
|
|
|
nsresult result;
|
1999-01-07 01:02:32 +00:00
|
|
|
PRUint32 length = mStringToInsert.Length();
|
1999-01-28 19:00:14 +00:00
|
|
|
result = mElement->DeleteData(mOffset, length);
|
|
|
|
return result;
|
1999-01-07 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
1999-01-14 18:02:45 +00:00
|
|
|
// set out param default value
|
|
|
|
if (nsnull!=aDidMerge)
|
|
|
|
*aDidMerge=PR_FALSE;
|
1999-02-17 01:59:56 +00:00
|
|
|
nsresult result = NS_OK;
|
1999-01-14 18:02:45 +00:00
|
|
|
if ((nsnull!=aDidMerge) && (nsnull!=aTransaction))
|
|
|
|
{
|
1999-01-28 17:19:24 +00:00
|
|
|
// if aTransaction isa InsertTextTxn, and if the selection hasn't changed,
|
|
|
|
// then absorb it
|
1999-06-28 13:44:40 +00:00
|
|
|
InsertTextTxn *otherInsTxn = nsnull;
|
1999-07-15 19:13:46 +00:00
|
|
|
aTransaction->QueryInterface(InsertTextTxn::GetCID(), (void **)&otherInsTxn);
|
1999-06-28 13:44:40 +00:00
|
|
|
if (otherInsTxn)
|
1999-01-14 18:02:45 +00:00
|
|
|
{
|
1999-06-28 13:44:40 +00:00
|
|
|
if (PR_TRUE==IsSequentialInsert(otherInsTxn))
|
1999-01-28 19:00:14 +00:00
|
|
|
{
|
|
|
|
nsAutoString otherData;
|
1999-06-28 13:44:40 +00:00
|
|
|
otherInsTxn->GetData(otherData);
|
1999-01-28 19:00:14 +00:00
|
|
|
mStringToInsert += otherData;
|
|
|
|
*aDidMerge = PR_TRUE;
|
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 17:58:07 +00:00
|
|
|
if (gNoisy) { printf("InsertTextTxn assimilated %p\n", aTransaction); }
|
1999-01-28 19:00:14 +00:00
|
|
|
}
|
1999-06-28 13:44:40 +00:00
|
|
|
NS_RELEASE(otherInsTxn);
|
1999-01-14 18:02:45 +00:00
|
|
|
}
|
1999-02-15 18:24:58 +00:00
|
|
|
else
|
|
|
|
{ // the next InsertTextTxn might be inside an aggregate that we have special knowledge of
|
1999-06-24 23:33:18 +00:00
|
|
|
EditAggregateTxn *otherTxn = nsnull;
|
|
|
|
aTransaction->QueryInterface(EditAggregateTxn::GetCID(), (void **)&otherTxn);
|
1999-02-15 18:24:58 +00:00
|
|
|
if (otherTxn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> txnName;
|
|
|
|
otherTxn->GetName(getter_AddRefs(txnName));
|
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 17:58:07 +00:00
|
|
|
if (txnName && txnName.get()==gInsertTextTxnName)
|
1999-02-15 18:24:58 +00:00
|
|
|
{ // yep, it's one of ours. By definition, it must contain only
|
1999-03-15 00:57:32 +00:00
|
|
|
// another aggregate with a single child,
|
|
|
|
// or a single InsertTextTxn
|
1999-09-21 22:31:27 +00:00
|
|
|
EditTxn * childTxn;
|
|
|
|
otherTxn->GetTxnAt(0, (&childTxn));
|
1999-03-15 00:57:32 +00:00
|
|
|
if (childTxn)
|
1999-02-15 18:24:58 +00:00
|
|
|
{
|
1999-09-21 22:31:27 +00:00
|
|
|
InsertTextTxn * otherInsertTxn = nsnull;
|
|
|
|
result = childTxn->QueryInterface(InsertTextTxn::GetCID(), (void**)&otherInsertTxn);
|
|
|
|
if (NS_SUCCEEDED(result))
|
1999-02-15 18:24:58 +00:00
|
|
|
{
|
1999-09-21 22:31:27 +00:00
|
|
|
if (otherInsertTxn)
|
1999-03-15 00:57:32 +00:00
|
|
|
{
|
1999-09-21 22:31:27 +00:00
|
|
|
if (PR_TRUE==IsSequentialInsert(otherInsertTxn))
|
|
|
|
{
|
|
|
|
nsAutoString otherData;
|
|
|
|
otherInsertTxn->GetData(otherData);
|
|
|
|
mStringToInsert += otherData;
|
|
|
|
*aDidMerge = PR_TRUE;
|
|
|
|
if (gNoisy) { printf("InsertTextTxn assimilated %p\n", aTransaction); }
|
|
|
|
}
|
|
|
|
NS_RELEASE(otherInsertTxn);
|
|
|
|
}
|
1999-02-15 18:24:58 +00:00
|
|
|
}
|
1999-09-21 22:31:27 +00:00
|
|
|
|
|
|
|
NS_RELEASE(childTxn);
|
1999-02-15 18:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-24 23:33:18 +00:00
|
|
|
NS_RELEASE(otherTxn);
|
1999-02-15 18:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
1999-01-14 18:02:45 +00:00
|
|
|
}
|
1999-02-17 01:59:56 +00:00
|
|
|
return result;
|
1999-01-07 01:02:32 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::Write(nsIOutputStream *aOutputStream)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-27 20:50:52 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::GetUndoString(nsString *aString)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
|
|
|
{
|
2000-04-18 07:44:58 +00:00
|
|
|
aString->AssignWithConversion("Remove Text: ");
|
1999-05-27 20:50:52 +00:00
|
|
|
*aString += mStringToInsert;
|
1999-01-07 01:02:32 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-27 20:50:52 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::GetRedoString(nsString *aString)
|
1999-01-07 01:02:32 +00:00
|
|
|
{
|
|
|
|
if (nsnull!=aString)
|
|
|
|
{
|
2000-04-18 07:44:58 +00:00
|
|
|
aString->AssignWithConversion("Insert Text: ");
|
1999-05-27 20:50:52 +00:00
|
|
|
*aString += mStringToInsert;
|
1999-01-07 01:02:32 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-14 18:02:45 +00:00
|
|
|
|
|
|
|
/* ============= nsISupports implementation ====================== */
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP
|
1999-01-14 18:02:45 +00:00
|
|
|
InsertTextTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-07-15 19:13:46 +00:00
|
|
|
if (aIID.Equals(InsertTextTxn::GetCID())) {
|
1999-01-14 18:02:45 +00:00
|
|
|
*aInstancePtr = (void*)(InsertTextTxn*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return (EditTxn::QueryInterface(aIID, aInstancePtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ============ protected methods ================== */
|
|
|
|
|
1999-03-02 05:30:53 +00:00
|
|
|
NS_IMETHODIMP InsertTextTxn::GetData(nsString& aResult)
|
1999-01-14 18:02:45 +00:00
|
|
|
{
|
|
|
|
aResult = mStringToInsert;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-28 19:00:14 +00:00
|
|
|
|
|
|
|
PRBool InsertTextTxn::IsSequentialInsert(InsertTextTxn *aOtherTxn)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull!=aOtherTxn, "null param");
|
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if (nsnull!=aOtherTxn)
|
|
|
|
{
|
|
|
|
if (aOtherTxn->mElement == mElement)
|
|
|
|
{
|
|
|
|
// here, we need to compare offsets.
|
1999-06-28 13:44:40 +00:00
|
|
|
PRInt32 length = mStringToInsert.Length();
|
|
|
|
if (aOtherTxn->mOffset==(mOffset+length))
|
1999-01-28 19:00:14 +00:00
|
|
|
{
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|