Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsComposerCommands.cpp File Reference
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsIHTMLAbsPosEditor.h"
#include "nsIDOMElement.h"
#include "nsIAtom.h"
#include "nsIClipboard.h"
#include "nsCOMPtr.h"
#include "nsComposerCommands.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsICommandParams.h"
#include "nsComponentManagerUtils.h"
#include "nsCRT.h"

Go to the source code of this file.

Defines

#define STATE_ENABLED   "state_enabled"
#define STATE_ALL   "state_all"
#define STATE_ANY   "state_any"
#define STATE_MIXED   "state_mixed"
#define STATE_BEGIN   "state_begin"
#define STATE_END   "state_end"
#define STATE_ATTRIBUTE   "state_attribute"
#define STATE_DATA   "state_data"

Functions

nsresult GetListState (nsIEditor *aEditor, PRBool *aMixed, PRUnichar **tagStr)
nsresult RemoveOneProperty (nsIHTMLEditor *aEditor, const nsString &aProp, const nsString &aAttr)
nsresult RemoveTextProperty (nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr)
nsresult SetTextProperty (nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value)

Define Documentation

#define STATE_ALL   "state_all"

Definition at line 73 of file nsComposerCommands.cpp.

#define STATE_ANY   "state_any"

Definition at line 74 of file nsComposerCommands.cpp.

#define STATE_ATTRIBUTE   "state_attribute"

Definition at line 78 of file nsComposerCommands.cpp.

#define STATE_BEGIN   "state_begin"

Definition at line 76 of file nsComposerCommands.cpp.

#define STATE_DATA   "state_data"

Definition at line 79 of file nsComposerCommands.cpp.

#define STATE_ENABLED   "state_enabled"

Definition at line 72 of file nsComposerCommands.cpp.

#define STATE_END   "state_end"

Definition at line 77 of file nsComposerCommands.cpp.

#define STATE_MIXED   "state_mixed"

Definition at line 75 of file nsComposerCommands.cpp.


Function Documentation

nsresult GetListState ( nsIEditor aEditor,
PRBool aMixed,
PRUnichar **  tagStr 
)

Definition at line 1616 of file nsComposerCommands.cpp.

{
  if (!aMixed || !_retval || !aEditor) 
    return NS_ERROR_NULL_POINTER;
  *_retval = nsnull;
  *aMixed = PR_FALSE;

  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
  nsresult err = NS_ERROR_NO_INTERFACE;
  if (htmlEditor)
  {
    PRBool bOL, bUL, bDL;
    err = htmlEditor->GetListState(aMixed, &bOL, &bUL, &bDL);
    if (NS_SUCCEEDED(err))
    {
      if (!*aMixed)
      {
        nsAutoString tagStr;
        if (bOL) 
          tagStr.AssignLiteral("ol");
        else if (bUL) 
          tagStr.AssignLiteral("ul");
        else if (bDL) 
          tagStr.AssignLiteral("dl");
        *_retval = ToNewUnicode(tagStr);
      }
    }  
  }
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult RemoveOneProperty ( nsIHTMLEditor aEditor,
const nsString aProp,
const nsString aAttr 
)

XXX Hack alert! Look in nsIEditProperty.h for this

Definition at line 1648 of file nsComposerCommands.cpp.

{
  if (!aEditor) 
    return NS_ERROR_NOT_INITIALIZED;

  nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(aProp);
  if (! styleAtom) 
    return NS_ERROR_OUT_OF_MEMORY;

  return aEditor->RemoveInlineProperty(styleAtom, aAttr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult RemoveTextProperty ( nsIEditor aEditor,
const PRUnichar prop,
const PRUnichar attr 
)

Definition at line 1666 of file nsComposerCommands.cpp.

{
  if (!aEditor) 
    return NS_ERROR_NOT_INITIALIZED;
  nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(aEditor);
  if (!editor) 
    return NS_ERROR_INVALID_ARG;
  // OK, I'm really hacking now. This is just so that 
  //     we can accept 'all' as input.  
  nsAutoString  allStr(prop);
  
  ToLowerCase(allStr);
  PRBool    doingAll = (allStr.EqualsLiteral("all"));
  nsresult  err = NS_OK;

  if (doingAll)
  {
    err = editor->RemoveAllInlineProperties();
  }
  else
  {
    nsAutoString  aProp(prop);
    nsAutoString  aAttr(attr);
    err = RemoveOneProperty(editor,aProp, aAttr);
  }
  
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult SetTextProperty ( nsIEditor aEditor,
const PRUnichar prop,
const PRUnichar attr,
const PRUnichar value 
)

XXX Hack alert! Look in nsIEditProperty.h for this

Definition at line 1699 of file nsComposerCommands.cpp.

{
  //static initialization 
  static const PRUnichar sEmptyStr = PRUnichar('\0');
  
  if (!aEditor) 
    return NS_ERROR_NOT_INITIALIZED;

  nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(prop);
  if (! styleAtom) 
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult  err = NS_NOINTERFACE;

  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor,&err);
  if (htmlEditor)
    err = htmlEditor->SetInlineProperty(styleAtom,
                                nsDependentString(attr?attr:&sEmptyStr),
                                nsDependentString(value?value:&sEmptyStr));

  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function: