Back to index

lightning-sunbird  0.9+nobinonly
nsBaseWidget.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 the GNU General Public License Version 2 or later (the "GPL"), or
00026  * 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 #ifndef nsBaseWidget_h__
00038 #define nsBaseWidget_h__
00039 
00040 #include "nsRect.h"
00041 #include "nsIWidget.h"
00042 #include "nsIMouseListener.h"
00043 #include "nsIEventListener.h"
00044 #include "nsIMenuListener.h"
00045 #include "nsIToolkit.h"
00046 #include "nsIAppShell.h"
00047 #include "nsILocalFile.h"
00048 #include "nsString.h"
00049 #include "nsVoidArray.h"
00050 #include "nsCOMPtr.h"
00051 #include "nsGUIEvent.h"
00052 
00062 class nsBaseWidget : public nsIWidget
00063 {
00064 
00065 public:
00066   nsBaseWidget();
00067   virtual ~nsBaseWidget();
00068   
00069   NS_DECL_ISUPPORTS
00070   
00071   NS_IMETHOD              PreCreateWidget(nsWidgetInitData *aWidgetInitData) { return NS_OK;}
00072   
00073   // nsIWidget interface
00074   NS_IMETHOD              CaptureMouse(PRBool aCapture);
00075   NS_IMETHOD              Validate();
00076   NS_IMETHOD              InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
00077   NS_IMETHOD              GetClientData(void*& aClientData);
00078   NS_IMETHOD              SetClientData(void* aClientData);
00079   NS_IMETHOD              Destroy();
00080   NS_IMETHOD              SetParent(nsIWidget* aNewParent);
00081   virtual nsIWidget*      GetParent(void);
00082   virtual void            AddChild(nsIWidget* aChild);
00083   virtual void            RemoveChild(nsIWidget* aChild);
00084 
00085   NS_IMETHOD              SetZIndex(PRInt32 aZIndex);
00086   NS_IMETHOD              GetZIndex(PRInt32* aZIndex);
00087   NS_IMETHOD              PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
00088                                       nsIWidget *aWidget, PRBool aActivate);
00089 
00090   NS_IMETHOD              SetSizeMode(PRInt32 aMode);
00091   NS_IMETHOD              GetSizeMode(PRInt32* aMode);
00092 
00093   virtual nscolor         GetForegroundColor(void);
00094   NS_IMETHOD              SetForegroundColor(const nscolor &aColor);
00095   virtual nscolor         GetBackgroundColor(void);
00096   NS_IMETHOD              SetBackgroundColor(const nscolor &aColor);
00097   virtual nsCursor        GetCursor();
00098   NS_IMETHOD              SetCursor(nsCursor aCursor);
00099   NS_IMETHOD              SetCursor(imgIContainer* aCursor,
00100                                     PRUint32 aHotspotX, PRUint32 aHotspotY);
00101   NS_IMETHOD              GetWindowType(nsWindowType& aWindowType);
00102   NS_IMETHOD              SetWindowType(nsWindowType aWindowType);
00103   NS_IMETHOD              SetWindowTranslucency(PRBool aTranslucent);
00104   NS_IMETHOD              GetWindowTranslucency(PRBool& aTranslucent);
00105   NS_IMETHOD              UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas);
00106   NS_IMETHOD              HideWindowChrome(PRBool aShouldHide);
00107   NS_IMETHOD              MakeFullScreen(PRBool aFullScreen);
00108   nsresult                MakeFullScreenInternal(PRBool aFullScreen);
00109   virtual nsIRenderingContext* GetRenderingContext();
00110   virtual nsIDeviceContext* GetDeviceContext();
00111   virtual nsIAppShell *   GetAppShell();
00112   virtual nsIToolkit*     GetToolkit();  
00113   NS_IMETHOD              SetModal(PRBool aModal); 
00114   NS_IMETHOD              ModalEventFilter(PRBool aRealEvent, void *aEvent,
00115                             PRBool *aForWindow);
00116   NS_IMETHOD              GetWindowClass(char *aClass);
00117   NS_IMETHOD              SetWindowClass(char *aClass);
00118   NS_IMETHOD              SetBorderStyle(nsBorderStyle aBorderStyle); 
00119   NS_IMETHOD              AddMouseListener(nsIMouseListener * aListener);
00120   NS_IMETHOD              AddEventListener(nsIEventListener * aListener);
00121   NS_IMETHOD              AddMenuListener(nsIMenuListener * aListener);
00122   NS_IMETHOD              SetBounds(const nsRect &aRect);
00123   NS_IMETHOD              GetBounds(nsRect &aRect);
00124   NS_IMETHOD              GetBoundsAppUnits(nsRect &aRect, float aAppUnits);
00125   NS_IMETHOD              GetClientBounds(nsRect &aRect);
00126   NS_IMETHOD              GetScreenBounds(nsRect &aRect);
00127   NS_IMETHOD              GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight);
00128   NS_IMETHOD              Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect);
00129   NS_IMETHOD              ScrollRect(nsRect &aRect, PRInt32 aDx, PRInt32 aDy);
00130   NS_IMETHOD              ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
00131   NS_IMETHOD              EnableDragDrop(PRBool aEnable);
00132   NS_IMETHOD              GetAttention(PRInt32 aCycleCount);
00133   NS_IMETHOD              GetLastInputEventTime(PRUint32& aTime);
00134   NS_IMETHOD              SetIcon(const nsAString &anIconSpec);
00135   virtual void            ConvertToDeviceCoordinates(nscoord  &aX,nscoord &aY) {}
00136   virtual void            FreeNativeData(void * data, PRUint32 aDataType) {}//~~~
00137 
00138 protected:
00139 
00140   virtual void            ResolveIconName(const nsAString &aIconName,
00141                                           const nsAString &aIconSuffix,
00142                                           nsILocalFile **aResult);
00143   virtual void            DrawScaledRect(nsIRenderingContext& aRenderingContext,
00144                                          const nsRect & aRect,
00145                                          float aScale,
00146                                          float aAppUnits);
00147   virtual void            DrawScaledLine(nsIRenderingContext& aRenderingContext, 
00148                                          nscoord aSX, nscoord aSY, nscoord aEX, nscoord aEY, 
00149                                          float   aScale, float aAppUnits, PRBool aIsHorz);
00150   virtual void            OnDestroy();
00151   virtual void            BaseCreate(nsIWidget *aParent,
00152                                      const nsRect &aRect,
00153                                      EVENT_CALLBACK aHandleEventFunction,
00154                                      nsIDeviceContext *aContext,
00155                                      nsIAppShell *aAppShell,
00156                                      nsIToolkit *aToolkit,
00157                                      nsWidgetInitData *aInitData);
00158 
00159 protected: 
00160   void*             mClientData;
00161   EVENT_CALLBACK    mEventCallback;
00162   nsIDeviceContext  *mContext;
00163   nsCOMPtr<nsIAppShell> mAppShell;
00164   nsIToolkit        *mToolkit;
00165   nsIMouseListener  *mMouseListener;
00166   nsIEventListener  *mEventListener;
00167   nsIMenuListener   *mMenuListener;
00168   nscolor           mBackground;
00169   nscolor           mForeground;
00170   nsCursor          mCursor;
00171   nsWindowType      mWindowType;
00172   nsBorderStyle     mBorderStyle;
00173   PRPackedBool      mIsShiftDown;
00174   PRPackedBool      mIsControlDown;
00175   PRPackedBool      mIsAltDown;
00176   PRPackedBool      mIsDestroying;
00177   PRPackedBool      mOnDestroyCalled;
00178   nsRect            mBounds;
00179   nsRect*           mOriginalBounds;
00180   PRInt32           mZIndex;
00181   nsSizeMode        mSizeMode;
00182     
00183     // Enumeration of the methods which are accessable on the "main GUI thread"
00184     // via the CallMethod(...) mechanism...
00185     // see nsSwitchToUIThread
00186   enum {
00187     CREATE       = 0x0101,
00188     CREATE_NATIVE,
00189     DESTROY, 
00190     SET_FOCUS,
00191     SET_CURSOR,
00192     CREATE_HACK
00193   };
00194 
00195 #ifdef DEBUG
00196 protected:
00197   static nsAutoString debug_GuiEventToString(nsGUIEvent * aGuiEvent);
00198   static PRBool debug_WantPaintFlashing();
00199 
00200   static void debug_DumpInvalidate(FILE *                aFileOut,
00201                                    nsIWidget *           aWidget,
00202                                    const nsRect *        aRect,
00203                                    PRBool                aIsSynchronous,
00204                                    const nsCAutoString & aWidgetName,
00205                                    PRInt32               aWindowID);
00206 
00207   static void debug_DumpEvent(FILE *                aFileOut,
00208                               nsIWidget *           aWidget,
00209                               nsGUIEvent *          aGuiEvent,
00210                               const nsCAutoString & aWidgetName,
00211                               PRInt32               aWindowID);
00212   
00213   static void debug_DumpPaintEvent(FILE *                aFileOut,
00214                                    nsIWidget *           aWidget,
00215                                    nsPaintEvent *        aPaintEvent,
00216                                    const nsCAutoString & aWidgetName,
00217                                    PRInt32               aWindowID);
00218 
00219   static PRBool debug_GetCachedBoolPref(const char* aPrefName);
00220 #endif
00221 };
00222 
00223 #endif // nsBaseWidget_h__