1998-06-24 00:29:00 +00: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.
|
|
|
|
*/
|
1999-08-09 01:43:24 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
1998-06-24 00:29:00 +00:00
|
|
|
#include "nsEditorMode.h"
|
|
|
|
#include "nsString.h"
|
1999-01-14 18:52:16 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
1998-06-24 00:29:00 +00:00
|
|
|
|
1999-07-14 18:54:29 +00:00
|
|
|
#include "nsIEditor.h"
|
1999-03-02 05:31:41 +00:00
|
|
|
#include "nsIHTMLEditor.h"
|
1999-08-09 01:43:24 +00:00
|
|
|
#include "nsITableEditor.h"
|
1999-08-24 18:30:19 +00:00
|
|
|
#include "nsIDocumentEncoder.h" // for output flags
|
1999-08-09 01:43:24 +00:00
|
|
|
|
1999-01-06 20:31:08 +00:00
|
|
|
#include "nsEditorCID.h"
|
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-06 20:31:08 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-03-02 05:31:41 +00:00
|
|
|
#include "resources.h"
|
1999-01-06 20:31:08 +00:00
|
|
|
|
1999-08-09 01:43:24 +00:00
|
|
|
static nsIEditor *gEditor;
|
1998-06-24 00:29:00 +00:00
|
|
|
|
1999-03-02 05:31:41 +00:00
|
|
|
static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
1999-01-06 20:31:08 +00:00
|
|
|
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"
|
1999-06-26 07:16:51 +00:00
|
|
|
#else // XP_UNIX || XP_BEOS
|
1999-06-04 21:54:38 +00:00
|
|
|
#define EDITOR_DLL "libender"MOZ_DLL_SUFFIX
|
1999-01-06 20:31:08 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1998-06-24 00:29:00 +00:00
|
|
|
|
1999-01-14 18:52:16 +00:00
|
|
|
nsresult NS_InitEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShell)
|
1998-06-24 00:29:00 +00:00
|
|
|
{
|
1999-01-06 20:31:08 +00:00
|
|
|
nsresult result = NS_OK;
|
1999-07-03 00:26:59 +00:00
|
|
|
|
1999-03-02 05:31:41 +00:00
|
|
|
// This is a big leak if called > once, but its only temp test code, correct?
|
1999-02-12 17:23:14 +00:00
|
|
|
if (gEditor)
|
1999-03-02 05:31:41 +00:00
|
|
|
gEditor=nsnull;
|
1999-01-06 20:31:08 +00:00
|
|
|
|
1999-01-14 18:52:16 +00:00
|
|
|
NS_ASSERTION(nsnull!=aDOMDocument, "null document");
|
|
|
|
NS_ASSERTION(nsnull!=aPresShell, "null presentation shell");
|
|
|
|
|
|
|
|
if ((nsnull==aDOMDocument) || (nsnull==aPresShell))
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-02-12 17:23:14 +00:00
|
|
|
/*
|
1999-01-06 20:31:08 +00:00
|
|
|
nsISupports *isup = nsnull;
|
1999-02-12 17:23:14 +00:00
|
|
|
result = nsServiceManager::GetService(kTextEditorCID,
|
|
|
|
kITextEditorIID, &isup);
|
|
|
|
*/
|
1999-03-09 09:44:27 +00:00
|
|
|
result = nsComponentManager::CreateInstance(kHTMLEditorCID,
|
1999-02-12 17:23:14 +00:00
|
|
|
nsnull,
|
1999-08-09 01:43:24 +00:00
|
|
|
nsIEditor::GetIID(), (void **)&gEditor);
|
1999-02-12 17:23:14 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!gEditor) {
|
1999-01-06 20:31:08 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1999-08-09 01:43:24 +00:00
|
|
|
result = gEditor->Init(aDOMDocument, aPresShell, 0);
|
1999-08-30 13:35:40 +00:00
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = gEditor->PostCreate();
|
1999-01-06 20:31:08 +00:00
|
|
|
return result;
|
1998-06-24 00:29:00 +00:00
|
|
|
}
|
1999-03-02 05:31:41 +00:00
|
|
|
|
1999-03-06 20:49:34 +00:00
|
|
|
|
1999-08-09 01:43:24 +00:00
|
|
|
static nsresult PrintEditorOutput(nsIEditor* editor, PRInt32 aCommandID)
|
1999-03-06 20:49:34 +00:00
|
|
|
{
|
|
|
|
nsString outString;
|
1999-07-14 18:54:29 +00:00
|
|
|
char* cString;
|
|
|
|
nsString formatString;
|
1999-08-24 18:30:19 +00:00
|
|
|
PRUint32 flags = 0;
|
1999-03-06 20:49:34 +00:00
|
|
|
|
|
|
|
switch (aCommandID)
|
|
|
|
{
|
|
|
|
case VIEWER_DISPLAYTEXT:
|
1999-07-14 18:54:29 +00:00
|
|
|
formatString = "text/plain";
|
1999-08-24 18:30:19 +00:00
|
|
|
flags = nsIDocumentEncoder::OutputFormatted;
|
1999-08-09 01:43:24 +00:00
|
|
|
editor->OutputToString(outString, formatString, flags);
|
1999-03-06 20:49:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DISPLAYHTML:
|
1999-07-14 18:54:29 +00:00
|
|
|
formatString = "text/html";
|
1999-08-09 01:43:24 +00:00
|
|
|
editor->OutputToString(outString, formatString, flags);
|
1999-03-06 20:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cString = outString.ToNewCString();
|
|
|
|
printf(cString);
|
|
|
|
delete [] cString;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-02 05:31:41 +00:00
|
|
|
nsresult NS_DoEditorTest(PRInt32 aCommandID)
|
|
|
|
{
|
1999-08-09 01:43:24 +00:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(gEditor);
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(gEditor);
|
|
|
|
if (htmlEditor && tableEditor)
|
1999-03-02 05:31:41 +00:00
|
|
|
{
|
|
|
|
switch(aCommandID)
|
|
|
|
{
|
1999-06-23 20:27:54 +00:00
|
|
|
case VIEWER_EDIT_SET_BGCOLOR_RED:
|
1999-08-09 01:43:24 +00:00
|
|
|
htmlEditor->SetBodyAttribute("bgcolor", "red");
|
1999-06-23 20:27:54 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_SET_BGCOLOR_YELLOW:
|
1999-08-09 01:43:24 +00:00
|
|
|
htmlEditor->SetBodyAttribute("bgcolor", "yellow");
|
1999-06-23 20:27:54 +00:00
|
|
|
break;
|
1999-03-02 05:31:41 +00:00
|
|
|
case VIEWER_EDIT_INSERT_CELL:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->InsertTableCell(1, PR_FALSE);
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_INSERT_COLUMN:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->InsertTableColumn(1, PR_FALSE);
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_INSERT_ROW:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->InsertTableRow(1, PR_FALSE);
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_TABLE:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->DeleteTable();
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_CELL:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->DeleteTableCell(1);
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_COLUMN:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->DeleteTableColumn(1);
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_ROW:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->DeleteTableRow(1);
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_JOIN_CELL_RIGHT:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->JoinTableCells();
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_JOIN_CELL_BELOW:
|
1999-08-09 01:43:24 +00:00
|
|
|
tableEditor->JoinTableCells();
|
1999-03-02 05:31:41 +00:00
|
|
|
break;
|
1999-03-04 21:50:44 +00:00
|
|
|
case VIEWER_DISPLAYTEXT:
|
1999-03-06 20:49:34 +00:00
|
|
|
case VIEWER_DISPLAYHTML:
|
|
|
|
PrintEditorOutput(gEditor, aCommandID);
|
1999-03-04 21:50:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
1999-03-02 05:31:41 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|