Back to index

lightning-sunbird  0.9+nobinonly
nsTreeContentView.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 Jan Varga.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Brian Ryner <bryner@brianryner.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsTreeContentView_h__
00039 #define nsTreeContentView_h__
00040 
00041 #include "nsFixedSizeAllocator.h"
00042 #include "nsVoidArray.h"
00043 #include "nsIDocument.h"
00044 #include "nsStubDocumentObserver.h"
00045 #include "nsITreeBoxObject.h"
00046 #include "nsITreeColumns.h"
00047 #include "nsITreeView.h"
00048 #include "nsITreeContentView.h"
00049 #include "nsITreeSelection.h"
00050 
00051 nsresult NS_NewTreeContentView(nsITreeContentView** aResult);
00052 
00053 class nsTreeContentView : public nsINativeTreeView,
00054                           public nsITreeContentView,
00055                           public nsStubDocumentObserver
00056 {
00057   public:
00058     nsTreeContentView(void);
00059 
00060     ~nsTreeContentView(void);
00061 
00062     friend nsresult NS_NewTreeContentView(nsITreeContentView** aResult);
00063 
00064     NS_DECL_ISUPPORTS
00065 
00066     NS_DECL_NSITREEVIEW
00067     // nsINativeTreeView: Untrusted code can use us
00068     NS_IMETHOD EnsureNative() { return NS_OK; }
00069 
00070     NS_DECL_NSITREECONTENTVIEW
00071 
00072     // nsIDocumentObserver
00073     virtual void ContentStatesChanged(nsIDocument* aDocument,
00074                                       nsIContent* aContent1,
00075                                       nsIContent* aContent2,
00076                                       PRInt32 aStateMask);
00077     virtual void AttributeChanged(nsIDocument *aDocument, nsIContent* aContent,
00078                                   PRInt32 aNameSpaceID, nsIAtom* aAttribute,
00079                                   PRInt32 aModType);
00080     virtual void ContentAppended(nsIDocument *aDocument,
00081                                  nsIContent* aContainer,
00082                                  PRInt32 aNewIndexInContainer);
00083     virtual void ContentInserted(nsIDocument *aDocument,
00084                                  nsIContent* aContainer,
00085                                  nsIContent* aChild,
00086                                  PRInt32 aIndexInContainer);
00087     virtual void ContentRemoved(nsIDocument *aDocument, nsIContent* aContainer,
00088                                 nsIContent* aChild, PRInt32 aIndexInContainer);
00089     virtual void DocumentWillBeDestroyed(nsIDocument *aDocument);
00090 
00091   protected:
00092     // Recursive methods which deal with serializing of nested content.
00093     void Serialize(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows);
00094 
00095     void SerializeItem(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows);
00096 
00097     void SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows);
00098 
00099     void SerializeOption(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
00100                          nsVoidArray& aRows);
00101 
00102     void SerializeOptGroup(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
00103                            nsVoidArray& aRows);
00104 
00105     void GetIndexInSubtree(nsIContent* aContainer, nsIContent* aContent, PRInt32* aResult);
00106     
00107     // Helper methods which we use to manage our plain array of rows.
00108     PRInt32 EnsureSubtree(PRInt32 aIndex);
00109 
00110     PRInt32 RemoveSubtree(PRInt32 aIndex);
00111 
00112     PRInt32 InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent);
00113 
00114     void InsertRowFor(nsIContent* aParent, nsIContent* aChild);
00115 
00116     PRInt32 RemoveRow(PRInt32 aIndex);
00117 
00118     void ClearRows();
00119     
00120     void OpenContainer(PRInt32 aIndex);
00121 
00122     void CloseContainer(PRInt32 aIndex);
00123 
00124     PRInt32 FindContent(nsIContent* aContent);
00125 
00126     void UpdateSubtreeSizes(PRInt32 aIndex, PRInt32 aCount);
00127 
00128     void UpdateParentIndexes(PRInt32 aIndex, PRInt32 aSkip, PRInt32 aCount);
00129 
00130     // Content helpers.
00131     nsIContent* GetCell(nsIContent* aContainer, nsITreeColumn* aCol);
00132 
00133   private:
00134     nsCOMPtr<nsITreeBoxObject>          mBoxObject;
00135     nsCOMPtr<nsITreeSelection>          mSelection;
00136     nsCOMPtr<nsIContent>                mRoot;
00137     nsIDocument*                        mDocument;      // WEAK
00138     nsFixedSizeAllocator                mAllocator;
00139     nsVoidArray                         mRows;
00140 
00141     PRPackedBool                        mUpdateSelection;
00142 };
00143 
00144 #endif // nsTreeContentView_h__