Initial checkin of file for the EditorAppShell test bed.

This commit is contained in:
kin%netscape.com 1999-02-25 16:24:05 +00:00
Родитель 41307aeb5d
Коммит 09ffdb34b9
34 изменённых файлов: 1923 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,17 @@
interface EditorAppCore : BaseAppCore
{
/* IID: { 0x9afff72b, 0xca9a, 0x11d2, \
{0x96, 0xc9, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56}} */
void EditorAppCore();
void setAttribute(in wstring attr, in wstring value);
void undo();
void exit();
void setToolbarWindow(in Window win);
void setContentWindow(in Window win);
void setWebShellWindow(in Window win);
};

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMEditorAppCore_h__
#define nsIDOMEditorAppCore_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMBaseAppCore.h"
class nsIDOMWindow;
#define NS_IDOMEDITORAPPCORE_IID \
{ 0x9afff72b, 0xca9a, 0x11d2, \
{0x96, 0xc9, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56}}
class nsIDOMEditorAppCore : public nsIDOMBaseAppCore {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMEDITORAPPCORE_IID; return iid; }
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue)=0;
NS_IMETHOD Undo()=0;
NS_IMETHOD Exit()=0;
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin)=0;
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin)=0;
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin)=0;
};
#define NS_DECL_IDOMEDITORAPPCORE \
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue); \
NS_IMETHOD Undo(); \
NS_IMETHOD Exit(); \
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin); \
#define NS_FORWARD_IDOMEDITORAPPCORE(_to) \
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue) { return _to##SetAttribute(aAttr, aValue); } \
NS_IMETHOD Undo() { return _to##Undo(); } \
NS_IMETHOD Exit() { return _to##Exit(); } \
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to##SetToolbarWindow(aWin); } \
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to##SetContentWindow(aWin); } \
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin) { return _to##SetWebShellWindow(aWin); } \
extern "C" NS_DOM nsresult NS_InitEditorAppCoreClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptEditorAppCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMEditorAppCore_h__

Просмотреть файл

@ -0,0 +1,533 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsEditorAppCore.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "pratom.h"
#include "nsRepository.h"
#include "nsAppCores.h"
#include "nsAppCoresCIDs.h"
#include "nsAppCoresManager.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIWidget.h"
#include "plevent.h"
#include "nsIAppShell.h"
#include "nsIAppShellService.h"
#include "nsAppShellCIDs.h"
#include "nsIDocumentViewer.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsEditorMode.h"
///////////////////////////////////////
// Editor Includes
///////////////////////////////////////
//#include "nsEditorMode.h"
#include "nsEditorInterfaces.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventCapturer.h"
#include "nsString.h"
#include "nsIDOMText.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIEditor.h"
#include "nsITextEditor.h"
#include "nsEditorCID.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
///////////////////////////////////////
/* Define Class IDs */
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_IID(kEditorAppCoreCID, NS_EDITORAPPCORE_CID);
/* Define Interface IDs */
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIEditorAppCoreIID, NS_IDOMEDITORAPPCORE_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, nsIDOMDocument::IID());
static NS_DEFINE_IID(kIDocumentIID, nsIDocument::IID());
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
#define APP_DEBUG 0
/////////////////////////////////////////////////////////////////////////
// nsEditorAppCore
/////////////////////////////////////////////////////////////////////////
nsEditorAppCore::nsEditorAppCore()
{
if (APP_DEBUG) printf("Created nsEditorAppCore\n");
mScriptObject = nsnull;
mToolbarWindow = nsnull;
mToolbarScriptContext = nsnull;
mContentWindow = nsnull;
mContentScriptContext = nsnull;
mWebShellWin = nsnull;
mWebShell = nsnull;
mCurrentNode = nsnull;
mDomDoc = nsnull;
mEditor = nsnull;
IncInstanceCount();
NS_INIT_REFCNT();
}
nsEditorAppCore::~nsEditorAppCore()
{
NS_IF_RELEASE(mToolbarWindow);
NS_IF_RELEASE(mToolbarScriptContext);
NS_IF_RELEASE(mContentWindow);
NS_IF_RELEASE(mContentScriptContext);
NS_IF_RELEASE(mWebShellWin);
NS_IF_RELEASE(mWebShell);
DecInstanceCount();
}
NS_IMPL_ADDREF(nsEditorAppCore)
NS_IMPL_RELEASE(nsEditorAppCore)
NS_IMETHODIMP
nsEditorAppCore::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIEditorAppCoreIID) ) {
*aInstancePtr = (void*) ((nsIDOMEditorAppCore*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kINetSupportIID)) {
*aInstancePtr = (void*) ((nsINetSupport*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIStreamObserverIID)) {
*aInstancePtr = (void*) ((nsIStreamObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return nsBaseAppCore::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
nsEditorAppCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptEditorAppCore(aContext,
(nsISupports *)(nsIDOMEditorAppCore*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsEditorAppCore::Init(const nsString& aId)
{
nsBaseAppCore::Init(aId);
// XXX This is lame and needs to be changed
nsAppCoresManager* sdm = new nsAppCoresManager();
sdm->Add((nsIDOMBaseAppCore *)(nsBaseAppCore *)this);
delete sdm;
return NS_OK;
}
nsIPresShell*
nsEditorAppCore::GetPresShellFor(nsIWebShell* aWebShell)
{
nsIPresShell* shell = nsnull;
if (nsnull != aWebShell) {
nsIContentViewer* cv = nsnull;
aWebShell->GetContentViewer(&cv);
if (nsnull != cv) {
nsIDocumentViewer* docv = nsnull;
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
if (nsnull != docv) {
nsIPresContext* cx;
docv->GetPresContext(cx);
if (nsnull != cx) {
cx->GetShell(&shell);
NS_RELEASE(cx);
}
NS_RELEASE(docv);
}
NS_RELEASE(cv);
}
}
return shell;
}
void
nsEditorAppCore::DoEditorMode(nsIWebShell *aWebShell)
{
PRInt32 i, n;
if (nsnull != aWebShell) {
nsIContentViewer* mCViewer;
aWebShell->GetContentViewer(&mCViewer);
if (nsnull != mCViewer) {
nsIDocumentViewer* mDViewer;
if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer))
{
nsIDocument* mDoc;
mDViewer->GetDocument(mDoc);
if (nsnull != mDoc) {
nsIDOMDocument* mDOMDoc;
if (NS_OK == mDoc->QueryInterface(kIDOMDocumentIID, (void**) &mDOMDoc))
{
nsIPresShell* shell = GetPresShellFor(aWebShell);
NS_InitEditorMode(mDOMDoc, shell);
mEditor = GetEditor();
//SetToEditorMode(mDOMDoc, shell);
NS_RELEASE(mDOMDoc);
NS_IF_RELEASE(shell);
}
NS_RELEASE(mDoc);
}
NS_RELEASE(mDViewer);
}
NS_RELEASE(mCViewer);
}
aWebShell->GetChildCount(n);
for (i = 0; i < n; i++) {
nsIWebShell* mChild;
aWebShell->ChildAt(i, mChild);
DoEditorMode(mChild);
NS_RELEASE(mChild);
}
}
}
NS_IMETHODIMP
nsEditorAppCore::SetAttribute(const nsString& aAttr, const nsString& aValue)
{
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::Back()
{
ExecuteScript(mToolbarScriptContext, mDisableScript);
ExecuteScript(mContentScriptContext, "window.back();");
ExecuteScript(mToolbarScriptContext, mEnableScript);
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::Forward()
{
ExecuteScript(mToolbarScriptContext, mDisableScript);
ExecuteScript(mContentScriptContext, "window.forward();");
ExecuteScript(mToolbarScriptContext, mEnableScript);
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::SetDisableCallback(const nsString& aScript)
{
mDisableScript = aScript;
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::SetEnableCallback(const nsString& aScript)
{
mEnableScript = aScript;
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::LoadUrl(const nsString& aUrl)
{
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::SetToolbarWindow(nsIDOMWindow* aWin)
{
mToolbarWindow = aWin;
NS_ADDREF(aWin);
mToolbarScriptContext = GetScriptContext(aWin);
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::SetContentWindow(nsIDOMWindow* aWin)
{
mContentWindow = aWin;
NS_ADDREF(aWin);
mContentScriptContext = GetScriptContext(aWin);
nsCOMPtr<nsIScriptGlobalObject> globalObj( mContentWindow );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
DoEditorMode(webShell);
NS_RELEASE(webShell);
}
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
{
if (!mContentWindow) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIScriptGlobalObject> globalObj( aWin );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
mWebShell = webShell;
NS_ADDREF(mWebShell);
const PRUnichar * name;
webShell->GetName( &name);
nsAutoString str(name);
if (APP_DEBUG) printf("Attaching to WebShellWindow[%s]\n", str.ToNewCString());
nsIWebShellContainer * webShellContainer;
webShell->GetContainer(webShellContainer);
if (nsnull != webShellContainer) {
if (NS_OK == webShellContainer->QueryInterface(kIWebShellWindowIID, (void**) &mWebShellWin)) {
}
NS_RELEASE(webShellContainer);
}
NS_RELEASE(webShell);
}
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::NewWindow()
{
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::Undo()
{
if (mEditor) {
mEditor->Undo(1);
}
return NS_OK;
}
//----------------------------------------
void nsEditorAppCore::SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName)
{
PRInt32 count = 0;
nsCOMPtr<nsIDOMNode> button(FindNamedDOMNode(nsAutoString("button"), aParentNode, count, aBtnNum));
count = 0;
nsCOMPtr<nsIDOMNode> img(FindNamedDOMNode(nsAutoString("img"), button, count, 1));
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(img));
if (imgElement) {
char * str = aResName.ToNewCString();
imgElement->SetSrc(str);
delete [] str;
}
}
NS_IMETHODIMP
nsEditorAppCore::PrintPreview()
{
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::Close()
{
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::Exit()
{
nsIAppShellService* appShell = nsnull;
/*
* Create the Application Shell instance...
*/
nsresult rv = nsServiceManager::GetService(kAppShellServiceCID,
kIAppShellServiceIID,
(nsISupports**)&appShell);
if (NS_SUCCEEDED(rv)) {
appShell->Shutdown();
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
}
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCore::ExecuteScript(nsIScriptContext * aContext, const nsString& aScript)
{
if (nsnull != aContext) {
const char* url = "";
PRBool isUndefined = PR_FALSE;
nsString rVal;
if (APP_DEBUG) printf("Executing [%s]\n", aScript.ToNewCString());
aContext->EvaluateString(aScript, url, 0, rVal, &isUndefined);
}
return NS_OK;
}
//static nsIDOMDocument* mDomDoc;
//static nsIDOMNode* mCurrentNode;
//static nsIEditor *gEditor;
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID);
#ifdef XP_PC
#define EDITOR_DLL "ender.dll"
#else
#ifdef XP_MAC
#define EDITOR_DLL "ENDER_DLL"
#else // XP_UNIX
#define EDITOR_DLL "libender.so"
#endif
#endif
NS_IMETHODIMP
nsEditorAppCore::SetToEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShell)
{
nsresult result = NS_OK;
static needsInit=PR_TRUE;
#if 0
if (gEditor)
gEditor=nsnull;
NS_ASSERTION(nsnull!=aDOMDocument, "null document");
NS_ASSERTION(nsnull!=aPresShell, "null presentation shell");
if ((nsnull==aDOMDocument) || (nsnull==aPresShell))
return NS_ERROR_NULL_POINTER;
/** temp code until the editor auto-registers **/
if (PR_TRUE==needsInit)
{
needsInit=PR_FALSE;
result = nsRepository::RegisterFactory(kTextEditorCID, EDITOR_DLL,
PR_FALSE, PR_FALSE);
if (NS_ERROR_FACTORY_EXISTS!=result)
{
if (NS_FAILED(result))
return result;
}
result = nsRepository::RegisterFactory(kEditorCID, EDITOR_DLL,
PR_FALSE, PR_FALSE);
if (NS_ERROR_FACTORY_EXISTS!=result)
{
if (NS_FAILED(result))
return result;
}
}
/** end temp code **/
/*
nsISupports *isup = nsnull;
result = nsServiceManager::GetService(kTextEditorCID,
kITextEditorIID, &isup);
*/
result = nsRepository::CreateInstance(kTextEditorCID,
nsnull,
kITextEditorIID, (void **)&gEditor);
if (NS_FAILED(result))
return result;
if (!gEditor) {
return NS_ERROR_OUT_OF_MEMORY;
}
gEditor->InitTextEditor(aDOMDocument, aPresShell);
gEditor->EnableUndo(PR_TRUE);
#endif
return result;
}

Просмотреть файл

@ -0,0 +1,101 @@
/* -*- 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.
*/
#ifndef nsEditorAppCore_h___
#define nsEditorAppCore_h___
//#include "nsAppCores.h"
#include "nscore.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsIDOMEditorAppCore.h"
#include "nsBaseAppCore.h"
#include "nsINetSupport.h"
#include "nsIStreamObserver.h"
class nsIBrowserWindow;
class nsIWebShell;
class nsIScriptContext;
class nsIDOMWindow;
class nsIURL;
class nsIWebShellWindow;
class nsIPresShell;
class nsITextEditor;
////////////////////////////////////////////////////////////////////////////////
// nsEditorAppCore:
////////////////////////////////////////////////////////////////////////////////
class nsEditorAppCore : public nsBaseAppCore,
public nsIDOMEditorAppCore
{
public:
nsEditorAppCore();
virtual ~nsEditorAppCore();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD Init(const nsString& aId);
NS_IMETHOD GetId(nsString& aId) { return nsBaseAppCore::GetId(aId); }
NS_IMETHOD SetAttribute(const nsString& aAttr, const nsString& aValue);
NS_IMETHOD Undo();
NS_IMETHOD Back();
NS_IMETHOD Forward();
NS_IMETHOD LoadUrl(const nsString& aUrl);
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin);
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin);
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin);
NS_IMETHOD SetDisableCallback(const nsString& aScript);
NS_IMETHOD SetEnableCallback(const nsString& aScript);
NS_IMETHOD NewWindow();
NS_IMETHOD PrintPreview();
NS_IMETHOD Close();
NS_IMETHOD Exit();
protected:
NS_IMETHOD SetToEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShell);
nsIPresShell* GetPresShellFor(nsIWebShell* aWebShell);
void DoEditorMode(nsIWebShell *aWebShell);
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
void SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName);
nsString mEnableScript;
nsString mDisableScript;
nsIScriptContext *mToolbarScriptContext;
nsIScriptContext *mContentScriptContext;
nsIDOMWindow *mToolbarWindow;
nsIDOMWindow *mContentWindow;
nsIWebShellWindow *mWebShellWin;
nsIWebShell * mWebShell;
nsITextEditor * mEditor;
nsIDOMDocument* mDomDoc;
nsIDOMNode* mCurrentNode;
};
#endif // nsEditorAppCore_h___

Просмотреть файл

@ -0,0 +1,131 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsAppCores.h"
#include "nsEditorAppCoreFactory.h"
#include "nsEditorAppCore.h"
#include "pratom.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
/////////////////////////////////////////////////////////////////////////
// nsEditorAppCoreFactory
/////////////////////////////////////////////////////////////////////////
nsEditorAppCoreFactory::nsEditorAppCoreFactory(void)
{
mRefCnt=0;
IncInstanceCount();
}
nsEditorAppCoreFactory::~nsEditorAppCoreFactory(void)
{
DecInstanceCount();
}
NS_IMETHODIMP
nsEditorAppCoreFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*) this;
}
else if ( aIID.Equals(kIFactoryIID) )
{
*aInstancePtr = (void*) this;
}
if (aInstancePtr == NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsEditorAppCoreFactory::AddRef(void)
{
return ++mRefCnt;
}
NS_IMETHODIMP
nsEditorAppCoreFactory::Release(void)
{
if (--mRefCnt ==0)
{
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
NS_IMETHODIMP
nsEditorAppCoreFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
/* do I have to use iSupports? */
nsEditorAppCore *inst = new nsEditorAppCore();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsEditorAppCoreFactory::LockFactory(PRBool aLock)
{
if (aLock)
IncLockCount();
else
DecLockCount();
return NS_OK;
}

Просмотреть файл

Просмотреть файл

@ -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__

Просмотреть файл

@ -0,0 +1,102 @@
/* -*- 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 "nsString.h"
#include "nsIDOMDocument.h"
#include "nsITextEditor.h"
#include "nsEditorCID.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
static nsITextEditor *gEditor;
static NS_DEFINE_IID(kITextEditorIID, NS_ITEXTEDITOR_IID);
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID);
static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID);
#ifdef XP_PC
#define EDITOR_DLL "ender.dll"
#else
#ifdef XP_MAC
#define EDITOR_DLL "ENDER_DLL"
#else // XP_UNIX
#define EDITOR_DLL "libender.so"
#endif
#endif
nsITextEditor * GetEditor()
{
return gEditor;
}
nsresult NS_InitEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShell)
{
nsresult result = NS_OK;
static needsInit=PR_TRUE;
if (gEditor)
gEditor=nsnull;
NS_ASSERTION(nsnull!=aDOMDocument, "null document");
NS_ASSERTION(nsnull!=aPresShell, "null presentation shell");
if ((nsnull==aDOMDocument) || (nsnull==aPresShell))
return NS_ERROR_NULL_POINTER;
/** temp code until the editor auto-registers **/
if (PR_TRUE==needsInit)
{
needsInit=PR_FALSE;
result = nsRepository::RegisterFactory(kTextEditorCID, EDITOR_DLL,
PR_FALSE, PR_FALSE);
if (NS_ERROR_FACTORY_EXISTS!=result)
{
if (NS_FAILED(result))
return result;
}
result = nsRepository::RegisterFactory(kEditorCID, EDITOR_DLL,
PR_FALSE, PR_FALSE);
if (NS_ERROR_FACTORY_EXISTS!=result)
{
if (NS_FAILED(result))
return result;
}
}
/** end temp code **/
/*
nsISupports *isup = nsnull;
result = nsServiceManager::GetService(kTextEditorCID,
kITextEditorIID, &isup);
*/
result = nsRepository::CreateInstance(kTextEditorCID,
nsnull,
kITextEditorIID, (void **)&gEditor);
if (NS_FAILED(result))
return result;
if (!gEditor) {
return NS_ERROR_OUT_OF_MEMORY;
}
gEditor->InitTextEditor(aDOMDocument, aPresShell);
gEditor->EnableUndo(PR_TRUE);
return result;
}

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- 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 "nsError.h"
class nsIDOMDocument;
class nsIPresShell;
class nsITextEditor;
extern nsresult NS_InitEditorMode(nsIDOMDocument * aDOMDocument, nsIPresShell* aPresShell);
extern nsITextEditor * GetEditor();
#endif //nsEditorMode_h__

Просмотреть файл

@ -0,0 +1,547 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMEditorAppCore.h"
#include "nsIDOMWindow.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h"
#include "nsDOMCID.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIEditorAppCoreIID, NS_IDOMEDITORAPPCORE_IID);
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
NS_DEF_PTR(nsIDOMEditorAppCore);
NS_DEF_PTR(nsIDOMWindow);
/***********************************************************************/
//
// EditorAppCore Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetEditorAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMEditorAppCore *a = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// EditorAppCore Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetEditorAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMEditorAppCore *a = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// EditorAppCore finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeEditorAppCore(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// EditorAppCore enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateEditorAppCore(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// EditorAppCore resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveEditorAppCore(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method SetAttribute
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (NS_OK != nativeThis->SetAttribute(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setAttribute requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Undo
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreUndo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Undo()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function undo requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Exit
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreExit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Exit()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function exit requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetToolbarWindow
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreSetToolbarWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
nsIDOMWindowPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIWindowIID,
"Window",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->SetToolbarWindow(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setToolbarWindow requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetContentWindow
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreSetContentWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
nsIDOMWindowPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIWindowIID,
"Window",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->SetContentWindow(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setContentWindow requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetWebShellWindow
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCoreSetWebShellWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj);
nsIDOMWindowPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIWindowIID,
"Window",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->SetWebShellWindow(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setWebShellWindow requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for EditorAppCore
//
JSClass EditorAppCoreClass = {
"EditorAppCore",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetEditorAppCoreProperty,
SetEditorAppCoreProperty,
EnumerateEditorAppCore,
ResolveEditorAppCore,
JS_ConvertStub,
FinalizeEditorAppCore
};
//
// EditorAppCore class properties
//
static JSPropertySpec EditorAppCoreProperties[] =
{
{0}
};
//
// EditorAppCore class methods
//
static JSFunctionSpec EditorAppCoreMethods[] =
{
{"setAttribute", EditorAppCoreSetAttribute, 2},
{"undo", EditorAppCoreUndo, 0},
{"exit", EditorAppCoreExit, 0},
{"setToolbarWindow", EditorAppCoreSetToolbarWindow, 1},
{"setContentWindow", EditorAppCoreSetContentWindow, 1},
{"setWebShellWindow", EditorAppCoreSetWebShellWindow, 1},
{0}
};
//
// EditorAppCore constructor
//
PR_STATIC_CALLBACK(JSBool)
EditorAppCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIID classID;
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
nsIScriptNameSpaceManager* manager;
nsIDOMEditorAppCore *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kIDOMEditorAppCoreIID, NS_IDOMEDITORAPPCORE_IID);
result = context->GetNameSpaceManager(&manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = manager->LookupName("EditorAppCore", PR_TRUE, classID);
NS_RELEASE(manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = nsRepository::CreateInstance(classID,
nsnull,
kIDOMEditorAppCoreIID,
(void **)&nativeThis);
if (NS_OK != result) {
return JS_FALSE;
}
// XXX We should be calling Init() on the instance
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK != result) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
return JS_TRUE;
}
//
// EditorAppCore class initialization
//
extern "C" NS_DOM nsresult NS_InitEditorAppCoreClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "EditorAppCore", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitBaseAppCoreClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&EditorAppCoreClass, // JSClass
EditorAppCore, // JSNative ctor
0, // ctor args
EditorAppCoreProperties, // proto props
EditorAppCoreMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new EditorAppCore JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptEditorAppCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptEditorAppCore");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMEditorAppCore *aEditorAppCore;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitEditorAppCoreClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIEditorAppCoreIID, (void **)&aEditorAppCore);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &EditorAppCoreClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aEditorAppCore);
}
else {
NS_RELEASE(aEditorAppCore);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,303 @@
<?xml version="1.0"?>
<?xml-stylesheet href="xul.css" type="text/css"?>
<!DOCTYPE window>
<xul:window xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xul:onConstruction="Startup()">
<html:style>
#header {
position: fixed;
width: 100%;
height: 75px;
top: 0;
right: 0;
bottom: auto;
left: 0;
}
#main {
position: fixed;
width: auto;
height: auto;
top: 75px;
right: 0;
bottom: 34px;
left: 0;
overflow: auto;
padding: 2px .5em;
border: solid 0px black;
}
#footer {
position: fixed;
width: 100%;
height: 34px;
top: auto;
right: 0;
bottom: 0;
left: 0;
margin-top: auto;
}
button {
background-color: green;
color: red;
}
</html:style>
<html:script>
function Startup()
{
dump("Doing Startup...\n");
appCore = XPAppCoresManager.Find("EditorAppCore");
dump("Looking up EditorAppCore...\n");
if (appCore == null) {
dump("Creating EditorAppCore...\n");
appCore = new EditorAppCore();
if (appCore != null) {
dump("EditorAppCore has been created.\n");
appCore.Init("EditorAppCore");
appCore.setContentWindow(window.frames[0]);
appCore.setWebShellWindow(window);
appCore.setToolbarWindow(window);
dump("Adding EditorAppCore to AppCoreManager...\n");
XPAppCoresManager.Add(appCore);
}
} else {
dump("EditorAppCore has already been created! Why?\n");
}
}
function DoDisableButtons()
{
// Find buttons in the UI and disable them
dump("Browser disabling buttons\n");
}
function DoEnableButtons()
{
// Find buttons in the UI and enable them
dump("Browser enabling buttons\n");
}
function EditorBold()
{
appCore = XPAppCoresManager.Find("EditorAppCore");
if (appCore != null) {
dump("Going Back\n");
appCore.setAttribute("bold", "");
} else {
dump("EditorAppCore has not been created!\n");
}
}
function BrowserForward()
{
appCore = XPAppCoresManager.Find("EditorAppCore");
if (appCore != null) {
dump("Going Forward\n");
appCore.forward();
} else {
dump("EditorAppCore has not been created!\n");
}
}
function EditorNewWindow()
{
appCore = XPAppCoresManager.Find("EditorAppCore");
if (appCore != null) {
dump("Opening New Window\n");
appCore.newWindow();
} else {
dump("EditorAppCore has not been created!\n");
}
}
function EditorUndo()
{
appCore = XPAppCoresManager.Find("EditorAppCore");
if (appCore != null) {
dump("Opening New Window\n");
appCore.undo();
} else {
dump("EditorAppCore has not been created!\n");
}
}
function BrowserClose()
{
dump("BrowserClose\n");
}
function BrowserExit()
{
appCore = XPAppCoresManager.Find("EditorAppCore");
if (appCore != null) {
dump("Exiting\n");
appCore.exit();
} else {
dump("EditorAppCore has not been created!\n");
}
}
function EditorPrintPreview() {
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore) {
toolkitCore = new ToolkitCore();
if (toolkitCore)
toolkitCore.Init("ToolkitCore");
}
if (toolkitCore)
toolkitCore.ShowWindow("resource:/res/samples/printsetup.html", window);
}
}
</html:script>
<xul:broadcaster id="canGoBack"/>
<xul:broadcaster id="canGoForward"/>
<xul:broadcaster id="canReload"/>
<xul:broadcaster id="canStop"/>
<xul:broadcaster id="canPrint"/>
<xul:menubar>
<xul:menu name="File">
<xul:menuitem name="New Window" onClick="EditorNewWindow();"/>
<xul:menuitem name="Change Icons" onClick="BrowserPrintPreview();"/>
<xul:separator />
<xul:menuitem name="Print Setup" onClick="EditorPrintPreview();"/>
<xul:menuitem name="Print Preview" onClick="BrowserPrintPreview();"/>
<xul:menuitem name="Print" onClick=""/>
<xul:separator />
<xul:menuitem name="Close" onClick=""/>
<xul:menuitem name="Exit" onClick="BrowserExit();"/>
</xul:menu>
<xul:menu name="Edit">
<xul:menuitem name="Undo" onClick="EditorUndo();"/>
<xul:separator />
<xul:menuitem name="Cut" onClick="EditorCut();"/>
<xul:menuitem name="Copy" onClick="EditorCopy();"/>
<xul:menuitem name="Paste" onClick="EditorPaste();"/>
</xul:menu>
<xul:menu name="View">
<xul:menuitem name="Hide Composition Toolbar" onClick="BrowserBack();"/>
<xul:menuitem name="Hide Format Toolbar" onClick="BrowserForward();" />
</xul:menu>
<xul:menu name="Insert">
<xul:menuitem name="Link..." onClick="MakeDialog();"/>
<xul:menuitem name="Target..." onClick="BrowserBack();"/>
<xul:menuitem name="Image..." onClick="BrowserBack();"/>
<xul:menuitem name="Horizontal Line" onClick="BrowserBack();"/>
<xul:menuitem name="Table" onClick="BrowserBack();"/>
<xul:menuitem name="HTML Tag..." onClick="BrowserBack();"/>
<xul:separator />
<xul:menuitem name="Line Break" onClick="BrowserBack();"/>
<xul:menuitem name="Break Below Image(s)" onClick="BrowserBack();"/>
</xul:menu>
<xul:menu name="Format">
<xul:menuitem name="Font" onClick="BrowserBack();"/>
<xul:menuitem name="Size" onClick="BrowserBack();"/>
<xul:menuitem name="Style" onClick="BrowserBack();"/>
<xul:menuitem name="Color..." onClick="BrowserBack();"/>
<xul:menuitem name="Remove All Style(s)" onClick="BrowserBack();"/>
<xul:separator />
<xul:menuitem name="Heading" onClick="BrowserBack();"/>
</xul:menu>
<xul:menu name="Tools">
<xul:menuitem name="Spell Check" onClick="BrowserBack();"/>
</xul:menu>
<xul:menu name="Communicator">
<xul:menuitem name="Navigator" onClick="BrowserBack();"/>
</xul:menu>
<xul:menu name="Help">
<xul:menuitem name="About" onClick="BrowserBack();"/>
</xul:menu>
</xul:menubar>
<html:div html:id="header">
<xul:toolbox>
<xul:toolbar>
<html:button id="cut" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Cut.gif"/>
</html:button>
<html:button id="copy" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Copy.gif"/>
</html:button>
<html:button id="paste" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Paste.gif"/>
</html:button>
<html:button id="Find" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Find.gif"/>
</html:button>
<html:button id="link" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Link.gif"/>
</html:button>
<html:button id="target" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Target.gif"/>
</html:button>
<html:button id="image" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Image.gif"/>
</html:button>
<html:button id="hline" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_HLine.gif"/>
</html:button>
<html:button id="table" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Table.gif"/>
</html:button>
<html:button id="spell" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Spell.gif"/>
</html:button>
</xul:toolbar>
<xul:toolbar>
<html:button id="undo" onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Undo.gif"/>
</html:button>
<html:button id="bold" onClick="EditorBold()">
<html:img src="resource:/res/toolbar/ED_Bold.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Underline.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Indent.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Dedent.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Bullets.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Numbers.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Left.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Center.gif"/>
</html:button>
<html:button onClick="EditorUndo()">
<html:img src="resource:/res/toolbar/ED_Right.gif"/>
</html:button>
</xul:toolbar>
</xul:toolbox>
</html:div>
<html:div html:id="main">
<html:iframe html:name="content" html:src="EditorInitPage.html" html:width="100%" html:height="450"></html:iframe>
</html:div>
<html:div html:id="footer">
<html:iframe html:name="status" html:src="status.html" html:width="100%" html:height="34"></html:iframe>
</html:div>
</xul:window>

Просмотреть файл

@ -0,0 +1,14 @@
<html>
<head>
<title>Gecko Editor Startup Page</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Welcome to the Little Feat - The Gecko Editor Test Bed</h1>
</body>
</html>

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл