* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
166 lines
3.8 KiB
C++
166 lines
3.8 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
*
|
|
* The contents of this file are subject to the Netscape Public License
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
* http://www.mozilla.org/NPL/
|
|
*
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
* for the specific language governing rights and limitations under the
|
|
* NPL.
|
|
*
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
* Communications Corporation. Portions created by Netscape are
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
* Reserved.
|
|
*/
|
|
|
|
#include "nsIEditActionListener.h"
|
|
#include "nsTSDNotifier.h"
|
|
#include "nsTextServicesDocument.h"
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
static NS_DEFINE_IID(kIEditActionListenerIID, NS_IEDITACTIONLISTENER_IID);
|
|
|
|
nsTSDNotifier::nsTSDNotifier(nsTextServicesDocument *aDoc) : mDoc(aDoc)
|
|
{
|
|
}
|
|
|
|
nsTSDNotifier::~nsTSDNotifier()
|
|
{
|
|
mDoc = 0;
|
|
}
|
|
|
|
#define DEBUG_TSD_NOTIFIER_REFCNT 1
|
|
|
|
#ifdef DEBUG_TSD_NOTIFIER_REFCNT
|
|
|
|
nsrefcnt nsTSDNotifier::AddRef(void)
|
|
{
|
|
return ++mRefCnt;
|
|
}
|
|
|
|
nsrefcnt nsTSDNotifier::Release(void)
|
|
{
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
if (--mRefCnt == 0) {
|
|
NS_DELETEXPCOM(this);
|
|
return 0;
|
|
}
|
|
return mRefCnt;
|
|
}
|
|
|
|
#else
|
|
|
|
NS_IMPL_ADDREF(nsTSDNotifier)
|
|
NS_IMPL_RELEASE(nsTSDNotifier)
|
|
|
|
#endif
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
{
|
|
if (nsnull == aInstancePtr) {
|
|
return NS_ERROR_NULL_POINTER;
|
|
}
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
NS_ADDREF_THIS();
|
|
return NS_OK;
|
|
}
|
|
if (aIID.Equals(kIEditActionListenerIID)) {
|
|
*aInstancePtr = (void*)(nsIEditActionListener*)this;
|
|
NS_ADDREF_THIS();
|
|
return NS_OK;
|
|
}
|
|
*aInstancePtr = 0;
|
|
return NS_NOINTERFACE;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::WillInsertNode(nsIDOMNode *aNode,
|
|
nsIDOMNode *aParent,
|
|
PRInt32 aPosition)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::DidInsertNode(nsIDOMNode *aNode,
|
|
nsIDOMNode *aParent,
|
|
PRInt32 aPosition,
|
|
nsresult aResult)
|
|
{
|
|
if (NS_FAILED(aResult))
|
|
return NS_OK;
|
|
|
|
if (!mDoc)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return mDoc->InsertNode(aNode, aParent, aPosition);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::WillDeleteNode(nsIDOMNode *aChild)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult)
|
|
{
|
|
if (NS_FAILED(aResult))
|
|
return NS_OK;
|
|
|
|
if (!mDoc)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return mDoc->DeleteNode(aChild);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::WillSplitNode(nsIDOMNode *aExistingRightNode,
|
|
PRInt32 aOffset)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::DidSplitNode(nsIDOMNode *aExistingRightNode,
|
|
PRInt32 aOffset,
|
|
nsIDOMNode *aNewLeftNode,
|
|
nsresult aResult)
|
|
{
|
|
if (NS_FAILED(aResult))
|
|
return NS_OK;
|
|
|
|
if (!mDoc)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return mDoc->SplitNode(aExistingRightNode, aOffset, aNewLeftNode);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::WillJoinNodes(nsIDOMNode *aLeftNode,
|
|
nsIDOMNode *aRightNode,
|
|
nsIDOMNode *aParent)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsTSDNotifier::DidJoinNodes(nsIDOMNode *aLeftNode,
|
|
nsIDOMNode *aRightNode,
|
|
nsIDOMNode *aParent,
|
|
nsresult aResult)
|
|
{
|
|
if (NS_FAILED(aResult))
|
|
return NS_OK;
|
|
|
|
if (!mDoc)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return mDoc->JoinNodes(aLeftNode, aRightNode, aParent);
|
|
}
|