Back to index

lightning-sunbird  0.9+nobinonly
nsView.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  *
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 nsView_h___
00039 #define nsView_h___
00040 
00041 #include "nsIView.h"
00042 #include "nsIWidget.h"
00043 #include "nsRegion.h"
00044 #include "nsRect.h"
00045 #include "nsCRT.h"
00046 #include "nsIFactory.h"
00047 #include "nsIViewObserver.h"
00048 #include "nsEvent.h"
00049 #include <stdio.h>
00050 
00051 //mmptemp
00052 
00053 class nsIRegion;
00054 class nsIRenderingContext;
00055 class nsIViewManager;
00056 class nsViewManager;
00057 class nsZPlaceholderView;
00058 
00059 // View flags private to the view module
00060 
00061 // indicates that the view is or contains a placeholder view
00062 #define NS_VIEW_FLAG_CONTAINS_PLACEHOLDER 0x0100
00063 
00064 // Flag to determine whether the view will check if events can be handled
00065 // by its children or just handle the events itself
00066 #define NS_VIEW_FLAG_DONT_CHECK_CHILDREN  0x0200
00067 
00068 // indicates that the view should not be bitblt'd when moved
00069 // or scrolled and instead must be repainted
00070 #define NS_VIEW_FLAG_DONT_BITBLT          0x0400
00071 
00072 // set if this view is clipping its normal descendants
00073 // to its bounds. When this flag is set, child views
00074 // bounds need not be inside this view's bounds.
00075 #define NS_VIEW_FLAG_CLIP_CHILDREN_TO_BOUNDS      0x0800
00076 
00077 // set if this view is clipping its descendants (including
00078 // placeholders) to its bounds
00079 #define NS_VIEW_FLAG_CLIP_PLACEHOLDERS_TO_BOUNDS  0x1000
00080 
00081 // set if this view has positioned its widget at least once
00082 #define NS_VIEW_FLAG_HAS_POSITIONED_WIDGET 0x2000
00083 
00084 class nsView : public nsIView_MOZILLA_1_8_BRANCH
00085 {
00086 public:
00087   nsView(nsViewManager* aViewManager = nsnull,
00088          nsViewVisibility aVisibility = nsViewVisibility_kShow);
00089 
00090   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00091 
00092   NS_IMETHOD  QueryInterface(const nsIID& aIID, void** aInstancePtr);
00093 
00103   NS_IMETHOD  Paint(nsIRenderingContext& rc, const nsRect& rect,
00104                     PRUint32 aPaintFlags, PRBool &aResult);
00114   NS_IMETHOD  Paint(nsIRenderingContext& rc, const nsIRegion& region,
00115                     PRUint32 aPaintFlags, PRBool &aResult);
00116 
00123   virtual void SetPosition(nscoord aX, nscoord aY);
00129   virtual void SetDimensions(const nsRect &aRect, PRBool aPaint = PR_TRUE,
00130                              PRBool aResizeWidget = PR_TRUE);
00131   void GetDimensions(nsRect &aRect) const { aRect = mDimBounds; aRect.x -= mPosX; aRect.y -= mPosY; }
00132   void GetDimensions(nsSize &aSize) const { aSize.width = mDimBounds.width; aSize.height = mDimBounds.height; }
00133 
00138   virtual PRBool IsZPlaceholderView() const { return PR_FALSE; }
00139 
00146   void SetClipChildrenToRect(const nsRect* aRect) {
00147     if (!aRect) {
00148       delete mClipRect;
00149       mClipRect = nsnull;
00150     } else {
00151       if (mClipRect) {
00152         *mClipRect = *aRect;
00153       } else {
00154         mClipRect = new nsRect(*aRect);
00155       }
00156     }
00157   }
00158   void SetClipChildrenToBounds(PRBool aDoClip) {
00159     mVFlags = (mVFlags & ~NS_VIEW_FLAG_CLIP_CHILDREN_TO_BOUNDS)
00160       | (aDoClip ? NS_VIEW_FLAG_CLIP_CHILDREN_TO_BOUNDS : 0);
00161   }
00162   void SetClipPlaceholdersToBounds(PRBool aDoClip) {
00163     mVFlags = (mVFlags & ~NS_VIEW_FLAG_CLIP_PLACEHOLDERS_TO_BOUNDS)
00164       | (aDoClip ? NS_VIEW_FLAG_CLIP_PLACEHOLDERS_TO_BOUNDS : 0);
00165   }
00166 
00170   const nsRect* GetClipChildrenToRect() const
00171   { return mClipRect; }
00172   PRBool GetClipChildrenToBounds(PRBool aPlaceholders) const
00173   { return (mVFlags & (aPlaceholders ? NS_VIEW_FLAG_CLIP_PLACEHOLDERS_TO_BOUNDS : NS_VIEW_FLAG_CLIP_CHILDREN_TO_BOUNDS)) != 0; }
00174 
00180   NS_IMETHOD  SetVisibility(nsViewVisibility visibility);
00181 
00191   void SetZIndex(PRBool aAuto, PRInt32 aZIndex, PRBool aTopMost);
00192 
00201   NS_IMETHOD  SetFloating(PRBool aFloatingView);
00208   NS_IMETHOD  SetOpacity(float opacity);
00214   NS_IMETHOD  SetContentTransparency(PRBool aTransparent);
00224   NS_IMETHOD  SetWidget(nsIWidget *aWidget);
00225 
00232   nsRect GetClippedRect(nsIView* aStopAtView = nsnull);
00233 
00234   // Helper function to get the view that's associated with a widget
00235   static nsView* GetViewFor(nsIWidget* aWidget) {
00236     return NS_STATIC_CAST(nsView*, nsIView::GetViewFor(aWidget));
00237   }
00238 
00239   // Helper function to get mouse grabbing off this view (by moving it to the
00240   // parent, if we can)
00241   void DropMouseGrabbing();
00242 
00243 public:
00244   // NOT in nsIView, so only available in view module
00245   nsZPlaceholderView* GetZParent() const { return mZParent; }
00246   // These are also present in nsIView, but these versions return nsView and nsViewManager
00247   // instead of nsIView and nsIViewManager.
00248   nsView* GetFirstChild() const { return mFirstChild; }
00249   nsView* GetNextSibling() const { return mNextSibling; }
00250   nsView* GetParent() const { return mParent; }
00251   nsViewManager* GetViewManager() const { return mViewManager; }
00252   // These are superceded by a better interface in nsIView
00253   PRInt32 GetZIndex() const { return mZIndex; }
00254   PRBool GetZIndexIsAuto() const { return (mVFlags & NS_VIEW_FLAG_AUTO_ZINDEX) != 0; }
00255   // This is a better interface than GetDimensions(nsRect&) above
00256   nsRect GetDimensions() const { nsRect r = mDimBounds; r.MoveBy(-mPosX, -mPosY); return r; }
00257   // These are defined exactly the same in nsIView, but for now they have to be redeclared
00258   // here because of stupid C++ method hiding rules
00259 
00260   PRBool HasNonEmptyDirtyRegion() {
00261     return mDirtyRegion && !mDirtyRegion->IsEmpty();
00262   }
00263   nsRegion* GetDirtyRegion() {
00264     if (!mDirtyRegion) {
00265       mDirtyRegion = new nsRegion();
00266       NS_ASSERTION(mDirtyRegion, "Out of memory!");
00267     }
00268     return mDirtyRegion;
00269   }
00270 
00271   void InsertChild(nsView *aChild, nsView *aSibling);
00272   void RemoveChild(nsView *aChild);
00273 
00274   void SetParent(nsView *aParent) { mParent = aParent; }
00275   void SetZParent(nsZPlaceholderView *aZParent) { mZParent = aZParent; }
00276   void SetNextSibling(nsView *aSibling) { mNextSibling = aSibling; }
00277 
00278   PRUint32 GetViewFlags() const { return mVFlags; }
00279   void SetViewFlags(PRUint32 aFlags) { mVFlags = aFlags; }
00280 
00281   void SetTopMost(PRBool aTopMost) { aTopMost ? mVFlags |= NS_VIEW_FLAG_TOPMOST : mVFlags &= ~NS_VIEW_FLAG_TOPMOST; }
00282   PRBool IsTopMost() { return((mVFlags & NS_VIEW_FLAG_TOPMOST) != 0); }
00283 
00284   // Don't use this method when you want to adjust an nsPoint.
00285   // Just write "pt += view->GetPosition();"
00286   // When everything's converted to nsPoint, this can go away.
00287   void ConvertToParentCoords(nscoord* aX, nscoord* aY) const { *aX += mPosX; *aY += mPosY; }
00288   // Don't use this method when you want to adjust an nsPoint.
00289   // Just write "pt -= view->GetPosition();"
00290   // When everything's converted to nsPoint, this can go away.
00291   void ConvertFromParentCoords(nscoord* aX, nscoord* aY) const { *aX -= mPosX; *aY -= mPosY; }
00292   void ResetWidgetBounds(PRBool aRecurse, PRBool aMoveOnly, PRBool aInvalidateChangedSize);
00293   void SetPositionIgnoringChildWidgets(nscoord aX, nscoord aY);
00294   nsresult LoadWidget(const nsCID &aClassIID);
00295 
00296   // Update the cached RootViewManager for all view manager descendents,
00297   // If the hierarchy is being removed, aViewManagerParent points to the view
00298   // manager for the hierarchy's old parent, and will have its mouse grab
00299   // released if it points to any view in this view hierarchy.
00300   void InvalidateHierarchy(nsViewManager *aViewManagerParent);
00301 
00302   virtual ~nsView();
00303 
00304 protected:
00305   // Do the actual work of ResetWidgetBounds, unconditionally.  Don't
00306   // call this method if we have no widget.
00307   void DoResetWidgetBounds(PRBool aMoveOnly, PRBool aInvalidateChangedSize);
00308   
00309   nsZPlaceholderView* mZParent;
00310 
00311   // mClipRect is relative to the view's origin.
00312   nsRect*      mClipRect;
00313   nsRegion*    mDirtyRegion;
00314   PRPackedBool mChildRemoved;
00315 };
00316 
00317 #endif