gecko-dev/editor/base/editorInterfaces.cpp

311 строки
6.2 KiB
C++
Исходник Обычный вид История

1998-11-11 06:34:37 +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 "editorInterfaces.h"
1998-11-11 06:34:37 +03:00
#include "nsString.h"
1998-11-12 03:15:58 +03:00
#include "editor.h"
1998-11-11 06:34:37 +03:00
1998-11-12 03:15:58 +03:00
1998-11-11 06:34:37 +03:00
/*
* nsEditorKeyListener implementation
1998-11-11 06:34:37 +03:00
*/
1998-11-12 03:15:58 +03:00
NS_IMPL_ADDREF(nsEditorKeyListener)
1998-11-12 03:15:58 +03:00
NS_IMPL_RELEASE(nsEditorKeyListener)
1998-11-12 03:15:58 +03:00
nsEditorKeyListener::nsEditorKeyListener()
1998-11-11 06:34:37 +03:00
{
}
1998-11-12 03:15:58 +03:00
nsEditorKeyListener::~nsEditorKeyListener()
1998-11-11 06:34:37 +03:00
{
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1998-11-11 06:34:37 +03:00
{
if (NULL == 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;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorKeyListener::ProcessEvent(nsIDOMEvent* aEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorKeyListener::GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar)
1998-11-11 06:34:37 +03:00
{
/* This is completely temporary to get this working while I check out Unicode conversion code. */
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;
}
return NS_ERROR_FAILURE;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
1998-11-11 06:34:37 +03:00
{
PRUint32 keyCode;
PRBool isShift;
PRBool ctrlKey;
char character;
1998-11-11 06:34:37 +03:00
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey))
) {
switch(keyCode) {
1998-11-11 06:34:37 +03:00
case nsIDOMEvent::VK_BACK:
break;
case nsIDOMEvent::VK_RETURN:
// Need to implement creation of either <P> or <BR> nodes.
mEditor->Commit(ctrlKey);
1998-11-11 06:34:37 +03:00
break;
default:
// XXX Replace with x-platform NS-virtkeycode transform.
if (NS_OK == GetCharFromKeyCode(keyCode, isShift, & character)) {
1998-11-11 06:34:37 +03:00
nsString* key = new nsString();
*key += character;
if (!isShift) {
1998-11-11 06:34:37 +03:00
key->ToLowerCase();
}
mEditor->InsertString(key);
delete key;
1998-11-11 06:34:37 +03:00
}
break;
}
}
return NS_ERROR_BASE;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
1998-11-11 06:34:37 +03:00
/*
* nsEditorMouseListener implementation
1998-11-11 06:34:37 +03:00
*/
1998-11-12 03:15:58 +03:00
NS_IMPL_ADDREF(nsEditorMouseListener)
1998-11-12 03:15:58 +03:00
NS_IMPL_RELEASE(nsEditorMouseListener)
1998-11-12 03:15:58 +03:00
nsEditorMouseListener::nsEditorMouseListener()
1998-11-11 06:34:37 +03:00
{
}
1998-11-12 03:15:58 +03:00
nsEditorMouseListener::~nsEditorMouseListener()
1998-11-11 06:34:37 +03:00
{
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1998-11-11 06:34:37 +03:00
{
if (NULL == 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;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::ProcessEvent(nsIDOMEvent* aEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
1998-11-11 06:34:37 +03:00
{
1998-11-12 03:15:58 +03:00
COM_auto_ptr<nsIDOMNode> target;
1998-11-13 01:18:43 +03:00
if (NS_OK == aMouseEvent->GetTarget(func_AddRefs(target))) {
1998-11-12 03:15:58 +03:00
// nsSetCurrentNode(aTarget);
1998-11-11 06:34:37 +03:00
}
//Should not be error. Need a new way to do return values
return NS_ERROR_BASE;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
1998-11-11 06:34:37 +03:00
{
mEditor->MouseClick(0,0);
1998-11-11 06:34:37 +03:00
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
nsresult
nsEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
1998-11-11 06:34:37 +03:00
{
return NS_OK;
}
1998-11-12 03:15:58 +03:00
1998-11-11 06:34:37 +03:00
/*
* Factory functions
*/
1998-11-12 03:15:58 +03:00
nsresult
NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult, nsEditor *aEditor)
1998-11-11 06:34:37 +03:00
{
nsEditorKeyListener* it = new nsEditorKeyListener();
1998-11-11 06:34:37 +03:00
if (NULL == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetEditor(aEditor);
1998-11-12 03:15:58 +03:00
1998-11-11 06:34:37 +03:00
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}
1998-11-12 03:15:58 +03:00
nsresult
NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsEditor *aEditor)
1998-11-11 06:34:37 +03:00
{
nsEditorMouseListener* it = new nsEditorMouseListener();
1998-11-11 06:34:37 +03:00
if (NULL == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetEditor(aEditor);
1998-11-12 03:15:58 +03:00
1998-11-11 06:34:37 +03:00
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}