Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsEditorMode.cpp File Reference
#include "nsCOMPtr.h"
#include "nsEditorMode.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIDOMDocument.h"
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsITableEditor.h"
#include "nsIDocumentEncoder.h"
#include "nsEditorCID.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "resources.h"
#include "nsISelectionController.h"
#include "nsIPresShell.h"

Go to the source code of this file.

Functions

static NS_DEFINE_CID (kHTMLEditorCID, NS_HTMLEDITOR_CID)
nsresult NS_InitEditorMode (nsIDOMDocument *aDOMDocument, nsIPresShell *aPresShell)
static nsresult PrintEditorOutput (nsIEditor *editor, PRInt32 aCommandID)
nsresult NS_DoEditorTest (PRInt32 aCommandID)

Variables

static nsIEditorgEditor

Function Documentation

static NS_DEFINE_CID ( kHTMLEditorCID  ,
NS_HTMLEDITOR_CID   
) [static]
nsresult NS_DoEditorTest ( PRInt32  aCommandID)

Definition at line 121 of file nsEditorMode.cpp.

{
  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(gEditor);
  nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(gEditor);
  if (htmlEditor && tableEditor)
  {
    switch(aCommandID)
    {
      case VIEWER_EDIT_SET_BGCOLOR_RED:
        htmlEditor->SetBodyAttribute(NS_LITERAL_STRING("bgcolor"), NS_LITERAL_STRING("red"));
        break;
      case VIEWER_EDIT_SET_BGCOLOR_YELLOW:
        htmlEditor->SetBodyAttribute(NS_LITERAL_STRING("bgcolor"), NS_LITERAL_STRING("yellow"));
        break;
      case VIEWER_EDIT_INSERT_CELL:  
        tableEditor->InsertTableCell(1, PR_FALSE);
        break;    
      case VIEWER_EDIT_INSERT_COLUMN:
        tableEditor->InsertTableColumn(1, PR_FALSE);
        break;    
      case VIEWER_EDIT_INSERT_ROW:    
        tableEditor->InsertTableRow(1, PR_FALSE);
        break;    
      case VIEWER_EDIT_DELETE_TABLE:  
        tableEditor->DeleteTable();
        break;    
      case VIEWER_EDIT_DELETE_CELL:  
        tableEditor->DeleteTableCell(1);
        break;    
      case VIEWER_EDIT_DELETE_COLUMN:
        tableEditor->DeleteTableColumn(1);
        break;    
      case VIEWER_EDIT_DELETE_ROW:
        tableEditor->DeleteTableRow(1);
        break;    
      case VIEWER_EDIT_JOIN_CELL_RIGHT:
        tableEditor->JoinTableCells(PR_FALSE);
        break;    
      case VIEWER_DISPLAYTEXT:
      case VIEWER_DISPLAYHTML:
        PrintEditorOutput(gEditor, aCommandID);
        break;
     default:
        return NS_ERROR_NOT_IMPLEMENTED;    
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult NS_InitEditorMode ( nsIDOMDocument aDOMDocument,
nsIPresShell aPresShell 
)

Definition at line 63 of file nsEditorMode.cpp.

{
  nsresult result = NS_OK;

  // This is a big leak if called > once, but its only temp test code, correct?
  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;

  result = CallCreateInstance(kHTMLEditorCID, &gEditor);
  if (NS_FAILED(result))
    return result;
  if (!gEditor) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  nsCOMPtr<nsISelectionController> selCon;
  selCon = do_QueryInterface(aPresShell);
  result = gEditor->Init(aDOMDocument, aPresShell, nsnull, selCon, 0);
  if (NS_SUCCEEDED(result))
    result = gEditor->PostCreate();
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult PrintEditorOutput ( nsIEditor editor,
PRInt32  aCommandID 
) [static]

Definition at line 92 of file nsEditorMode.cpp.

{
       nsString             outString;
       char*                cString;
       nsString             formatString;
    PRUint32        flags = 0;
       
       switch (aCommandID)
       {
      case VIEWER_DISPLAYTEXT:
        formatString.AssignLiteral("text/plain");
        flags = nsIDocumentEncoder::OutputFormatted;
        editor->OutputToString(formatString, flags, outString);
        break;
        
      case VIEWER_DISPLAYHTML:
        formatString.AssignLiteral("text/html");
        editor->OutputToString(formatString, flags, outString);
        break;
       }

       cString = ToNewCString(outString);
       printf(cString);
       delete [] cString;
       
       return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

nsIEditor* gEditor [static]

Definition at line 59 of file nsEditorMode.cpp.