Back to index

lightning-sunbird  0.9+nobinonly
nsWindow.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 Window_h__
00038 #define Window_h__
00039 
00040 #include "nsISupports.h"
00041 #include "nsIPluginWidget.h"
00042 #include "nsBaseWidget.h"
00043 #include "nsDeleteObserver.h"
00044 
00045 #include "nsIWidget.h"
00046 #include "nsIKBStateControl.h"
00047 #include "nsIAppShell.h"
00048 
00049 #include "nsIMouseListener.h"
00050 #include "nsIEventListener.h"
00051 #include "nsString.h"
00052 
00053 #include "nsIMenuBar.h"
00054 
00055 #include "nsplugindefs.h"
00056 #include <Quickdraw.h>
00057 
00058 #define NSRGB_2_COLOREF(color) \
00059             RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
00060 
00061 struct nsPluginPort;
00062 struct TRectArray;
00063 
00064 
00065 class CursorSpinner {
00066 public:
00067     CursorSpinner();
00068     ~CursorSpinner();
00069     void StartSpinCursor();
00070     void StopSpinCursor();    
00071 
00072 private:
00073     short                mSpinCursorFrame;
00074     EventLoopTimerUPP    mTimerUPP;
00075     EventLoopTimerRef    mTimerRef;
00076     
00077     short                GetNextCursorFrame();
00078     static pascal void   SpinCursor(EventLoopTimerRef inTimer, void *inUserData);
00079 };
00080 
00081 //-------------------------------------------------------------------------
00082 //
00083 // nsWindow
00084 //
00085 //-------------------------------------------------------------------------
00086 
00087 class nsWindow :    public nsBaseWidget,
00088                     public nsDeleteObserved,
00089                     public nsIKBStateControl,
00090                     public nsIPluginWidget
00091 {
00092 private:
00093   typedef nsBaseWidget Inherited;
00094 
00095 public:
00096                             nsWindow();
00097     virtual                 ~nsWindow();
00098     
00099     NS_DECL_ISUPPORTS_INHERITED
00100     
00101     // nsIWidget interface
00102     NS_IMETHOD              Create(nsIWidget *aParent,
00103                                    const nsRect &aRect,
00104                                    EVENT_CALLBACK aHandleEventFunction,
00105                                    nsIDeviceContext *aContext,
00106                                    nsIAppShell *aAppShell = nsnull,
00107                                    nsIToolkit *aToolkit = nsnull,
00108                                    nsWidgetInitData *aInitData = nsnull);
00109     NS_IMETHOD              Create(nsNativeWidget aNativeParent,
00110                                    const nsRect &aRect,
00111                                    EVENT_CALLBACK aHandleEventFunction,
00112                                    nsIDeviceContext *aContext,
00113                                    nsIAppShell *aAppShell = nsnull,
00114                                    nsIToolkit *aToolkit = nsnull,
00115                                    nsWidgetInitData *aInitData = nsnull);
00116 
00117      // Utility method for implementing both Create(nsIWidget ...) and
00118      // Create(nsNativeWidget...)
00119 
00120     virtual nsresult        StandardCreate(nsIWidget *aParent,
00121                                 const nsRect &aRect,
00122                                 EVENT_CALLBACK aHandleEventFunction,
00123                                 nsIDeviceContext *aContext,
00124                                 nsIAppShell *aAppShell,
00125                                 nsIToolkit *aToolkit,
00126                                 nsWidgetInitData *aInitData,
00127                                 nsNativeWidget aNativeParent = nsnull);
00128 
00129     NS_IMETHOD              Destroy();
00130     virtual nsIWidget*      GetParent(void);
00131 
00132     NS_IMETHOD              Show(PRBool aState);
00133     NS_IMETHOD              IsVisible(PRBool & aState);
00134 
00135     NS_IMETHOD              ModalEventFilter(PRBool aRealEvent, void *aEvent,
00136                                              PRBool *aForWindow);
00137 
00138     NS_IMETHOD                  ConstrainPosition(PRBool aAllowSlop,
00139                                                   PRInt32 *aX, PRInt32 *aY);
00140     NS_IMETHOD              Move(PRInt32 aX, PRInt32 aY);
00141     NS_IMETHOD              Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
00142     NS_IMETHOD              Resize(PRInt32 aX, PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
00143 
00144     NS_IMETHOD              Enable(PRBool aState);
00145     NS_IMETHOD              IsEnabled(PRBool *aState);
00146     NS_IMETHOD              SetFocus(PRBool aRaise);
00147     NS_IMETHOD              SetBounds(const nsRect &aRect);
00148     NS_IMETHOD              GetBounds(nsRect &aRect);
00149 
00150     virtual nsIFontMetrics* GetFont(void);
00151     NS_IMETHOD              SetFont(const nsFont &aFont);
00152     NS_IMETHOD              Validate();
00153     NS_IMETHOD              Invalidate(PRBool aIsSynchronous);
00154     NS_IMETHOD              Invalidate(const nsRect &aRect,PRBool aIsSynchronous);
00155     NS_IMETHOD              InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
00156 
00157     virtual void*           GetNativeData(PRUint32 aDataType);
00158     NS_IMETHOD              SetColorMap(nsColorMap *aColorMap);
00159     NS_IMETHOD              Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
00160     NS_IMETHOD              WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
00161     NS_IMETHOD              ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
00162     NS_IMETHOD              BeginResizingChildren(void);
00163     NS_IMETHOD              EndResizingChildren(void);
00164 
00165     static  PRBool          ConvertStatus(nsEventStatus aStatus);
00166     NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
00167     virtual PRBool          DispatchMouseEvent(nsMouseEvent &aEvent);
00168 
00169     virtual void          StartDraw(nsIRenderingContext* aRenderingContext = nsnull);
00170     virtual void          EndDraw();
00171     PRBool                IsDrawing() const { return mDrawing; }
00172     
00173     NS_IMETHOD            Update();
00174     virtual void          UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext);
00175     
00176     virtual void          ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY);
00177     void                  LocalToWindowCoordinate(nsPoint& aPoint)            { ConvertToDeviceCoordinates(aPoint.x, aPoint.y); }
00178     void                  LocalToWindowCoordinate(nscoord& aX, nscoord& aY)       { ConvertToDeviceCoordinates(aX, aY); }
00179     void                  LocalToWindowCoordinate(nsRect& aRect)              { ConvertToDeviceCoordinates(aRect.x, aRect.y); }
00180 
00181     NS_IMETHOD            SetMenuBar(nsIMenuBar * aMenuBar);
00182     NS_IMETHOD            ShowMenuBar(PRBool aShow);
00183     virtual nsIMenuBar*   GetMenuBar();
00184     NS_IMETHOD        GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
00185     NS_IMETHOD        SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
00186     
00187     NS_IMETHOD        SetCursor(nsCursor aCursor);
00188     static void       SetCursorResource(short aCursorResourceNum);
00189 
00190     NS_IMETHOD        CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
00191     NS_IMETHOD        SetTitle(const nsAString& title);
00192   
00193     NS_IMETHOD        GetAttention(PRInt32 aCycleCount);
00194 
00195     // Mac specific methods
00196     static void         nsRectToMacRect(const nsRect& aRect, Rect& aMacRect);
00197     PRBool              RgnIntersects(RgnHandle aTheRegion,RgnHandle aIntersectRgn);
00198     virtual void        CalcWindowRegions();
00199 
00200     virtual PRBool      PointInWidget(Point aThePoint);
00201     virtual nsWindow*   FindWidgetHit(Point aThePoint);
00202 
00203     virtual PRBool      DispatchWindowEvent(nsGUIEvent& event);
00204     virtual PRBool      DispatchWindowEvent(nsGUIEvent &event,nsEventStatus &aStatus);
00205     virtual nsresult    HandleUpdateEvent(RgnHandle regionToValidate);
00206     virtual void        AcceptFocusOnClick(PRBool aBool) { mAcceptFocusOnClick = aBool;};
00207     PRBool              AcceptFocusOnClick() { return mAcceptFocusOnClick;};
00208     void                Flash(nsPaintEvent  &aEvent);
00209     PRBool              IsTopLevelWidgetWindow() const { return mIsTopWidgetWindow; };
00210 
00211     // nsIPluginWidget interface
00212 
00213     NS_IMETHOD              GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigin, PRBool& outWidgetVisible);
00214     NS_IMETHOD              StartDrawPlugin(void);
00215     NS_IMETHOD              EndDrawPlugin(void);
00216 
00217     // nsIKBStateControl interface
00218     NS_IMETHOD ResetInputState();
00219     NS_IMETHOD SetIMEOpenState(PRBool aState);
00220     NS_IMETHOD GetIMEOpenState(PRBool* aState);
00221     NS_IMETHOD CancelIMEComposition();
00222 
00223 protected:
00224 
00225   PRBool          ReportDestroyEvent();
00226   PRBool          ReportMoveEvent();
00227   PRBool          ReportSizeEvent();
00228 
00229   void            CalcOffset(PRInt32 &aX,PRInt32 &aY);
00230   PRBool          ContainerHierarchyIsVisible();
00231   
00232   virtual PRBool      OnPaint(nsPaintEvent & aEvent);
00233 
00234   // our own impl of ::ScrollRect() that uses CopyBits so that it looks good. On 
00235   // Carbon, this just calls ::ScrollWindowRect()
00236   void          ScrollBits ( Rect & foo, PRInt32 inLeftDelta, PRInt32 inTopDelta ) ;
00237 
00238   void          CombineRects ( TRectArray & inRectArray ) ;
00239   void          SortRectsLeftToRight ( TRectArray & inRectArray ) ;
00240 
00241 protected:
00242 #if DEBUG
00243   const char*       gInstanceClassName;
00244 #endif
00245 
00246   nsIWidget*        mParent;
00247   PRPackedBool      mIsTopWidgetWindow;
00248   PRPackedBool      mResizingChildren;
00249   PRPackedBool      mSaveVisible;
00250   PRPackedBool      mVisible;
00251   PRPackedBool      mEnabled;
00252   PRInt32           mPreferredWidth;
00253   PRInt32           mPreferredHeight;
00254   nsIFontMetrics*   mFontMetrics;
00255   nsIMenuBar*       mMenuBar;
00256 
00257   RgnHandle         mWindowRegion;
00258   RgnHandle         mVisRegion;
00259   WindowPtr         mWindowPtr;
00260 
00261   PRPackedBool      mDestructorCalled;
00262 
00263   PRPackedBool      mAcceptFocusOnClick;
00264 
00265   PRPackedBool      mDrawing;
00266   PRPackedBool      mInUpdate;    // this is only used for the top-level widget
00267   PRPackedBool      mTempRenderingContextMadeHere;
00268 
00269   nsIRenderingContext*    mTempRenderingContext;
00270     
00271   nsPluginPort*     mPluginPort;
00272 
00273   
00274   // Routines for iterating over the rects of a region and painting
00275   static OSStatus AddRectToArrayProc(UInt16 message, RgnHandle rgn,
00276                                      const Rect* rect, void* refCon);
00277   static void PaintUpdateRect(Rect* r, void* data);
00278 
00279 };
00280 
00281 
00282 #if DEBUG
00283 #define WIDGET_SET_CLASSNAME(n)   gInstanceClassName = (n)
00284 #else
00285 #define WIDGET_SET_CLASSNAME(n)   
00286 #endif
00287 
00288 
00289 //-------------------------------------------------------------------------
00290 //
00291 // nsChildWindow
00292 //
00293 //-------------------------------------------------------------------------
00294 
00295 // Some XP Widgets (like the nsImageButton) include this header file
00296 // and expect to find in it the definition of a "ChildWindow".
00297 
00298 #include "nsChildWindow.h"
00299 
00300 #define ChildWindow   nsChildWindow
00301 
00302 
00303 
00304 #endif // Window_h__