Adding editor mode to the viewer

This commit is contained in:
joki 1998-06-24 00:29:00 +00:00
parent 435b8d9ff2
commit 3ce17a3724
9 changed files with 545 additions and 8 deletions

View File

@ -109,17 +109,23 @@ $(OBJDIR)/nsViewer.o:: nsViewer.cpp
$(OBJDIR)/nsMotifMenu.o:: nsMotifMenu.cpp
$(CCC) -o $@ -c $(CFLAGS) nsMotifMenu.cpp $(LDFLAGS)
$(OBJDIR)/nsEditorMode.o:: nsEditorMode.cpp
$(CCC) -o $@ -c $(CFLAGS) nsEditorMode.cpp $(LDFLAGS)
$(OBJDIR)/nsEditorInterfaces.o:: nsEditorInterfaces.cpp
$(CCC) -o $@ -c $(CFLAGS) nsEditorInterfaces.cpp $(LDFLAGS)
$(OBJDIR)/%.o: %.cpp
@$(MAKE_OBJDIR)
$(CCC) -o $@ $(CFLAGS) -c $*.cpp
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(EX_LIBS)
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(OBJDIR)/nsEditorMode.o $(OBJDIR)/nsEditorInterfaces.o $(EX_LIBS)
@$(MAKE_OBJDIR)
ifeq ($(OS_ARCH),Linux)
$(CCC) -rdynamic -o $@ $@.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS) -L/usr/X11R6/lib -lXm -lXt -lX11 -lXp -lXext
$(CCC) -rdynamic -o $@ $@.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(OBJDIR)/nsEditorMode.o $(OBJDIR)/nsEditorInterfaces.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS) -L/usr/X11R6/lib -lXm -lXt -lX11 -lXp -lXext
else
$(CCC) -o $@ $@.o -woff 84,85 $(LDFLAGS) $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(EX_LIBS) $(OS_LIBS) -lXm -lXt -lX11
$(CCC) -o $@ $@.o -woff 84,85 $(LDFLAGS) $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(OBJDIR)/nsEditorMode.o $(OBJDIR)/nsEditorInterfaces.o $(EX_LIBS) $(OS_LIBS) -lXm -lXt -lX11
endif
export::

View File

@ -30,11 +30,13 @@ MISCDEP= \
$(DIST)\lib\libplc21.lib
OBJS = \
.\$(OBJDIR)\winmain.obj \
.\$(OBJDIR)\nsViewer.obj \
.\$(OBJDIR)\JSConsole.obj \
.\$(OBJDIR)\nsDocLoader.obj \
OBJS = \
.\$(OBJDIR)\winmain.obj \
.\$(OBJDIR)\nsViewer.obj \
.\$(OBJDIR)\JSConsole.obj \
.\$(OBJDIR)\nsDocLoader.obj \
.\$(OBJDIR)\nsEditorInterfaces.obj \
.\$(OBJDIR)\nsEditorMode.obj \
$(NULL)
LINCS=-I$(PUBLIC)\raptor -I$(PUBLIC)\xpcom -I$(PUBLIC)\dom -I$(PUBLIC)\js -I$(PUBLIC)\netlib
@ -77,6 +79,7 @@ install:: $(PROGRAM)
$(MAKE_INSTALL) samples\test8siz.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test8sca.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test8tab.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test_ed.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test9.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test9a.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\raptor.jpg $(DIST)\bin\res\samples
@ -99,6 +102,7 @@ clobber::
rm -f $(DIST)\bin\res\samples\test8siz.html
rm -f $(DIST)\bin\res\samples\test8sca.html
rm -f $(DIST)\bin\res\samples\test8tab.html
rm -f $(DIST)\bin\res\samples\test_ed.html
rm -f $(DIST)\bin\res\samples\test9.html
rm -f $(DIST)\bin\res\samples\test9a.html
rm -f $(DIST)\bin\res\samples\raptor.jpg

View File

@ -0,0 +1,241 @@
/* -*- 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 "nsEditorInterfaces.h"
#include "nsEditorMode.h"
#include "nsString.h"
/*
* nsEditorKeyListener implementation
*/
nsEditorKeyListener::nsEditorKeyListener()
{
}
nsEditorKeyListener::~nsEditorKeyListener()
{
}
nsresult nsEditorKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
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;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMEventListenerIID)) {
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMKeyListenerIID)) {
*aInstancePtr = (void*)(nsIDOMKeyListener*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsEditorKeyListener)
NS_IMPL_RELEASE(nsEditorKeyListener)
nsresult nsEditorKeyListener::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult nsEditorKeyListener::GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar)
{
/* 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) {
*aChar = (char)aKeyCode;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult nsEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
PRUint32 mKeyCode;
PRBool mIsShift;
char mChar;
if (NS_OK == aKeyEvent->GetKeyCode(mKeyCode) &&
NS_OK == aKeyEvent->GetShiftKey(mIsShift)) {
switch(mKeyCode) {
case NS_VK_BACK:
nsDeleteLast();
break;
case NS_VK_RETURN:
// Need to implement creation of either <P> or <BR> nodes.
break;
default:
// XXX Replace with x-platform NS-virtkeycode transform.
char mChar;
if (NS_OK == GetCharFromKeyCode(mKeyCode, mIsShift, &mChar)) {
nsString* key = new nsString();
*key += mChar;
if (!mIsShift) {
key->ToLowerCase();
}
nsAppendText(key);
}
break;
}
}
return NS_ERROR_BASE;
}
nsresult nsEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
{
return NS_OK;
}
nsresult nsEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
return NS_OK;
}
/*
* nsEditorMouseListener implementation
*/
nsEditorMouseListener::nsEditorMouseListener()
{
}
nsEditorMouseListener::~nsEditorMouseListener()
{
}
nsresult nsEditorMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
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;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMEventListenerIID)) {
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMMouseListenerIID)) {
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsEditorMouseListener)
NS_IMPL_RELEASE(nsEditorMouseListener)
nsresult nsEditorMouseListener::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult nsEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
{
nsIDOMNode *aTarget;
if (NS_OK == aMouseEvent->GetTarget(&aTarget)) {
nsSetCurrentNode(aTarget);
NS_RELEASE(aTarget);
}
//Should not be error. Need a new way to do return values
return NS_ERROR_BASE;
}
nsresult nsEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
nsresult nsEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
nsresult nsEditorMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
nsresult nsEditorMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
nsresult nsEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
/*
* Factory functions
*/
nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult)
{
nsEditorKeyListener* it = new nsEditorKeyListener();
if (NULL == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}
nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult)
{
nsEditorMouseListener* it = new nsEditorMouseListener();
if (NULL == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}

View File

@ -0,0 +1,69 @@
/* -*- 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.
*/
#ifndef nsEditorInterfaces_h__
#define nsEditorInterfaces_h__
#include "nsIDOMEvent.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
//nsIDOMKeyListener interface
class nsEditorKeyListener : public nsIDOMKeyListener {
public:
nsEditorKeyListener();
virtual ~nsEditorKeyListener();
NS_DECL_ISUPPORTS
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
public:
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
private:
virtual nsresult GetCharFromKeyCode(PRUint32 aKeyCode, PRBool aIsShift, char *aChar);
};
//nsIDOMMouseListener interface
class nsEditorMouseListener : public nsIDOMMouseListener {
public:
nsEditorMouseListener();
virtual ~nsEditorMouseListener();
NS_DECL_ISUPPORTS
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
public:
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
};
extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult);
extern nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult);
#endif //nsEditorInterfaces_h__

View File

@ -0,0 +1,170 @@
/* -*- 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 "nsEditorMode.h"
#include "nsEditorInterfaces.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventCapturer.h"
#include "nsString.h"
#include "nsIDOMText.h"
#include "nsIDOMElement.h"
static nsIDOMDocument* kDomDoc;
static nsIDOMNode* kCurrentNode;
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
nsresult nsInitEditorMode(nsIDOMDocument *aDOMDocument)
{
NS_IF_RELEASE(kCurrentNode);
kCurrentNode = nsnull;
kDomDoc = aDOMDocument;
kDomDoc->AddRef();
RegisterEventListeners();
return NS_OK;
}
nsresult RegisterEventListeners()
{
nsIDOMEventReceiver *er;
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
if (NS_OK == kDomDoc->QueryInterface(kIDOMEventReceiverIID, (void**) &er)) {
nsIDOMEventListener * mouseListener;
nsIDOMEventListener * keyListener;
if (NS_OK == NS_NewEditorKeyListener(&keyListener)) {
er->AddEventListener(keyListener, kIDOMKeyListenerIID);
}
if (NS_OK == NS_NewEditorMouseListener(&mouseListener)) {
er->AddEventListener(mouseListener, kIDOMMouseListenerIID);
}
}
return NS_OK;
}
nsresult nsDeleteLast()
{
nsIDOMNode *mNode;
nsIDOMText *mText;
nsString mStr;
PRInt32 mLength;
if (NS_OK == nsGetCurrentNode(&mNode) &&
NS_OK == mNode->QueryInterface(kIDOMTextIID, (void**)&mText)) {
mText->GetData(mStr);
mLength = mStr.Length();
if (mLength > 0) {
mText->Delete(mLength-1, 1);
}
NS_RELEASE(mText);
}
NS_IF_RELEASE(mNode);
return NS_OK;
}
nsresult GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode)
{
PRInt32 mType;
PRBool mCNodes;
*aRetNode = nsnull;
aNode->GetNodeType(&mType);
if (aNode->ELEMENT == mType) {
if (NS_OK == aNode->HasChildNodes(&mCNodes) && PR_TRUE == mCNodes) {
nsIDOMNode *mNode, *mSibNode;
aNode->GetFirstChild(&mNode);
while(nsnull == *aRetNode) {
GetFirstTextNode(mNode, aRetNode);
mNode->GetNextSibling(&mSibNode);
NS_RELEASE(mNode);
mNode = mSibNode;
}
NS_IF_RELEASE(mNode);
}
}
else if (aNode->TEXT == mType) {
*aRetNode = aNode;
aNode->AddRef();
}
return NS_OK;
}
nsresult nsGetCurrentNode(nsIDOMNode ** aNode)
{
if (kCurrentNode != nsnull) {
*aNode = kCurrentNode;
kCurrentNode->AddRef();
return NS_OK;
}
/* If no node set, get first text node */
nsIDOMNode *mDocNode, *mFirstTextNode;
if (NS_OK == kDomDoc->GetFirstChild(&mDocNode) &&
NS_OK == GetFirstTextNode(mDocNode, &mFirstTextNode)) {
nsSetCurrentNode(mFirstTextNode);
NS_RELEASE(mFirstTextNode);
NS_RELEASE(mDocNode);
*aNode = kCurrentNode;
kCurrentNode->AddRef();
return NS_OK;
}
NS_IF_RELEASE(mDocNode);
return NS_ERROR_FAILURE;
}
nsresult nsSetCurrentNode(nsIDOMNode * aNode)
{
NS_IF_RELEASE(kCurrentNode);
kCurrentNode = aNode;
kCurrentNode->AddRef();
return NS_OK;
}
nsresult nsAppendText(nsString *aStr)
{
nsIDOMNode *mNode;
nsIDOMText *mText;
if (NS_OK == nsGetCurrentNode(&mNode) &&
NS_OK == mNode->QueryInterface(kIDOMTextIID, (void**)&mText)) {
mText->Append(*aStr);
NS_RELEASE(mText);
}
NS_IF_RELEASE(mNode);
return NS_OK;
}

View File

@ -0,0 +1,33 @@
/* -*- 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.
*/
#ifndef nsEditorMode_h__
#define nsEditorMode_h__
#include "nsIDOMDocument.h"
extern nsresult nsInitEditorMode(nsIDOMDocument * aDOMDocument);
extern nsresult nsAppendText(nsString *aStr);
extern nsresult nsDeleteLast();
extern nsresult nsSetCurrentNode(nsIDOMNode *aNode);
extern nsresult nsGetCurrentNode(nsIDOMNode **aNode);
nsresult RegisterEventListeners();
nsresult GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode);
#endif //nsEditorMode_h__

View File

@ -48,6 +48,8 @@
#include "nsIScriptContext.h"
#include "nsDocLoader.h"
#include "nsIFileWidget.h"
#include "nsIDOMDocument.h"
#include "nsEditorMode.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIPresShell.h"
@ -1037,6 +1039,16 @@ nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd)
case JS_CONSOLE:
ShowConsole(wd);
break;
case EDITOR_MODE:
if ((nsnull != wd) && (nsnull != wd->ww)) {
nsIDOMDocument* domDoc = nsnull;
if (NS_OK == wd->ww->GetDOMDocument(&domDoc)) {
nsInitEditorMode(domDoc);
domDoc->Release();
}
}
break;
}
return(result);

View File

@ -56,6 +56,7 @@
#define VIEWER_THREE_COLUMN 40035
#define JS_CONSOLE 40100
#define EDITOR_MODE 40120
#define VIEWER_EDIT_CUT 40201
#define VIEWER_EDIT_COPY 40202

View File

@ -80,6 +80,7 @@ VIEWER MENU DISCARDABLE
POPUP "&Tools"
{
MENUITEM "&JavaScript Console", JS_CONSOLE
MENUITEM "&Editor Mode", EDITOR_MODE
}
}