Back to index

lightning-sunbird  0.9+nobinonly
nsWidget.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  *   Ken Faulkner <faulkner@igelaus.com.au>
00024  *   Quy Tonthat <quy@igelaus.com.au>
00025  *   B.J. Rossiter <bj@igelaus.com.au>
00026  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * 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 #ifndef nsWidget_h__
00043 #define nsWidget_h__
00044 
00045 #include "nsBaseWidget.h"
00046 #include "nsWeakReference.h"
00047 #include "nsHashtable.h"
00048 #include "prlog.h"
00049 #include "nsIRegion.h"
00050 #include "nsIRollupListener.h"
00051 #include "xlibrgb.h"
00052 
00053 #ifdef DEBUG_blizzard
00054 #define XLIB_WIDGET_NOISY
00055 #endif
00056 
00057 class nsWidget : public nsBaseWidget, public nsSupportsWeakReference
00058 {
00059 public:
00060   nsWidget();
00061   virtual ~nsWidget();
00062 
00063   NS_DECL_ISUPPORTS_INHERITED
00064 
00065   NS_IMETHOD Create(nsIWidget *aParent,
00066                     const nsRect &aRect,
00067                     EVENT_CALLBACK aHandleEventFunction,
00068                     nsIDeviceContext *aContext,
00069                     nsIAppShell *aAppShell = nsnull,
00070                     nsIToolkit *aToolkit = nsnull,
00071                     nsWidgetInitData *aInitData = nsnull);
00072 
00073   NS_IMETHOD Create(nsNativeWidget aParent,
00074                     const nsRect &aRect,
00075                     EVENT_CALLBACK aHandleEventFunction,
00076                     nsIDeviceContext *aContext,
00077                     nsIAppShell *aAppShell = nsnull,
00078                     nsIToolkit *aToolkit = nsnull,
00079                     nsWidgetInitData *aInitData = nsnull);
00080 
00081   virtual nsresult StandardWidgetCreate(nsIWidget *aParent,
00082                                         const nsRect &aRect,
00083                                         EVENT_CALLBACK aHandleEventFunction,
00084                                         nsIDeviceContext *aContext,
00085                                         nsIAppShell *aAppShell,
00086                                         nsIToolkit *aToolkit,
00087                                         nsWidgetInitData *aInitData,
00088                                         nsNativeWidget aNativeParent = nsnull);
00089   NS_IMETHOD Destroy();
00090   virtual nsIWidget *GetParent(void);
00091   NS_IMETHOD Show(PRBool bState);
00092   NS_IMETHOD IsVisible(PRBool &aState);
00093 
00094   NS_IMETHOD ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY);
00095   NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
00096   NS_IMETHOD Resize(PRInt32 aWidth,
00097                     PRInt32 aHeight,
00098                     PRBool   aRepaint);
00099   NS_IMETHOD Resize(PRInt32 aX,
00100                     PRInt32 aY,
00101                     PRInt32 aWidth,
00102                     PRInt32 aHeight,
00103                     PRBool   aRepaint);
00104 
00105   NS_IMETHOD Enable(PRBool aState);
00106   NS_IMETHOD IsEnabled(PRBool *aState);
00107   NS_IMETHOD              SetFocus(PRBool aRaise = PR_FALSE);
00108   NS_IMETHOD              SetName(const char * aName);
00109   NS_IMETHOD              SetBackgroundColor(const nscolor &aColor);
00110   virtual nsIFontMetrics* GetFont(void);
00111   NS_IMETHOD              SetFont(const nsFont &aFont);
00112   NS_IMETHOD              SetCursor(nsCursor aCursor);
00113   void                    LockCursor(PRBool aLock);
00114 
00115   NS_IMETHOD Invalidate(PRBool aIsSynchronous);
00116   NS_IMETHOD              Invalidate(const nsRect & aRect, PRBool aIsSynchronous);
00117   NS_IMETHOD              Update();
00118   virtual void*           GetNativeData(PRUint32 aDataType);
00119   NS_IMETHOD              SetColorMap(nsColorMap *aColorMap);
00120   NS_IMETHOD              Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
00121   NS_IMETHOD              SetMenuBar(nsIMenuBar * aMenuBar); 
00122   NS_IMETHOD              ShowMenuBar(PRBool aShow);
00123   NS_IMETHOD              SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);   
00124   NS_IMETHOD              RemoveTooltips();
00125   NS_IMETHOD              UpdateTooltips(nsRect* aNewTips[]);
00126   NS_IMETHOD              WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
00127   NS_IMETHOD              ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
00128   NS_IMETHOD              BeginResizingChildren(void);
00129   NS_IMETHOD              EndResizingChildren(void);
00130   NS_IMETHOD              GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
00131   NS_IMETHOD              SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
00132   NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
00133   NS_IMETHOD              PreCreateWidget(nsWidgetInitData *aInitData);
00134   NS_IMETHOD              SetBounds(const nsRect &aRect);
00135   NS_IMETHOD              GetRequestedBounds(nsRect &aRect);
00136 
00137   NS_IMETHOD              CaptureRollupEvents(nsIRollupListener *aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
00138   NS_IMETHOD              SetTitle(const nsAString& title);
00139 #ifdef DEBUG
00140   void                    DebugPrintEvent(nsGUIEvent & aEvent,Window aWindow);
00141 #endif
00142 
00143   virtual PRBool          OnPaint(nsPaintEvent &event);
00144   virtual PRBool          OnResize(nsSizeEvent &event);
00145   virtual PRBool          OnDeleteWindow(void);
00146 
00147   // KenF Added FIXME:
00148   virtual void            OnDestroy(void);
00149   virtual PRBool          DispatchMouseEvent(nsMouseEvent &aEvent);
00150   virtual PRBool          DispatchKeyEvent(nsKeyEvent &aKeyEvent);
00151   virtual PRBool          DispatchDestroyEvent(void);
00152 
00153   static nsWidget        * GetWidgetForWindow(Window aWindow);
00154   void                     SetVisibility(int aState); // using the X constants here
00155   void                     SetIonic(PRBool isIonic);
00156   static Window            GetFocusWindow(void);
00157 
00158   Cursor                   XlibCreateCursor(nsCursor aCursorType);
00159 
00160   PRBool DispatchWindowEvent(nsGUIEvent & aEvent);
00161 
00162   // these are for the wm protocols
00163   static Atom   WMDeleteWindow;
00164   static Atom   WMTakeFocus;
00165   static Atom   WMSaveYourself;
00166   static PRBool WMProtocolsInitialized;
00167 
00168   // Checks if parent is alive. nsWidget has a stub, nsWindow has real
00169   // thing. KenF
00170   void *CheckParent(long ThisWindow);
00171 
00172   // Deal with rollup for popups
00173   PRBool IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY);
00174   PRBool HandlePopup( PRInt32 inMouseX, PRInt32 inMouseY);
00175 
00176   void WidgetShow       (nsWidget *aWidget);
00177 protected:
00178 
00179   nsCOMPtr<nsIRegion> mUpdateArea;
00180   // private event functions
00181   PRBool ConvertStatus(nsEventStatus aStatus);
00182 
00183   // create the native window for this class
00184   virtual void CreateNativeWindow(Window aParent, nsRect aRect,
00185                                   XSetWindowAttributes aAttr, unsigned long aMask);
00186   virtual void CreateNative(Window aParent, nsRect aRect);
00187   virtual void DestroyNative();
00188   static void  DestroyNativeChildren(Display *aDisplay, Window aWindow);
00189   void         Map(void);
00190   void         Unmap(void);
00191 
00192   // Let each sublclass set the event mask according to their needs
00193   virtual long GetEventMask();
00194 
00195   // these will add and delete a window
00196   static void  AddWindowCallback   (Window aWindow, nsWidget *aWidget);
00197   static void  DeleteWindowCallback(Window aWindow);
00198 
00199   // set up our wm hints
00200   void          SetUpWMHints(void);
00201 
00202   // here's how we add children
00203   // there's no geometry information here because that should be in the mBounds
00204   // in the widget
00205   void WidgetPut        (nsWidget *aWidget);
00206   void WidgetMove       (nsWidget *aWidget);
00207   void WidgetMoveResize (nsWidget *aWidget);
00208   void WidgetResize     (nsWidget *aWidget);
00209   // check to see whether or not a rect will intersect with the current scrolled area
00210   PRBool WidgetVisible  (nsRect   &aBounds);
00211 
00212   PRBool         mIsShown;
00213   int            mVisibility; // this is an int because that's the way X likes it
00214   PRUint32       mPreferredWidth;
00215   PRUint32       mPreferredHeight;
00216 
00217   nsIWidget   *  mParentWidget;
00218   Window         mParentWindow;
00219 
00220   // All widgets have at least these items.
00221   XlibRgbHandle *mXlibRgbHandle;
00222   Display *      mDisplay;
00223   Screen *       mScreen;
00224   Window         mBaseWindow;
00225   Visual *       mVisual;
00226   int            mDepth;
00227   unsigned long  mBackgroundPixel;
00228   PRUint32       mBorderRGB;
00229   unsigned long  mBorderPixel;
00230   nsString       mName;           // name of the type of widget
00231   nsRect         mRequestedSize;
00232   PRPackedBool   mIsToplevel;
00233   PRPackedBool   mMapped;
00234   PRPackedBool   mLastGrabFailed;
00235 
00236   static Window  mFocusWindow;
00237 
00238   // Changed to protected so nsWindow has access to it. KenF
00239 protected:
00240   PRBool       mListenForResizes;     // If we're native we want to listen.
00241   static       nsHashtable *          gsWindowList;
00242   static       Cursor                 gsXlibCursorCache[eCursorCount];
00243 
00244   // Variables for infomation about the current popup window and its listener
00245   static nsCOMPtr<nsIRollupListener> gRollupListener;
00246   static nsWeakPtr                   gRollupWidget;
00247   static PRBool                      gRollupConsumeRollupEvent;
00248 };
00249 
00250 extern PRLogModuleInfo *XlibWidgetsLM;
00251 extern PRLogModuleInfo *XlibScrollingLM;
00252 
00253 #endif /* !nsWidget_h__ */
00254 
00255 
00256