Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsStyleUpdatingCommand Class Reference

#include <nsComposerCommands.h>

Inheritance diagram for nsStyleUpdatingCommand:
Inheritance graph
[legend]
Collaboration diagram for nsStyleUpdatingCommand:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsStyleUpdatingCommand (const char *aTagName)
NS_DECL_ISUPPORTS NS_IMETHOD IsCommandEnabled (const char *aCommandName, nsISupports *aCommandRefCon, PRBool *_retval)=0
NS_IMETHOD DoCommand (const char *aCommandName, nsISupports *aCommandRefCon)=0
boolean isCommandEnabled (in string aCommandName, in nsISupports aCommandContext)
 Returns true if the command is currently enabled.
void getCommandStateParams (in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext)
void doCommand (in string aCommandName, in nsISupports aCommandContext)
 Execute the name command.
void doCommandParams (in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext)

Protected Member Functions

virtual nsresult GetCurrentState (nsIEditor *aEditor, const char *aTagName, nsICommandParams *aParams)
virtual nsresult ToggleState (nsIEditor *aEditor, const char *aTagName)

Protected Attributes

const char * mTagName

Detailed Description

Definition at line 110 of file nsComposerCommands.h.


Constructor & Destructor Documentation

Definition at line 207 of file nsComposerCommands.cpp.


Member Function Documentation

NS_IMETHOD nsBaseComposerCommand::DoCommand ( const char *  aCommandName,
nsISupports *  aCommandRefCon 
) [pure virtual, inherited]
void nsIControllerCommand::doCommand ( in string  aCommandName,
in nsISupports  aCommandContext 
) [inherited]

Execute the name command.

Parameters:
aCommandNamethe name of the command to execute.
aCommandContexta cookie held by the nsIControllerCommandTable, allowing the command to get some context information. The contents of this cookie are implementation-defined.
void nsIControllerCommand::doCommandParams ( in string  aCommandName,
in nsICommandParams  aParams,
in nsISupports  aCommandContext 
) [inherited]
void nsIControllerCommand::getCommandStateParams ( in string  aCommandName,
in nsICommandParams  aParams,
in nsISupports  aCommandContext 
) [inherited]
nsresult nsStyleUpdatingCommand::GetCurrentState ( nsIEditor aEditor,
const char *  aTagName,
nsICommandParams aParams 
) [protected, virtual]

Implements nsBaseStateUpdatingCommand.

Definition at line 213 of file nsComposerCommands.cpp.

{
  NS_ASSERTION(aEditor, "Need editor here");
  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
  if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
  
  nsresult rv = NS_OK;

  PRBool firstOfSelectionHasProp = PR_FALSE;
  PRBool anyOfSelectionHasProp = PR_FALSE;
  PRBool allOfSelectionHasProp = PR_FALSE;

  nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(aTagName);
  rv = htmlEditor->GetInlineProperty(styleAtom, EmptyString(), 
                                     EmptyString(), 
                                     &firstOfSelectionHasProp, 
                                     &anyOfSelectionHasProp, 
                                     &allOfSelectionHasProp);

  aParams->SetBooleanValue(STATE_ENABLED, NS_SUCCEEDED(rv));
  aParams->SetBooleanValue(STATE_ALL, allOfSelectionHasProp);
  aParams->SetBooleanValue(STATE_ANY, anyOfSelectionHasProp);
  aParams->SetBooleanValue(STATE_MIXED, anyOfSelectionHasProp
           && !allOfSelectionHasProp);
  aParams->SetBooleanValue(STATE_BEGIN, firstOfSelectionHasProp);
  aParams->SetBooleanValue(STATE_END, allOfSelectionHasProp);//not completely accurate
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

boolean nsIControllerCommand::isCommandEnabled ( in string  aCommandName,
in nsISupports  aCommandContext 
) [inherited]

Returns true if the command is currently enabled.

An nsIControllerCommand can implement more than one commands; say, a group of related commands (e.g. delete left/delete right). Because of this, the command name is passed to each method.

Parameters:
aCommandNamethe name of the command for which we want the enabled state.
aCommandContexta cookie held by the nsIControllerCommandTable, allowing the command to get some context information. The contents of this cookie are implementation-defined.
NS_DECL_ISUPPORTS NS_IMETHOD nsBaseComposerCommand::IsCommandEnabled ( const char *  aCommandName,
nsISupports *  aCommandRefCon,
PRBool _retval 
) [pure virtual, inherited]
nsresult nsStyleUpdatingCommand::ToggleState ( nsIEditor aEditor,
const char *  aTagName 
) [protected, virtual]

Implements nsBaseStateUpdatingCommand.

Definition at line 245 of file nsComposerCommands.cpp.

{
  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
  if (!htmlEditor)
    return NS_ERROR_NO_INTERFACE;

  //create some params now...
  nsresult rv;
  nsCOMPtr<nsICommandParams> params =
      do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
  if (NS_FAILED(rv) || !params)
    return rv;

  // tags "href" and "name" are special cases in the core editor 
  // they are used to remove named anchor/link and shouldn't be used for insertion
  nsAutoString tagName; tagName.AssignWithConversion(aTagName);
  PRBool doTagRemoval;
  if (tagName.EqualsLiteral("href") ||
      tagName.EqualsLiteral("name"))
    doTagRemoval = PR_TRUE;
  else
  {
    // check current selection; set doTagRemoval if formatting should be removed
    rv = GetCurrentState(aEditor, aTagName, params);
    if (NS_FAILED(rv)) 
      return rv;
    rv = params->GetBooleanValue(STATE_ALL, &doTagRemoval);
    if (NS_FAILED(rv)) 
      return rv;
  }

  if (doTagRemoval)
    rv = RemoveTextProperty(aEditor, tagName.get(), nsnull);
  else
  {
    // Superscript and Subscript styles are mutually exclusive
    nsAutoString removeName; 
    aEditor->BeginTransaction();

    if (tagName.EqualsLiteral("sub"))
    {
      removeName.AssignLiteral("sup");
      rv = RemoveTextProperty(aEditor,tagName.get(), nsnull);
    } 
    else if (tagName.EqualsLiteral("sup"))
    {
      removeName.AssignLiteral("sub");
      rv = RemoveTextProperty(aEditor, tagName.get(), nsnull);
    }
    if (NS_SUCCEEDED(rv))
      rv = SetTextProperty(aEditor,tagName.get(), nsnull, nsnull);

    aEditor->EndTransaction();
  }

  return rv;
}

Here is the call graph for this function:


Member Data Documentation

const char* nsBaseStateUpdatingCommand::mTagName [protected, inherited]

Definition at line 104 of file nsComposerCommands.h.


The documentation for this class was generated from the following files: