1999-02-12 20:18:58 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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 "nsEditorEventListeners.h"
|
|
|
|
#include "nsEditor.h"
|
|
|
|
|
|
|
|
#include "CreateElementTxn.h"
|
|
|
|
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-02-24 20:24:37 +03:00
|
|
|
#include "nsIEditProperty.h"
|
|
|
|
#include "nsISupportsArray.h"
|
1999-02-12 20:18:58 +03:00
|
|
|
#include "nsString.h"
|
1999-03-23 01:10:29 +03:00
|
|
|
#include "nsIStringStream.h"
|
1999-02-12 20:18:58 +03:00
|
|
|
|
1999-04-20 21:43:26 +04:00
|
|
|
// for testing only
|
|
|
|
#include "nsIHTMLEditor.h"
|
|
|
|
// end for testing only
|
|
|
|
|
1999-04-15 10:06:33 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "TextEditorTest.h"
|
|
|
|
#endif
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
|
|
|
|
|
1999-04-07 00:24:09 +04:00
|
|
|
#ifdef NEW_CLIPBOARD_SUPPORT
|
|
|
|
|
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIClipboard.h"
|
1999-04-17 17:52:28 +04:00
|
|
|
#include "nsIDragService.h"
|
1999-04-07 00:24:09 +04:00
|
|
|
#include "nsITransferable.h"
|
1999-04-17 17:52:28 +04:00
|
|
|
#include "nsIGenericTransferable.h"
|
1999-04-07 00:24:09 +04:00
|
|
|
#include "nsIDataFlavor.h"
|
|
|
|
#include "nsIFormatConverter.h"
|
|
|
|
|
|
|
|
// Drag & Drop, Clipboard Support
|
|
|
|
static NS_DEFINE_IID(kIClipboardIID, NS_ICLIPBOARD_IID);
|
|
|
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
|
|
|
|
1999-04-17 17:52:28 +04:00
|
|
|
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
|
|
|
|
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIGenericTransferableIID, NS_IGENERICTRANSFERABLE_IID);
|
|
|
|
static NS_DEFINE_CID(kCGenericTransferableCID, NS_GENERICTRANSFERABLE_CID);
|
1999-04-07 00:24:09 +04:00
|
|
|
static NS_DEFINE_IID(kIDataFlavorIID, NS_IDATAFLAVOR_IID);
|
|
|
|
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
|
|
|
|
static NS_DEFINE_IID(kIFormatConverterIID, NS_IFORMATCONVERTER_IID);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
/*
|
|
|
|
* nsTextEditorKeyListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorKeyListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorKeyListener)
|
|
|
|
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
nsTextEditorKeyListener::nsTextEditorKeyListener()
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorKeyListener::~nsTextEditorKeyListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMKeyListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMKeyListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorKeyListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-12 08:28:22 +03:00
|
|
|
#define HAVE_EVENT_CHARCODE // on when we have the charCode in the event
|
1999-03-11 09:42:09 +03:00
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar)
|
|
|
|
{
|
|
|
|
/* This is completely temporary to get this working while I check out Unicode conversion code. */
|
|
|
|
#ifdef XP_MAC
|
|
|
|
if (aChar) {
|
|
|
|
*aChar = (char)aKeyCode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (aKeyCode >= 0x41 && aKeyCode <= 0x5A) {
|
|
|
|
if (aIsShift) {
|
|
|
|
*aChar = (char)aKeyCode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aChar = (char)(aKeyCode + 0x20);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if ((aKeyCode >= 0x30 && aKeyCode <= 0x39) || aKeyCode == 0x20) {
|
|
|
|
*aChar = (char)aKeyCode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
PRUint32 keyCode;
|
1999-03-11 09:42:09 +03:00
|
|
|
PRBool isShift;
|
|
|
|
PRBool ctrlKey;
|
1999-02-12 20:18:58 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
|
|
|
|
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
|
|
|
|
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey))
|
|
|
|
) {
|
|
|
|
PRBool keyProcessed;
|
|
|
|
ProcessShortCutKeys(aKeyEvent, keyProcessed);
|
|
|
|
if (PR_FALSE==keyProcessed)
|
|
|
|
{
|
|
|
|
switch(keyCode) {
|
|
|
|
case nsIDOMEvent::VK_BACK:
|
|
|
|
mEditor->DeleteSelection(nsIEditor::eRTL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMEvent::VK_DELETE:
|
|
|
|
mEditor->DeleteSelection(nsIEditor::eLTR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMEvent::VK_RETURN:
|
1999-03-11 22:34:28 +03:00
|
|
|
//case nsIDOMEvent::VK_ENTER: // why does this not exist?
|
1999-02-12 20:18:58 +03:00
|
|
|
// Need to implement creation of either <P> or <BR> nodes.
|
1999-03-10 22:49:43 +03:00
|
|
|
mEditor->InsertBreak();
|
1999-02-12 20:18:58 +03:00
|
|
|
break;
|
1999-03-11 22:34:28 +03:00
|
|
|
|
|
|
|
case nsIDOMEvent::VK_LEFT:
|
|
|
|
case nsIDOMEvent::VK_RIGHT:
|
|
|
|
case nsIDOMEvent::VK_UP:
|
|
|
|
case nsIDOMEvent::VK_DOWN:
|
|
|
|
// these have already been handled in nsRangeList. Why are we getting them
|
|
|
|
// again here (Mac)? In switch to avoid putting in bogus chars.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMEvent::VK_HOME:
|
|
|
|
case nsIDOMEvent::VK_END:
|
|
|
|
case nsIDOMEvent::VK_PAGE_UP:
|
|
|
|
case nsIDOMEvent::VK_PAGE_DOWN:
|
|
|
|
// who handles these?
|
|
|
|
#if DEBUG
|
1999-03-12 08:28:22 +03:00
|
|
|
printf("Key not handled\n");
|
1999-03-11 22:34:28 +03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
default:
|
|
|
|
{
|
1999-03-11 09:42:09 +03:00
|
|
|
nsAutoString key;
|
|
|
|
#ifdef HAVE_EVENT_CHARCODE
|
|
|
|
PRUint32 character;
|
|
|
|
// do we convert to Unicode here, or has this already been done? (sfraser)
|
|
|
|
if (NS_SUCCEEDED(aKeyEvent->GetCharCode(&character)))
|
|
|
|
{
|
|
|
|
key += character;
|
1999-03-14 07:12:21 +03:00
|
|
|
if (0!=character)
|
|
|
|
mEditor->InsertText(key);
|
1999-03-11 09:42:09 +03:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
char character;
|
1999-02-12 20:18:58 +03:00
|
|
|
// XXX Replace with x-platform NS-virtkeycode transform.
|
|
|
|
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
|
1999-03-14 07:12:21 +03:00
|
|
|
if (0!=character)
|
|
|
|
{
|
|
|
|
nsAutoString key;
|
|
|
|
key += character;
|
|
|
|
if (!isShift) {
|
|
|
|
key.ToLowerCase();
|
|
|
|
}
|
|
|
|
mEditor->InsertText(key);
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-11 09:42:09 +03:00
|
|
|
#endif
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_BASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* these includes are for debug only. this module should never instantiate it's own transactions */
|
|
|
|
#include "SplitElementTxn.h"
|
|
|
|
#include "TransactionFactory.h"
|
|
|
|
static NS_DEFINE_IID(kSplitElementTxnIID, SPLIT_ELEMENT_TXN_IID);
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed)
|
|
|
|
{
|
|
|
|
aProcessed=PR_FALSE;
|
|
|
|
PRUint32 keyCode;
|
|
|
|
PRBool isShift;
|
|
|
|
PRBool ctrlKey;
|
1999-03-23 01:10:29 +03:00
|
|
|
PRBool altKey;
|
1999-02-12 20:18:58 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
|
|
|
|
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
|
1999-03-23 01:10:29 +03:00
|
|
|
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey)) &&
|
|
|
|
NS_SUCCEEDED(aKeyEvent->GetAltKey(&altKey))
|
1999-02-12 20:18:58 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
// XXX: please please please get these mappings from an external source!
|
|
|
|
switch (keyCode)
|
|
|
|
{
|
1999-03-10 22:49:43 +03:00
|
|
|
// XXX: hard-coded select all
|
|
|
|
case nsIDOMEvent::VK_A:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->SelectAll();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-03-11 01:46:15 +03:00
|
|
|
// XXX: hard-coded cut
|
|
|
|
case nsIDOMEvent::VK_X:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->Cut();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// XXX: hard-coded copy
|
|
|
|
case nsIDOMEvent::VK_C:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->Copy();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// XXX: hard-coded paste
|
|
|
|
case nsIDOMEvent::VK_V:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
printf("control-v\n");
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->Paste();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
// XXX: hard-coded undo
|
|
|
|
case nsIDOMEvent::VK_Z:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
1999-03-02 10:52:41 +03:00
|
|
|
if (mEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
mEditor->Undo(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// XXX: hard-coded redo
|
|
|
|
case nsIDOMEvent::VK_Y:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
1999-03-02 10:52:41 +03:00
|
|
|
if (mEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
mEditor->Redo(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-02-24 20:24:37 +03:00
|
|
|
// hard-coded ChangeTextAttributes test -- italics
|
|
|
|
case nsIDOMEvent::VK_I:
|
1999-02-12 20:18:58 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-02-24 20:24:37 +03:00
|
|
|
aProcessed=PR_TRUE;
|
1999-03-02 10:52:41 +03:00
|
|
|
if (mEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
1999-04-04 22:01:35 +04:00
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->GetTextProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
|
1999-04-04 22:01:35 +04:00
|
|
|
if (PR_FALSE==first) {
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->SetTextProperty(nsIEditProperty::i, nsnull, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->RemoveTextProperty(nsIEditProperty::i, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
1999-02-24 20:24:37 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-23 01:10:29 +03:00
|
|
|
|
|
|
|
// Hardcoded Insert Arbitrary HTML
|
|
|
|
else if (PR_TRUE==altKey)
|
|
|
|
{
|
|
|
|
printf("Trying to insert HTML\n");
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsString nsstr ("<b>This is bold <em>and emphasized</em></b>");
|
1999-03-30 02:01:26 +04:00
|
|
|
nsresult res = mEditor->Insert(nsstr);
|
|
|
|
if (!NS_SUCCEEDED(res))
|
|
|
|
printf("nsTextEditor::Insert(string) failed\n");
|
1999-03-23 01:10:29 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-24 20:24:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- bold
|
|
|
|
case nsIDOMEvent::VK_B:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
1999-03-02 10:52:41 +03:00
|
|
|
if (mEditor)
|
1999-02-24 20:24:37 +03:00
|
|
|
{
|
1999-04-04 22:01:35 +04:00
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->GetTextProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
1999-04-04 22:01:35 +04:00
|
|
|
if (PR_FALSE==first) {
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->SetTextProperty(nsIEditProperty::b, nsnull, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->RemoveTextProperty(nsIEditProperty::b, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
1999-03-02 10:52:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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
|
|
|
// hard-coded ChangeTextAttributes test -- underline
|
1999-03-02 10:52:41 +03:00
|
|
|
case nsIDOMEvent::VK_U:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
1999-04-04 22:01:35 +04:00
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->GetTextProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
|
1999-04-04 22:01:35 +04:00
|
|
|
if (PR_FALSE==first) {
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->SetTextProperty(nsIEditProperty::u, nsnull, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-04-15 10:06:33 +04:00
|
|
|
mEditor->RemoveTextProperty(nsIEditProperty::u, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-04-15 10:06:33 +04:00
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font color red
|
|
|
|
case nsIDOMEvent::VK_1:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-16 22:29:12 +04:00
|
|
|
nsAutoString color = "COLOR";
|
1999-04-15 10:06:33 +04:00
|
|
|
nsAutoString value = "red";
|
|
|
|
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font color green
|
|
|
|
case nsIDOMEvent::VK_2:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-16 22:29:12 +04:00
|
|
|
nsAutoString color = "COLOR";
|
1999-04-15 10:06:33 +04:00
|
|
|
nsAutoString value = "green";
|
|
|
|
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-04-20 21:43:26 +04:00
|
|
|
// hard-coded ChangeTextAttributes test -- font size +2
|
|
|
|
case nsIDOMEvent::VK_3:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
|
|
|
nsAutoString prop = "SIZE";
|
|
|
|
nsAutoString value = "+2";
|
|
|
|
mEditor->SetTextProperty(nsIEditProperty::font, &prop, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font size -2
|
|
|
|
case nsIDOMEvent::VK_4:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
|
|
|
nsAutoString prop = "SIZE";
|
|
|
|
nsAutoString value = "-2";
|
|
|
|
mEditor->SetTextProperty(nsIEditProperty::font, &prop, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font face helvetica
|
|
|
|
case nsIDOMEvent::VK_5:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
|
|
|
nsAutoString prop = "FACE";
|
|
|
|
nsAutoString value = "helvetica";
|
|
|
|
mEditor->SetTextProperty(nsIEditProperty::font, &prop, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font face times
|
|
|
|
case nsIDOMEvent::VK_6:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
|
|
|
nsAutoString prop = "FACE";
|
|
|
|
nsAutoString value = "times";
|
|
|
|
mEditor->SetTextProperty(nsIEditProperty::font, &prop, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded change structure test -- block H1
|
|
|
|
case nsIDOMEvent::VK_7:
|
|
|
|
case nsIDOMEvent::VK_Q:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor>htmlEditor;
|
|
|
|
htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
{
|
|
|
|
nsAutoString tag;
|
|
|
|
nsIEditProperty::h1->ToString(tag);
|
|
|
|
htmlEditor->AddBlockParent(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded change structure test -- block H2
|
|
|
|
case nsIDOMEvent::VK_8:
|
|
|
|
case nsIDOMEvent::VK_W:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor>htmlEditor;
|
|
|
|
htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
{
|
|
|
|
nsAutoString tag;
|
|
|
|
nsIEditProperty::h2->ToString(tag);
|
|
|
|
htmlEditor->AddBlockParent(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded change structure test -- normal
|
|
|
|
case nsIDOMEvent::VK_9:
|
|
|
|
case nsIDOMEvent::VK_E:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor>htmlEditor;
|
|
|
|
htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor) {
|
|
|
|
htmlEditor->RemoveBlockParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
1999-04-15 10:06:33 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// hard-coded Text Editor Unit Test
|
|
|
|
case nsIDOMEvent::VK_T:
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
TextEditorTest *tester = new TextEditorTest();
|
|
|
|
if (tester)
|
|
|
|
{
|
|
|
|
tester->Run(mEditor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsTextEditorMouseListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorMouseListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorMouseListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorMouseListener::nsTextEditorMouseListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorMouseListener::~nsTextEditorMouseListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorMouseListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> target;
|
|
|
|
if (NS_OK == aMouseEvent->GetTarget(getter_AddRefs(target))) {
|
|
|
|
// nsSetCurrentNode(aTarget);
|
|
|
|
}
|
|
|
|
//Should not be error. Need a new way to do return values
|
|
|
|
return NS_ERROR_BASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsTextEditorMouseListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorTextListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorTextListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorTextListener::nsTextEditorTextListener()
|
|
|
|
: mCommitText(PR_FALSE),
|
|
|
|
mInTransaction(PR_FALSE)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorTextListener::~nsTextEditorTextListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
/*
|
|
|
|
* nsTextEditorDragListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorDragListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorDragListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorDragListener::nsTextEditorDragListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorDragListener::~nsTextEditorDragListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorTextListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kIDOMTextListenerIID, NS_IDOMTEXTLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMTextListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMTextListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorTextListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-03-20 02:36:20 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorTextListener::HandleText(nsIDOMEvent* aTextEvent)
|
|
|
|
{
|
|
|
|
nsString composedText;
|
|
|
|
const PRUnichar* composedTextAsChar;
|
|
|
|
PRBool commitText;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
aTextEvent->GetText(composedText);
|
|
|
|
composedTextAsChar = (const PRUnichar*)(&composedText);
|
|
|
|
|
|
|
|
if (!mInTransaction) {
|
|
|
|
// mEditor->BeginTransaction();
|
|
|
|
mInTransaction = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aTextEvent->GetCommitText(&commitText);
|
|
|
|
if (commitText) {
|
|
|
|
mEditor->Undo(1);
|
|
|
|
result = mEditor->InsertText(composedText);
|
|
|
|
// result = mEditor->EndTransaction();
|
|
|
|
mInTransaction=PR_FALSE;
|
|
|
|
mCommitText = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
if (!mCommitText) {
|
|
|
|
mEditor->Undo(1);
|
|
|
|
} else {
|
|
|
|
mCommitText = PR_FALSE;
|
|
|
|
}
|
|
|
|
result = mEditor->InsertText(composedText);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMDragListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMDragListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorDragListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-03-14 07:45:00 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-04-07 00:24:09 +04:00
|
|
|
nsTextEditorDragListener::DragEnter(nsIDOMEvent* aDragEvent)
|
|
|
|
{
|
1999-04-17 17:52:28 +04:00
|
|
|
#ifdef NEW_DRAG_AND_DROP
|
|
|
|
nsIDragService* dragService;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
|
|
|
kIDragServiceIID,
|
|
|
|
(nsISupports **)&dragService);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
dragService->SetCanDrop(PR_TRUE);
|
|
|
|
NS_RELEASE(dragService);
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-07 00:24:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragOver(nsIDOMEvent* aDragEvent)
|
|
|
|
{
|
1999-04-17 17:52:28 +04:00
|
|
|
#ifdef NEW_DRAG_AND_DROP
|
|
|
|
nsIDragService* dragService;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
|
|
|
kIDragServiceIID,
|
|
|
|
(nsISupports **)&dragService);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
dragService->SetCanDrop(PR_TRUE);
|
|
|
|
NS_RELEASE(dragService);
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-07 00:24:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragExit(nsIDOMEvent* aDragEvent)
|
1999-03-14 07:45:00 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
1999-04-07 00:24:09 +04:00
|
|
|
|
1999-04-17 17:52:28 +04:00
|
|
|
#ifdef NEW_DRAG_AND_DROP
|
1999-04-07 00:24:09 +04:00
|
|
|
nsString stuffToPaste;
|
1999-04-17 17:52:28 +04:00
|
|
|
nsIDragService* dragService;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
|
|
|
kIDragServiceIID,
|
|
|
|
(nsISupports **)&dragService);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIGenericTransferable *genericTrans = 0;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCGenericTransferableCID, nsnull,
|
|
|
|
kIGenericTransferableIID, (void**) &genericTrans);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIDataFlavor *flavor = 0;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCDataFlavorCID, nsnull, kIDataFlavorIID, (void**) &flavor);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
flavor->Init(kTextMime, "Text");
|
|
|
|
|
|
|
|
genericTrans->AddDataFlavor(flavor);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans = do_QueryInterface(genericTrans);
|
|
|
|
if (trans) {
|
|
|
|
|
|
|
|
dragService->GetData(trans);
|
|
|
|
|
|
|
|
char *str = 0;
|
|
|
|
PRUint32 len;
|
|
|
|
trans->GetTransferData(flavor, (void **)&str, &len);
|
|
|
|
|
|
|
|
if (str) {
|
|
|
|
if (str[len-1] == 0) {
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
stuffToPaste.SetString(str, len);
|
|
|
|
mEditor->InsertText(stuffToPaste);
|
|
|
|
}
|
1999-04-07 00:24:09 +04:00
|
|
|
|
1999-04-17 17:52:28 +04:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(flavor);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(genericTrans);
|
1999-04-07 00:24:09 +04:00
|
|
|
}
|
1999-04-17 17:52:28 +04:00
|
|
|
NS_IF_RELEASE(dragService);
|
1999-04-07 00:24:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//mEditor->InsertText(nsAutoString("hello"));
|
1999-03-14 07:45:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Factory functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult,
|
|
|
|
nsITextEditor *aEditor)
|
|
|
|
{
|
|
|
|
nsTextEditorKeyListener* it = new nsTextEditorKeyListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
|
|
|
|
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
|
|
|
|
nsITextEditor *aEditor)
|
|
|
|
{
|
|
|
|
nsTextEditorMouseListener* it = new nsTextEditorMouseListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
|
|
|
|
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsITextEditor* aEditor)
|
|
|
|
{
|
|
|
|
nsTextEditorTextListener* it = new nsTextEditorTextListener();
|
|
|
|
if (nsnull==it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
|
|
|
|
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult,
|
|
|
|
nsITextEditor *aEditor)
|
|
|
|
{
|
|
|
|
nsTextEditorDragListener* it = new nsTextEditorDragListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
|
|
|
|
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
|