Back to index

lightning-sunbird  0.9+nobinonly
nsComposerCommandsUpdater.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Simon Fraser   <sfraser@netscape.com>
00025  *   Michael Judge  <mjudge@netscape.com>
00026  *   Charles Manske <cmanske@netscape.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 
00043 
00044 
00045 #ifndef nsComposerCommandsUpdater_h__
00046 #define nsComposerCommandsUpdater_h__
00047 
00048 #include "nsCOMPtr.h"
00049 #include "nsITimer.h"
00050 #include "nsWeakPtr.h"
00051 #include "nsPICommandUpdater.h"
00052 
00053 #include "nsISelectionListener.h"
00054 #include "nsIDocumentStateListener.h"
00055 #include "nsITransactionListener.h"
00056 
00057 class nsIDocShell;
00058 class nsITransactionManager;
00059 
00060 class nsComposerCommandsUpdater : public nsISelectionListener,
00061                                   public nsIDocumentStateListener,
00062                                   public nsITransactionListener,
00063                                   public nsITimerCallback
00064 {
00065 public:
00066 
00067                                   nsComposerCommandsUpdater();
00068   virtual                         ~nsComposerCommandsUpdater();
00069 
00070   // nsISupports
00071   NS_DECL_ISUPPORTS
00072   
00073   // nsISelectionListener
00074   NS_DECL_NSISELECTIONLISTENER
00075   
00076   // nsIDocumentStateListener
00077   NS_DECL_NSIDOCUMENTSTATELISTENER
00078 
00079   // nsITimerCallback interfaces
00080   NS_DECL_NSITIMERCALLBACK
00081 
00084   NS_IMETHOD WillDo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt);
00085   NS_IMETHOD DidDo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult);
00086   NS_IMETHOD WillUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt);
00087   NS_IMETHOD DidUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aUndoResult);
00088   NS_IMETHOD WillRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt);
00089   NS_IMETHOD DidRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult);
00090   NS_IMETHOD WillBeginBatch(nsITransactionManager *aManager, PRBool *aInterrupt);
00091   NS_IMETHOD DidBeginBatch(nsITransactionManager *aManager, nsresult aResult);
00092   NS_IMETHOD WillEndBatch(nsITransactionManager *aManager, PRBool *aInterrupt);
00093   NS_IMETHOD DidEndBatch(nsITransactionManager *aManager, nsresult aResult);
00094   NS_IMETHOD WillMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction,
00095                        nsITransaction *aTransactionToMerge, PRBool *aInterrupt);
00096   NS_IMETHOD DidMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction,
00097                       nsITransaction *aTransactionToMerge,
00098                       PRBool aDidMerge, nsresult aMergeResult);
00099 
00100 
00101   nsresult   Init(nsIDOMWindow* aDOMWindow);
00102 
00103 protected:
00104 
00105   enum {
00106     eStateUninitialized   = -1,
00107     eStateOff             = PR_FALSE,
00108     eStateOn              = PR_TRUE
00109   };
00110   
00111   PRBool        SelectionIsCollapsed();
00112   nsresult      UpdateDirtyState(PRBool aNowDirty);  
00113   nsresult      UpdateOneCommand(const char* aCommand);
00114   nsresult      UpdateCommandGroup(const nsAString& aCommandGroup);
00115 
00116   already_AddRefed<nsPICommandUpdater> GetCommandUpdater();
00117   
00118   nsresult      PrimeUpdateTimer();
00119   void          TimerCallback();
00120   nsCOMPtr<nsITimer>  mUpdateTimer;
00121 
00122   nsIDOMWindow* mDOMWindow;  // Weak reference
00123   nsWeakPtr     mDocShell;
00124   PRInt8        mDirtyState;  
00125   PRInt8        mSelectionCollapsed;  
00126   PRPackedBool  mFirstDoOfFirstUndo;
00127     
00128 
00129 };
00130 
00131 extern "C" nsresult NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult);
00132 
00133 
00134 #endif // nsComposerCommandsUpdater_h__