2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-24 04:29:00 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (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/
|
1998-06-24 04:29:00 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1998-06-24 04:29:00 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-01-11 23:49:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-09 05:43:24 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
1998-06-24 04:29:00 +04:00
|
|
|
#include "nsEditorMode.h"
|
|
|
|
#include "nsString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-01-14 21:52:16 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
1998-06-24 04:29:00 +04:00
|
|
|
|
1999-07-14 22:54:29 +04:00
|
|
|
#include "nsIEditor.h"
|
1999-03-02 08:31:41 +03:00
|
|
|
#include "nsIHTMLEditor.h"
|
1999-08-09 05:43:24 +04:00
|
|
|
#include "nsITableEditor.h"
|
1999-08-24 22:30:19 +04:00
|
|
|
#include "nsIDocumentEncoder.h" // for output flags
|
1999-08-09 05:43:24 +04:00
|
|
|
|
1999-01-06 23:31:08 +03:00
|
|
|
#include "nsEditorCID.h"
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-06 23:31:08 +03:00
|
|
|
#include "nsIServiceManager.h"
|
1999-03-02 08:31:41 +03:00
|
|
|
#include "resources.h"
|
2000-04-28 10:22:07 +04:00
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-01-06 23:31:08 +03:00
|
|
|
|
1999-08-09 05:43:24 +04:00
|
|
|
static nsIEditor *gEditor;
|
1998-06-24 04:29:00 +04:00
|
|
|
|
1999-03-02 08:31:41 +03:00
|
|
|
static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
1999-01-06 23:31:08 +03: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 11:16:51 +04:00
|
|
|
#else // XP_UNIX || XP_BEOS
|
1999-06-05 01:54:38 +04:00
|
|
|
#define EDITOR_DLL "libender"MOZ_DLL_SUFFIX
|
1999-01-06 23:31:08 +03:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1998-06-24 04:29:00 +04:00
|
|
|
|
1999-01-14 21:52:16 +03:00
|
|
|
nsresult NS_InitEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShell)
|
1998-06-24 04:29:00 +04:00
|
|
|
{
|
1999-01-06 23:31:08 +03:00
|
|
|
nsresult result = NS_OK;
|
1999-07-03 04:26:59 +04:00
|
|
|
|
1999-03-02 08:31:41 +03:00
|
|
|
// This is a big leak if called > once, but its only temp test code, correct?
|
1999-02-12 20:23:14 +03:00
|
|
|
if (gEditor)
|
1999-03-02 08:31:41 +03:00
|
|
|
gEditor=nsnull;
|
1999-01-06 23:31:08 +03:00
|
|
|
|
1999-01-14 21:52:16 +03: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 20:23:14 +03:00
|
|
|
/*
|
1999-01-06 23:31:08 +03:00
|
|
|
nsISupports *isup = nsnull;
|
1999-02-12 20:23:14 +03:00
|
|
|
result = nsServiceManager::GetService(kTextEditorCID,
|
|
|
|
kITextEditorIID, &isup);
|
|
|
|
*/
|
1999-03-09 12:44:27 +03:00
|
|
|
result = nsComponentManager::CreateInstance(kHTMLEditorCID,
|
1999-02-12 20:23:14 +03:00
|
|
|
nsnull,
|
2000-01-11 23:49:15 +03:00
|
|
|
NS_GET_IID(nsIEditor), (void **)&gEditor);
|
1999-02-12 20:23:14 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!gEditor) {
|
1999-01-06 23:31:08 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-04-28 10:22:07 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
selCon = do_QueryInterface(aPresShell);
|
2000-05-04 13:03:58 +04:00
|
|
|
result = gEditor->Init(aDOMDocument, aPresShell, nsnull, selCon, 0);
|
1999-08-30 17:35:40 +04:00
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = gEditor->PostCreate();
|
1999-01-06 23:31:08 +03:00
|
|
|
return result;
|
1998-06-24 04:29:00 +04:00
|
|
|
}
|
1999-03-02 08:31:41 +03:00
|
|
|
|
1999-03-06 23:49:34 +03:00
|
|
|
|
1999-08-09 05:43:24 +04:00
|
|
|
static nsresult PrintEditorOutput(nsIEditor* editor, PRInt32 aCommandID)
|
1999-03-06 23:49:34 +03:00
|
|
|
{
|
|
|
|
nsString outString;
|
1999-07-14 22:54:29 +04:00
|
|
|
char* cString;
|
|
|
|
nsString formatString;
|
1999-08-24 22:30:19 +04:00
|
|
|
PRUint32 flags = 0;
|
1999-03-06 23:49:34 +03:00
|
|
|
|
|
|
|
switch (aCommandID)
|
|
|
|
{
|
|
|
|
case VIEWER_DISPLAYTEXT:
|
2001-12-16 14:58:03 +03:00
|
|
|
formatString.Assign(NS_LITERAL_STRING("text/plain"));
|
1999-08-24 22:30:19 +04:00
|
|
|
flags = nsIDocumentEncoder::OutputFormatted;
|
2002-03-26 01:39:19 +03:00
|
|
|
editor->OutputToString(formatString, flags, outString);
|
1999-03-06 23:49:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DISPLAYHTML:
|
2001-12-16 14:58:03 +03:00
|
|
|
formatString.Assign(NS_LITERAL_STRING("text/html"));
|
2002-03-26 01:39:19 +03:00
|
|
|
editor->OutputToString(formatString, flags, outString);
|
1999-03-06 23:49:34 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
cString = ToNewCString(outString);
|
1999-03-06 23:49:34 +03:00
|
|
|
printf(cString);
|
|
|
|
delete [] cString;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-02 08:31:41 +03:00
|
|
|
nsresult NS_DoEditorTest(PRInt32 aCommandID)
|
|
|
|
{
|
1999-08-09 05:43:24 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(gEditor);
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(gEditor);
|
|
|
|
if (htmlEditor && tableEditor)
|
1999-03-02 08:31:41 +03:00
|
|
|
{
|
|
|
|
switch(aCommandID)
|
|
|
|
{
|
1999-06-24 00:27:54 +04:00
|
|
|
case VIEWER_EDIT_SET_BGCOLOR_RED:
|
2001-11-14 04:33:42 +03:00
|
|
|
htmlEditor->SetBodyAttribute(NS_LITERAL_STRING("bgcolor"), NS_LITERAL_STRING("red"));
|
1999-06-24 00:27:54 +04:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_SET_BGCOLOR_YELLOW:
|
2001-11-14 04:33:42 +03:00
|
|
|
htmlEditor->SetBodyAttribute(NS_LITERAL_STRING("bgcolor"), NS_LITERAL_STRING("yellow"));
|
1999-06-24 00:27:54 +04:00
|
|
|
break;
|
1999-03-02 08:31:41 +03:00
|
|
|
case VIEWER_EDIT_INSERT_CELL:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->InsertTableCell(1, PR_FALSE);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_INSERT_COLUMN:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->InsertTableColumn(1, PR_FALSE);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_INSERT_ROW:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->InsertTableRow(1, PR_FALSE);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_TABLE:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->DeleteTable();
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_CELL:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->DeleteTableCell(1);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_COLUMN:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->DeleteTableColumn(1);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_DELETE_ROW:
|
1999-08-09 05:43:24 +04:00
|
|
|
tableEditor->DeleteTableRow(1);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
|
|
|
case VIEWER_EDIT_JOIN_CELL_RIGHT:
|
2000-07-01 04:37:23 +04:00
|
|
|
tableEditor->JoinTableCells(PR_FALSE);
|
1999-03-02 08:31:41 +03:00
|
|
|
break;
|
1999-03-05 00:50:44 +03:00
|
|
|
case VIEWER_DISPLAYTEXT:
|
1999-03-06 23:49:34 +03:00
|
|
|
case VIEWER_DISPLAYHTML:
|
|
|
|
PrintEditorOutput(gEditor, aCommandID);
|
1999-03-05 00:50:44 +03:00
|
|
|
break;
|
|
|
|
default:
|
1999-03-02 08:31:41 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|