gecko-dev/editor/libeditor/base/IMETextTxn.cpp

356 lines
12 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2012-05-21 11:12:37 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "IMETextTxn.h"
#include "nsIDOMCharacterData.h"
#include "nsRange.h"
#include "nsIPrivateTextRange.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
#include "nsISelectionController.h"
#include "nsComponentManagerUtils.h"
#include "nsIEditor.h"
1999-12-01 00:35:31 +00:00
// #define DEBUG_IMETXN
IMETextTxn::IMETextTxn()
: EditTxn()
{
}
NS_IMPL_CYCLE_COLLECTION_CLASS(IMETextTxn)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IMETextTxn, EditTxn)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mElement)
// mRangeList can't lead to cycles
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IMETextTxn, EditTxn)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mElement)
// mRangeList can't lead to cycles
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IMETextTxn)
if (aIID.Equals(IMETextTxn::GetCID())) {
*aInstancePtr = (void*)(IMETextTxn*)this;
NS_ADDREF_THIS();
return NS_OK;
} else
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
PRUint32 aReplaceLength,
nsIPrivateTextRangeList *aTextRangeList,
const nsAString &aStringToInsert,
nsIEditor *aEditor)
{
NS_ASSERTION(aElement, "illegal value- null ptr- aElement");
NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList");
NS_ENSURE_TRUE(aElement && aTextRangeList, NS_ERROR_NULL_POINTER);
mElement = do_QueryInterface(aElement);
mOffset = aOffset;
mReplaceLength = aReplaceLength;
mStringToInsert = aStringToInsert;
mEditor = aEditor;
mRangeList = do_QueryInterface(aTextRangeList);
mFixed = false;
return NS_OK;
}
Fixes for bug #66308 ([embed] XPIDL'ize transaction manager) sr=sfraser@netscape.com,mscott@netscape.com r=jfrancis@netscape.com * nsITransaction, nsITransactionListenter, nsITransactionManager have been XPIDL'ized and moved into mozilla/editor/txmgr/idl. The versions of these interfaces in mozilla/editor/txmgr/public are being CVS removed. * Renamed Do(), Undo(), and Redo() to DoTransaction(), UndoTransaction(), and RedoTransaction() to avoid reserved word problems in languages like JS. I did a sweep through editor and mailnews to remove these methods. * PeekUndoStack() and PeekRedoStack() now return an AddRef'd pointer. * Removed GetUndoString(), GetRedoString() and Write() from the nsITransaction interface. Neither editor or mailnews really made use of these methods. * Removed Write() from the nsITransactionManager.cpp interface. * The Transaction Manager now supports weak references. * Added support for nsITransactionList to the TransactionManager to allow access to all transactions on the Undo and Redo stacks, as well as auto-aggregated transactions. * Removed all references to nsITransactionDescription from txmgr and editor. * Added nsPIEditorTransaction and made all Editor internal transactions inherit from it so we can distinguish between our transactions and ones from 3rd parties. New files checked in: editor/txmgr/idl/nsITransaction.idl editor/txmgr/idl/nsITransactionList.idl editor/txmgr/idl/nsITransactionListener.idl editor/txmgr/idl/nsITransactionManager.idl editor/txmgr/src/nsITransactionList.cpp editor/txmgr/src/nsITransactionList.h editor/idl/nsPIEditorTransaction.idl Files that were CVS removed: editor/txmgr/public/nsITransaction.h editor/txmgr/public/nsITransactionListener.h editor/txmgr/public/nsITransactionManager.h editor/txmgr/idl/nsITransactionDescription.h editor/base/IMECommitTxn.cpp editor/base/IMECommitTxn.h Files modified: editor/Makefile.in editor/makefile.win editor/base/ChangeAttributeTxn.cpp editor/base/ChangeAttributeTxn.h editor/base/CreateElementTxn.cpp editor/base/CreateElementTxn.h editor/base/DeleteElementTxn.cpp editor/base/DeleteElementTxn.h editor/base/DeleteRangeTxn.cpp editor/base/DeleteRangeTxn.h editor/base/DeleteTextTxn.cpp editor/base/DeleteTextTxn.h editor/base/EditAggregateTxn.cpp editor/base/EditAggregateTxn.h editor/base/EditTxn.cpp editor/base/EditTxn.h editor/base/IMECommitTxn.cpp editor/base/IMECommitTxn.h editor/base/IMETextTxn.cpp editor/base/IMETextTxn.h editor/base/InsertElementTxn.cpp editor/base/InsertElementTxn.h editor/base/InsertTextTxn.cpp editor/base/InsertTextTxn.h editor/base/JoinElementTxn.cpp editor/base/JoinElementTxn.h editor/base/nsEditor.cpp editor/base/nsEditorShell.cpp editor/base/nsEditorShell.h editor/base/nsEditorTxnLog.cpp editor/base/nsStyleSheetTxns.cpp editor/base/nsStyleSheetTxns.h editor/base/PlaceholderTxn.cpp editor/base/PlaceholderTxn.h editor/base/SetDocTitleTxn.cpp editor/base/SetDocTitleTxn.h editor/base/SplitElementTxn.cpp editor/base/SplitElementTxn.h editor/idl/Makefile.in editor/idl/makefile.win editor/idl/MANIFEST editor/idl/nsIEditorShell.idl editor/macbuild/editor.mcp editor/macbuild/EditorIDL.mcp editor/txmgr/idl/Makefile.in editor/txmgr/idl/makefile.win editor/txmgr/idl/MANIFEST editor/txmgr/idl/nsITransactionManager.idl editor/txmgr/macbuild/txmgr.mcp editor/txmgr/macbuild/txmgrIDL.mcp editor/txmgr/public/Makefile.in editor/txmgr/public/makefile.win editor/txmgr/public/MANIFEST editor/txmgr/src/Makefile.in editor/txmgr/src/makefile.win editor/txmgr/src/nsTransactionItem.cpp editor/txmgr/src/nsTransactionItem.h editor/txmgr/src/nsTransactionList.cpp editor/txmgr/src/nsTransactionList.h editor/txmgr/src/nsTransactionManager.cpp editor/txmgr/src/nsTransactionManager.h editor/txmgr/src/nsTransactionManagerFactory.cpp editor/txmgr/src/nsTransactionStack.cpp editor/txmgr/src/nsTransactionStack.h editor/txmgr/tests/TestTXMgr.cpp editor/ui/composer/content/EditorCommandsDebug.js editor/ui/composer/content/editorOverlay.xul editor/ui/composer/locale/en-US/editorOverlay.dtd mailnews/base/src/nsMessenger.cpp mailnews/base/util/nsMsgTxn.cpp mailnews/base/util/nsMsgTxn.h mailnews/imap/src/nsImapMailFolder.cpp mailnews/imap/src/nsImapUndoTxn.cpp mailnews/imap/src/nsImapUndoTxn.h mailnews/local/src/nsLocalMailFolder.cpp mailnews/local/src/nsLocalUndoTxn.cpp mailnews/local/src/nsLocalUndoTxn.h
2001-03-09 14:23:59 +00:00
NS_IMETHODIMP IMETextTxn::DoTransaction(void)
{
#ifdef DEBUG_IMETXN
printf("Do IME Text element = %p replace = %d len = %d\n", mElement.get(), mReplaceLength, mStringToInsert.Length());
#endif
nsCOMPtr<nsISelectionController> selCon;
mEditor->GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
// advance caret: This requires the presentation shell to get the selection.
nsresult result;
if (mReplaceLength == 0) {
result = mElement->InsertData(mOffset, mStringToInsert);
} else {
result = mElement->ReplaceData(mOffset, mReplaceLength, mStringToInsert);
}
if (NS_SUCCEEDED(result)) {
result = CollapseTextSelection();
}
return result;
}
Fixes for bug #66308 ([embed] XPIDL'ize transaction manager) sr=sfraser@netscape.com,mscott@netscape.com r=jfrancis@netscape.com * nsITransaction, nsITransactionListenter, nsITransactionManager have been XPIDL'ized and moved into mozilla/editor/txmgr/idl. The versions of these interfaces in mozilla/editor/txmgr/public are being CVS removed. * Renamed Do(), Undo(), and Redo() to DoTransaction(), UndoTransaction(), and RedoTransaction() to avoid reserved word problems in languages like JS. I did a sweep through editor and mailnews to remove these methods. * PeekUndoStack() and PeekRedoStack() now return an AddRef'd pointer. * Removed GetUndoString(), GetRedoString() and Write() from the nsITransaction interface. Neither editor or mailnews really made use of these methods. * Removed Write() from the nsITransactionManager.cpp interface. * The Transaction Manager now supports weak references. * Added support for nsITransactionList to the TransactionManager to allow access to all transactions on the Undo and Redo stacks, as well as auto-aggregated transactions. * Removed all references to nsITransactionDescription from txmgr and editor. * Added nsPIEditorTransaction and made all Editor internal transactions inherit from it so we can distinguish between our transactions and ones from 3rd parties. New files checked in: editor/txmgr/idl/nsITransaction.idl editor/txmgr/idl/nsITransactionList.idl editor/txmgr/idl/nsITransactionListener.idl editor/txmgr/idl/nsITransactionManager.idl editor/txmgr/src/nsITransactionList.cpp editor/txmgr/src/nsITransactionList.h editor/idl/nsPIEditorTransaction.idl Files that were CVS removed: editor/txmgr/public/nsITransaction.h editor/txmgr/public/nsITransactionListener.h editor/txmgr/public/nsITransactionManager.h editor/txmgr/idl/nsITransactionDescription.h editor/base/IMECommitTxn.cpp editor/base/IMECommitTxn.h Files modified: editor/Makefile.in editor/makefile.win editor/base/ChangeAttributeTxn.cpp editor/base/ChangeAttributeTxn.h editor/base/CreateElementTxn.cpp editor/base/CreateElementTxn.h editor/base/DeleteElementTxn.cpp editor/base/DeleteElementTxn.h editor/base/DeleteRangeTxn.cpp editor/base/DeleteRangeTxn.h editor/base/DeleteTextTxn.cpp editor/base/DeleteTextTxn.h editor/base/EditAggregateTxn.cpp editor/base/EditAggregateTxn.h editor/base/EditTxn.cpp editor/base/EditTxn.h editor/base/IMECommitTxn.cpp editor/base/IMECommitTxn.h editor/base/IMETextTxn.cpp editor/base/IMETextTxn.h editor/base/InsertElementTxn.cpp editor/base/InsertElementTxn.h editor/base/InsertTextTxn.cpp editor/base/InsertTextTxn.h editor/base/JoinElementTxn.cpp editor/base/JoinElementTxn.h editor/base/nsEditor.cpp editor/base/nsEditorShell.cpp editor/base/nsEditorShell.h editor/base/nsEditorTxnLog.cpp editor/base/nsStyleSheetTxns.cpp editor/base/nsStyleSheetTxns.h editor/base/PlaceholderTxn.cpp editor/base/PlaceholderTxn.h editor/base/SetDocTitleTxn.cpp editor/base/SetDocTitleTxn.h editor/base/SplitElementTxn.cpp editor/base/SplitElementTxn.h editor/idl/Makefile.in editor/idl/makefile.win editor/idl/MANIFEST editor/idl/nsIEditorShell.idl editor/macbuild/editor.mcp editor/macbuild/EditorIDL.mcp editor/txmgr/idl/Makefile.in editor/txmgr/idl/makefile.win editor/txmgr/idl/MANIFEST editor/txmgr/idl/nsITransactionManager.idl editor/txmgr/macbuild/txmgr.mcp editor/txmgr/macbuild/txmgrIDL.mcp editor/txmgr/public/Makefile.in editor/txmgr/public/makefile.win editor/txmgr/public/MANIFEST editor/txmgr/src/Makefile.in editor/txmgr/src/makefile.win editor/txmgr/src/nsTransactionItem.cpp editor/txmgr/src/nsTransactionItem.h editor/txmgr/src/nsTransactionList.cpp editor/txmgr/src/nsTransactionList.h editor/txmgr/src/nsTransactionManager.cpp editor/txmgr/src/nsTransactionManager.h editor/txmgr/src/nsTransactionManagerFactory.cpp editor/txmgr/src/nsTransactionStack.cpp editor/txmgr/src/nsTransactionStack.h editor/txmgr/tests/TestTXMgr.cpp editor/ui/composer/content/EditorCommandsDebug.js editor/ui/composer/content/editorOverlay.xul editor/ui/composer/locale/en-US/editorOverlay.dtd mailnews/base/src/nsMessenger.cpp mailnews/base/util/nsMsgTxn.cpp mailnews/base/util/nsMsgTxn.h mailnews/imap/src/nsImapMailFolder.cpp mailnews/imap/src/nsImapUndoTxn.cpp mailnews/imap/src/nsImapUndoTxn.h mailnews/local/src/nsLocalMailFolder.cpp mailnews/local/src/nsLocalUndoTxn.cpp mailnews/local/src/nsLocalUndoTxn.h
2001-03-09 14:23:59 +00:00
NS_IMETHODIMP IMETextTxn::UndoTransaction(void)
{
#ifdef DEBUG_IMETXN
printf("Undo IME Text element = %p\n", mElement.get());
#endif
nsCOMPtr<nsISelectionController> selCon;
mEditor->GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
nsresult result = mElement->DeleteData(mOffset, mStringToInsert.Length());
if (NS_SUCCEEDED(result))
{ // set the selection to the insertion point where the string was removed
nsCOMPtr<nsISelection> selection;
2000-04-27 07:37:12 +00:00
result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_SUCCEEDED(result) && selection) {
result = selection->Collapse(mElement, mOffset);
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of IME insert.");
}
}
return result;
}
NS_IMETHODIMP IMETextTxn::Merge(nsITransaction *aTransaction, bool *aDidMerge)
{
NS_ASSERTION(aDidMerge, "illegal vaule- null ptr- aDidMerge");
NS_ASSERTION(aTransaction, "illegal vaule- null ptr- aTransaction");
NS_ENSURE_TRUE(aDidMerge && aTransaction, NS_ERROR_NULL_POINTER);
#ifdef DEBUG_IMETXN
printf("Merge IME Text element = %p\n", mElement.get());
#endif
//
// check to make sure we aren't fixed, if we are then nothing get's absorbed
//
if (mFixed) {
*aDidMerge = false;
return NS_OK;
}
//
// if aTransaction is another IMETextTxn then absorb it
//
IMETextTxn* otherTxn = nsnull;
nsresult result = aTransaction->QueryInterface(IMETextTxn::GetCID(),(void**)&otherTxn);
if (otherTxn && NS_SUCCEEDED(result))
{
//
// we absorb the next IME transaction by adopting its insert string as our own
//
nsIPrivateTextRangeList* newTextRangeList;
otherTxn->GetData(mStringToInsert,&newTextRangeList);
mRangeList = do_QueryInterface(newTextRangeList);
*aDidMerge = true;
#ifdef DEBUG_IMETXN
printf("IMETextTxn assimilated IMETextTxn:%p\n", aTransaction);
#endif
NS_RELEASE(otherTxn);
return NS_OK;
}
*aDidMerge = false;
return NS_OK;
}
2000-07-11 19:51:36 +00:00
NS_IMETHODIMP IMETextTxn::MarkFixed(void)
{
mFixed = true;
2000-07-11 19:51:36 +00:00
return NS_OK;
}
NS_IMETHODIMP IMETextTxn::GetTxnDescription(nsAString& aString)
{
aString.AssignLiteral("IMETextTxn: ");
Fixes for bug #66308 ([embed] XPIDL'ize transaction manager) sr=sfraser@netscape.com,mscott@netscape.com r=jfrancis@netscape.com * nsITransaction, nsITransactionListenter, nsITransactionManager have been XPIDL'ized and moved into mozilla/editor/txmgr/idl. The versions of these interfaces in mozilla/editor/txmgr/public are being CVS removed. * Renamed Do(), Undo(), and Redo() to DoTransaction(), UndoTransaction(), and RedoTransaction() to avoid reserved word problems in languages like JS. I did a sweep through editor and mailnews to remove these methods. * PeekUndoStack() and PeekRedoStack() now return an AddRef'd pointer. * Removed GetUndoString(), GetRedoString() and Write() from the nsITransaction interface. Neither editor or mailnews really made use of these methods. * Removed Write() from the nsITransactionManager.cpp interface. * The Transaction Manager now supports weak references. * Added support for nsITransactionList to the TransactionManager to allow access to all transactions on the Undo and Redo stacks, as well as auto-aggregated transactions. * Removed all references to nsITransactionDescription from txmgr and editor. * Added nsPIEditorTransaction and made all Editor internal transactions inherit from it so we can distinguish between our transactions and ones from 3rd parties. New files checked in: editor/txmgr/idl/nsITransaction.idl editor/txmgr/idl/nsITransactionList.idl editor/txmgr/idl/nsITransactionListener.idl editor/txmgr/idl/nsITransactionManager.idl editor/txmgr/src/nsITransactionList.cpp editor/txmgr/src/nsITransactionList.h editor/idl/nsPIEditorTransaction.idl Files that were CVS removed: editor/txmgr/public/nsITransaction.h editor/txmgr/public/nsITransactionListener.h editor/txmgr/public/nsITransactionManager.h editor/txmgr/idl/nsITransactionDescription.h editor/base/IMECommitTxn.cpp editor/base/IMECommitTxn.h Files modified: editor/Makefile.in editor/makefile.win editor/base/ChangeAttributeTxn.cpp editor/base/ChangeAttributeTxn.h editor/base/CreateElementTxn.cpp editor/base/CreateElementTxn.h editor/base/DeleteElementTxn.cpp editor/base/DeleteElementTxn.h editor/base/DeleteRangeTxn.cpp editor/base/DeleteRangeTxn.h editor/base/DeleteTextTxn.cpp editor/base/DeleteTextTxn.h editor/base/EditAggregateTxn.cpp editor/base/EditAggregateTxn.h editor/base/EditTxn.cpp editor/base/EditTxn.h editor/base/IMECommitTxn.cpp editor/base/IMECommitTxn.h editor/base/IMETextTxn.cpp editor/base/IMETextTxn.h editor/base/InsertElementTxn.cpp editor/base/InsertElementTxn.h editor/base/InsertTextTxn.cpp editor/base/InsertTextTxn.h editor/base/JoinElementTxn.cpp editor/base/JoinElementTxn.h editor/base/nsEditor.cpp editor/base/nsEditorShell.cpp editor/base/nsEditorShell.h editor/base/nsEditorTxnLog.cpp editor/base/nsStyleSheetTxns.cpp editor/base/nsStyleSheetTxns.h editor/base/PlaceholderTxn.cpp editor/base/PlaceholderTxn.h editor/base/SetDocTitleTxn.cpp editor/base/SetDocTitleTxn.h editor/base/SplitElementTxn.cpp editor/base/SplitElementTxn.h editor/idl/Makefile.in editor/idl/makefile.win editor/idl/MANIFEST editor/idl/nsIEditorShell.idl editor/macbuild/editor.mcp editor/macbuild/EditorIDL.mcp editor/txmgr/idl/Makefile.in editor/txmgr/idl/makefile.win editor/txmgr/idl/MANIFEST editor/txmgr/idl/nsITransactionManager.idl editor/txmgr/macbuild/txmgr.mcp editor/txmgr/macbuild/txmgrIDL.mcp editor/txmgr/public/Makefile.in editor/txmgr/public/makefile.win editor/txmgr/public/MANIFEST editor/txmgr/src/Makefile.in editor/txmgr/src/makefile.win editor/txmgr/src/nsTransactionItem.cpp editor/txmgr/src/nsTransactionItem.h editor/txmgr/src/nsTransactionList.cpp editor/txmgr/src/nsTransactionList.h editor/txmgr/src/nsTransactionManager.cpp editor/txmgr/src/nsTransactionManager.h editor/txmgr/src/nsTransactionManagerFactory.cpp editor/txmgr/src/nsTransactionStack.cpp editor/txmgr/src/nsTransactionStack.h editor/txmgr/tests/TestTXMgr.cpp editor/ui/composer/content/EditorCommandsDebug.js editor/ui/composer/content/editorOverlay.xul editor/ui/composer/locale/en-US/editorOverlay.dtd mailnews/base/src/nsMessenger.cpp mailnews/base/util/nsMsgTxn.cpp mailnews/base/util/nsMsgTxn.h mailnews/imap/src/nsImapMailFolder.cpp mailnews/imap/src/nsImapUndoTxn.cpp mailnews/imap/src/nsImapUndoTxn.h mailnews/local/src/nsLocalMailFolder.cpp mailnews/local/src/nsLocalUndoTxn.cpp mailnews/local/src/nsLocalUndoTxn.h
2001-03-09 14:23:59 +00:00
aString += mStringToInsert;
return NS_OK;
}
/* ============ protected methods ================== */
static SelectionType TextRangeToSelection(int aTextRangeType)
{
switch(aTextRangeType)
{
case nsIPrivateTextRange::TEXTRANGE_RAWINPUT:
2000-04-27 07:37:12 +00:00
return nsISelectionController::SELECTION_IME_RAWINPUT;
case nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT:
2000-04-27 07:37:12 +00:00
return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;
case nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT:
2000-04-27 07:37:12 +00:00
return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;
case nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT:
2000-04-27 07:37:12 +00:00
return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;
case nsIPrivateTextRange::TEXTRANGE_CARETPOSITION:
default:
2000-04-27 07:37:12 +00:00
return nsISelectionController::SELECTION_NORMAL;
};
}
NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aTextRangeList)
{
NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
NS_ENSURE_TRUE(aTextRangeList, NS_ERROR_NULL_POINTER);
aResult = mStringToInsert;
*aTextRangeList = mRangeList;
return NS_OK;
}
static SelectionType sel[4]=
{
2000-04-27 07:37:12 +00:00
nsISelectionController::SELECTION_IME_RAWINPUT,
nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT,
nsISelectionController::SELECTION_IME_CONVERTEDTEXT,
nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT
};
NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void)
{
nsresult result;
PRUint16 i;
1999-12-01 00:35:31 +00:00
#ifdef DEBUG_IMETXN
PRUint16 listlen,start,stop,type;
result = mRangeList->GetLength(&listlen);
printf("nsIPrivateTextRangeList[%p]\n",mRangeList);
nsIPrivateTextRange* rangePtr;
for (i=0;i<listlen;i++) {
(void)mRangeList->Item(i,&rangePtr);
rangePtr->GetRangeStart(&start);
rangePtr->GetRangeEnd(&stop);
rangePtr->GetRangeType(&type);
printf("range[%d] start=%d end=%d type=",i,start,stop,type);
if (type==nsIPrivateTextRange::TEXTRANGE_RAWINPUT)
printf("TEXTRANGE_RAWINPUT\n");
else if (type==nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT)
printf("TEXTRANGE_SELECTEDRAWTEXT\n");
else if (type==nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT)
printf("TEXTRANGE_CONVERTEDTEXT\n");
else if (type==nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT)
printf("TEXTRANGE_SELECTEDCONVERTEDTEXT\n");
else if (type==nsIPrivateTextRange::TEXTRANGE_CARETPOSITION)
printf("TEXTRANGE_CARETPOSITION\n");
else printf("unknown constant\n");
}
#endif
//
// run through the text range list, if any
//
nsCOMPtr<nsISelectionController> selCon;
mEditor->GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
2000-04-27 07:37:12 +00:00
PRUint16 textRangeListLength,selectionStart,selectionEnd,
textRangeType;
textRangeListLength = mRangeList->GetLength();
nsCOMPtr<nsISelection> selection;
2000-04-27 07:37:12 +00:00
result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if(NS_SUCCEEDED(result))
{
nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
result = selPriv->StartBatchChanges();
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsISelection> imeSel;
for(PRInt8 selIdx = 0; selIdx < 4;selIdx++)
{
2000-04-27 07:37:12 +00:00
result = selCon->GetSelection(sel[selIdx], getter_AddRefs(imeSel));
if (NS_SUCCEEDED(result))
{
result = imeSel->RemoveAllRanges();
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot ClearSelection");
// we just ignore the result and clean up the next one here
}
}
nsCOMPtr<nsIPrivateTextRange> textRange;
bool setCaret=false;
for(i=0;i<textRangeListLength;i++)
{
textRange = mRangeList->Item(i);
NS_ASSERTION(textRange, "cannot get item");
if(!textRange)
break;
result = textRange->GetRangeType(&textRangeType);
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range type");
if(NS_FAILED(result))
break;
result = textRange->GetRangeStart(&selectionStart);
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range start");
if(NS_FAILED(result))
break;
result = textRange->GetRangeEnd(&selectionEnd);
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range end");
if(NS_FAILED(result))
break;
if(nsIPrivateTextRange::TEXTRANGE_CARETPOSITION == textRangeType)
{
NS_ASSERTION(selectionStart == selectionEnd,
"nsEditor doesn't support wide caret");
// Set the caret....
result = selection->Collapse(mElement,
mOffset+selectionStart);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot Collapse");
if(NS_SUCCEEDED(result))
setCaret = true;
} else {
// NS_ASSERTION(selectionStart != selectionEnd, "end == start");
if(selectionStart == selectionEnd)
continue;
2000-04-27 07:37:12 +00:00
result= selCon->GetSelection(TextRangeToSelection(textRangeType),
getter_AddRefs(imeSel));
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get selction");
if(NS_FAILED(result))
break;
nsRefPtr<nsRange> newRange = new nsRange();
result = newRange->SetStart(mElement,mOffset+selectionStart);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetStart");
if(NS_FAILED(result))
break;
result = newRange->SetEnd(mElement,mOffset+selectionEnd);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetEnd");
if(NS_FAILED(result))
break;
result = imeSel->AddRange(newRange);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot AddRange");
if(NS_FAILED(result))
break;
nsCOMPtr<nsISelectionPrivate> imeSelPriv(
do_QueryInterface(imeSel));
if (imeSelPriv) {
nsTextRangeStyle textRangeStyle;
result = textRange->GetRangeStyle(&textRangeStyle);
NS_ASSERTION(NS_SUCCEEDED(result),
"nsIPrivateTextRange::GetRangeStyle failed");
if (NS_FAILED(result))
break;
result = imeSelPriv->SetTextRangeStyle(newRange, textRangeStyle);
NS_ASSERTION(NS_SUCCEEDED(result),
"nsISelectionPrivate::SetTextRangeStyle failed");
if (NS_FAILED(result))
break;
} else {
NS_WARNING("IME selection doesn't have nsISelectionPrivate");
}
} // if GetRangeEnd
} // for textRangeListLength
if(! setCaret) {
// set cursor
result = selection->Collapse(mElement,mOffset+mStringToInsert.Length());
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot Collapse");
}
result = selPriv->EndBatchChanges();
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot EndBatchChanges");
} // if StartBatchChanges
} // if GetSelection
return result;
}