Back to index

lightning-sunbird  0.9+nobinonly
nsPlaintextEditor.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Daniel Glazman <glazman@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsPlaintextEditor_h__
00040 #define nsPlaintextEditor_h__
00041 
00042 #include "nsCOMPtr.h"
00043 
00044 #include "nsIPlaintextEditor.h"
00045 #include "nsIEditorMailSupport.h"
00046 
00047 #include "nsEditor.h"
00048 #include "nsIDOMElement.h"
00049 #include "nsIDOMEventListener.h"
00050 
00051 #include "nsEditRules.h"
00052  
00053 class nsITransferable;
00054 class nsIDOMEventReceiver;
00055 class nsIDocumentEncoder;
00056 
00061 class nsPlaintextEditor : public nsEditor,
00062                           public nsIPlaintextEditor,
00063                           public nsIEditorMailSupport
00064 {
00065 
00066 public:
00067 
00068 // Interfaces for addref and release and queryinterface
00069 // NOTE macro used is for classes that inherit from 
00070 // another class. Only the base class should use NS_DECL_ISUPPORTS
00071   NS_DECL_ISUPPORTS_INHERITED
00072 
00073   /* below used by TypedText() */
00074   enum {
00075     eTypedText,  /* user typed text */
00076     eTypedBR,    /* user typed shift-enter to get a br */
00077     eTypedBreak  /* user typed enter */
00078   };
00079 
00080            nsPlaintextEditor();
00081   virtual  ~nsPlaintextEditor();
00082 
00083   /* ------------ nsIPlaintextEditor methods -------------- */
00084   NS_DECL_NSIPLAINTEXTEDITOR
00085 
00086   /* ------------ nsIEditorMailSupport overrides -------------- */
00087   NS_DECL_NSIEDITORMAILSUPPORT
00088 
00089   /* ------------ nsIEditorIMESupport overrides -------------- */
00090   
00091   NS_IMETHOD SetCompositionString(const nsAString & aCompositionString, nsIPrivateTextRangeList * aTextRange, nsTextEventReply * aReply);
00092   NS_IMETHOD GetReconversionString(nsReconversionEventReply* aReply);
00093 
00094   /* ------------ Overrides of nsEditor interface methods -------------- */
00095   NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
00096   NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
00097                                       const nsAString & aAttribute,
00098                                       const nsAString & aValue,
00099                                       PRBool aSuppressTransaction);
00100   NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
00101                                          const nsAString & aAttribute,
00102                                          PRBool aSuppressTransaction);
00103 
00105   NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell,  nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);
00106   
00107   NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
00108   NS_IMETHOD GetIsDocumentEditable(PRBool *aIsDocumentEditable);
00109 
00110   NS_IMETHOD DeleteSelection(EDirection aAction);
00111 
00112   NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
00113 
00114   NS_IMETHOD GetFlags(PRUint32 *aFlags);
00115   NS_IMETHOD SetFlags(PRUint32 aFlags);
00116 
00117   NS_IMETHOD Undo(PRUint32 aCount);
00118   NS_IMETHOD Redo(PRUint32 aCount);
00119 
00120   NS_IMETHOD Cut();
00121   NS_IMETHOD CanCut(PRBool *aCanCut);
00122   NS_IMETHOD Copy();
00123   NS_IMETHOD CanCopy(PRBool *aCanCopy);
00124   NS_IMETHOD Paste(PRInt32 aSelectionType);
00125   NS_IMETHOD CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste);
00126 
00127   NS_IMETHOD CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDrag);
00128   NS_IMETHOD DoDrag(nsIDOMEvent *aDragEvent);
00129   NS_IMETHOD InsertFromDrop(nsIDOMEvent* aDropEvent);
00130 
00131   NS_IMETHOD OutputToString(const nsAString& aFormatType,
00132                             PRUint32 aFlags,
00133                             nsAString& aOutputString);
00134                             
00135   NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
00136                             const nsAString& aFormatType,
00137                             const nsACString& aCharsetOverride,
00138                             PRUint32 aFlags);
00139 
00140 
00143   NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
00144 
00147   NS_IMETHOD EndOperation();
00148 
00150   NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
00151 
00152   /* ------------ Utility Routines, not part of public API -------------- */
00153   NS_IMETHOD TypedText(const nsAString& aString, PRInt32 aAction);
00154 
00159   nsresult GetTextSelectionOffsets(nsISelection *aSelection,
00160                                    PRUint32 &aStartOffset, 
00161                                    PRUint32 &aEndOffset);
00162 
00163   nsresult InsertTextAt(const nsAString &aStringToInsert,
00164                         nsIDOMNode *aDestinationNode,
00165                         PRInt32 aDestOffset,
00166                         PRBool aDoDeleteSelection);
00167 
00168 protected:
00169 
00170   NS_IMETHOD  InitRules();
00171   void        BeginEditorInit();
00172   nsresult    EndEditorInit();
00173 
00174   // Create the event listeners for the editor to install.
00175   virtual nsresult CreateEventListeners();
00176 
00183   NS_IMETHOD GetLayoutObject(nsIDOMNode *aInNode, nsISupports **aOutLayoutObject);
00184   // Helpers for output routines
00185   NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
00186                                   PRUint32 aFlags,
00187                                   const nsACString& aCharset,
00188                                   nsIDocumentEncoder** encoder);
00189 
00190   // key event helpers
00191   NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, 
00192                       nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
00193   NS_IMETHOD CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, 
00194                          PRInt32 *aInOutOffset, 
00195                          nsCOMPtr<nsIDOMNode> *outBRNode, 
00196                          EDirection aSelect);
00197   NS_IMETHOD InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode);
00198 
00199   // factored methods for handling insertion of data from transferables (drag&drop or clipboard)
00200   NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
00201   NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
00202                                         nsIDOMNode *aDestinationNode,
00203                                         PRInt32 aDestOffset,
00204                                         PRBool aDoDeleteSelection);
00205   virtual nsresult SetupDocEncoder(nsIDocumentEncoder **aDocEncoder);
00206   virtual nsresult PutDragDataInTransferable(nsITransferable **aTransferable);
00207 
00209   nsresult SharedOutputString(PRUint32 aFlags, PRBool* aIsCollapsed, nsAString& aResult);
00210 
00211   /* small utility routine to test the eEditorReadonly bit */
00212   PRBool IsModifiable();
00213 
00214   //XXX Kludge: Used to suppress spurious drag/drop events (bug 50703)
00215   PRBool   mIgnoreSpuriousDragEvent;
00216   NS_IMETHOD IgnoreSpuriousDragEvent(PRBool aIgnoreSpuriousDragEvent) {mIgnoreSpuriousDragEvent = aIgnoreSpuriousDragEvent; return NS_OK;}
00217 
00218 // Data members
00219 protected:
00220 
00221   nsCOMPtr<nsIEditRules>        mRules;
00222   PRBool  mWrapToWindow;
00223   PRInt32 mWrapColumn;
00224   PRInt32 mMaxTextLength;
00225   PRInt32 mInitTriggerCounter;
00226 
00227 // friends
00228 friend class nsHTMLEditRules;
00229 friend class nsTextEditRules;
00230 friend class nsAutoEditInitRulesTrigger;
00231 
00232 };
00233 
00234 #endif //nsPlaintextEditor_h__
00235