Back to index

lightning-sunbird  0.9+nobinonly
nsChildView.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 
00038 #ifndef nsChildView_h__
00039 #define nsChildView_h__
00040 
00041 #import "mozView.h"
00042 
00043 #include "nsISupports.h"
00044 #include "nsBaseWidget.h"
00045 #include "nsIPluginWidget.h"
00046 #include "nsIEventSink.h"
00047 #include "nsIScrollableView.h"
00048 
00049 #include "nsIWidget.h"
00050 #include "nsIKBStateControl.h"
00051 #include "nsIAppShell.h"
00052 
00053 #include "nsIMouseListener.h"
00054 #include "nsIEventListener.h"
00055 #include "nsString.h"
00056 
00057 #include "nsIMenuBar.h"
00058 
00059 #include "nsplugindefs.h"
00060 #include <Quickdraw.h>
00061 
00062 #define NSRGB_2_COLOREF(color) \
00063             RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
00064 
00065 struct nsPluginPort;
00066 
00067 #undef DARWIN
00068 #import <Cocoa/Cocoa.h>
00069 
00070 class nsChildView;
00071 
00072 
00073 @interface ChildView : NSQuickDrawView<mozView, NSTextInput>
00074 {
00075 @private
00076   NSWindow*       mWindow;    // shortcut to the top window, [WEAK]
00077   
00078     // the nsChildView that created the view. It retains this NSView, so
00079     // the link back to it must be weak.
00080   nsChildView* mGeckoChild;
00081   
00082     // allows us to redispatch events back to a centralized location
00083   nsIEventSink* mEventSink;
00084   
00085     // tag for our mouse enter/exit tracking rect
00086   NSTrackingRectTag mMouseEnterExitTag;
00087 
00088   // Whether we're a plugin view.
00089   BOOL mIsPluginView;
00090 
00091   NSEvent* mCurKeyEvent;   // only valid during a keyDown
00092   
00093   // needed for NSTextInput implementation
00094   NSRange mMarkedRange;
00095   NSRange mSelectedRange;
00096   BOOL mInComposition;
00097   BOOL mIgnoreDoCommand;
00098 
00099   BOOL mToggleMouseMoveEventWatching;
00100 
00101   BOOL mInHandScroll; // true for as long as we are hand scrolling
00102   // hand scroll locations
00103   NSPoint mHandScrollStartMouseLoc;
00104   nscoord mHandScrollStartScrollX, mHandScrollStartScrollY;
00105 
00106   // rects that were invalidated during a draw, so have pending drawing
00107   NSMutableArray* mPendingDirtyRects;
00108   BOOL mPendingFullDisplay;
00109   
00110   PRUint32 mLastModifierState;
00111 }
00112 
00113 // these are sent to the first responder when the window key status
00114 // changes
00115 - (void)viewsWindowDidBecomeKey;
00116 - (void)viewsWindowDidResignKey;
00117 
00118 @end
00119 
00120 
00121 
00122 //-------------------------------------------------------------------------
00123 //
00124 // nsChildView
00125 //
00126 //-------------------------------------------------------------------------
00127 
00128 class nsChildView : public nsBaseWidget,
00129                     public nsIPluginWidget,
00130                     public nsIKBStateControl,
00131                     public nsIEventSink
00132 {
00133 private:
00134   typedef nsBaseWidget Inherited;
00135 
00136 public:
00137                           nsChildView();
00138   virtual                 ~nsChildView();
00139   
00140   NS_DECL_ISUPPORTS_INHERITED
00141   NS_DECL_NSIEVENTSINK 
00142 
00143   // nsIKBStateControl interface
00144   NS_IMETHOD              ResetInputState();
00145   NS_IMETHOD              SetIMEOpenState(PRBool aState);
00146   NS_IMETHOD              GetIMEOpenState(PRBool* aState);
00147   NS_IMETHOD              CancelIMEComposition();
00148  
00149   // nsIWidget interface
00150   NS_IMETHOD              Create(nsIWidget *aParent,
00151                                  const nsRect &aRect,
00152                                  EVENT_CALLBACK aHandleEventFunction,
00153                                  nsIDeviceContext *aContext,
00154                                  nsIAppShell *aAppShell = nsnull,
00155                                  nsIToolkit *aToolkit = nsnull,
00156                                  nsWidgetInitData *aInitData = nsnull);
00157   NS_IMETHOD              Create(nsNativeWidget aNativeParent,
00158                                  const nsRect &aRect,
00159                                  EVENT_CALLBACK aHandleEventFunction,
00160                                  nsIDeviceContext *aContext,
00161                                  nsIAppShell *aAppShell = nsnull,
00162                                  nsIToolkit *aToolkit = nsnull,
00163                                  nsWidgetInitData *aInitData = nsnull);
00164 
00165    // Utility method for implementing both Create(nsIWidget ...) and
00166    // Create(nsNativeWidget...)
00167 
00168   virtual nsresult        StandardCreate(nsIWidget *aParent,
00169                               const nsRect &aRect,
00170                               EVENT_CALLBACK aHandleEventFunction,
00171                               nsIDeviceContext *aContext,
00172                               nsIAppShell *aAppShell,
00173                               nsIToolkit *aToolkit,
00174                               nsWidgetInitData *aInitData,
00175                               nsNativeWidget aNativeParent = nsnull);
00176 
00177   NS_IMETHOD              Destroy();
00178 
00179   NS_IMETHOD              Show(PRBool aState);
00180   NS_IMETHOD              IsVisible(PRBool & aState);
00181 
00182   virtual nsIWidget*      GetParent(void);
00183   
00184   NS_IMETHOD              ModalEventFilter(PRBool aRealEvent, void *aEvent,
00185                                            PRBool *aForWindow);
00186 
00187   NS_IMETHOD              ConstrainPosition(PRBool aAllowSlop,
00188                                             PRInt32 *aX, PRInt32 *aY);
00189   NS_IMETHOD              Move(PRInt32 aX, PRInt32 aY);
00190   NS_IMETHOD              MoveWithRepaintOption(PRInt32 aX, PRInt32 aY, PRBool aRepaint);
00191   NS_IMETHOD              Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
00192   NS_IMETHOD              Resize(PRInt32 aX, PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
00193 
00194   NS_IMETHOD              Enable(PRBool aState);
00195   NS_IMETHOD              IsEnabled(PRBool *aState);
00196   NS_IMETHOD              SetFocus(PRBool aRaise);
00197   NS_IMETHOD              SetBounds(const nsRect &aRect);
00198   NS_IMETHOD              GetBounds(nsRect &aRect);
00199 
00200   virtual nsIFontMetrics* GetFont(void);
00201   NS_IMETHOD              SetFont(const nsFont &aFont);
00202   NS_IMETHOD              Invalidate(PRBool aIsSynchronous);
00203   NS_IMETHOD              Invalidate(const nsRect &aRect,PRBool aIsSynchronous);
00204   NS_IMETHOD              InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
00205   NS_IMETHOD              Validate();
00206 
00207   virtual void*           GetNativeData(PRUint32 aDataType);
00208   NS_IMETHOD              SetColorMap(nsColorMap *aColorMap);
00209   NS_IMETHOD              Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
00210   NS_IMETHOD              WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
00211   NS_IMETHOD              ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
00212   NS_IMETHOD              BeginResizingChildren(void);
00213   NS_IMETHOD              EndResizingChildren(void);
00214 
00215   static  PRBool          ConvertStatus(nsEventStatus aStatus);
00216   NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
00217   virtual PRBool          DispatchMouseEvent(nsMouseEvent &aEvent);
00218 
00219   virtual void            StartDraw(nsIRenderingContext* aRenderingContext = nsnull);
00220   virtual void            EndDraw();
00221   NS_IMETHOD              Update();
00222   virtual void            UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext);
00223   
00224   virtual void      ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY);
00225   void              LocalToWindowCoordinate(nsPoint& aPoint)            { ConvertToDeviceCoordinates(aPoint.x, aPoint.y); }
00226   void              LocalToWindowCoordinate(nscoord& aX, nscoord& aY)   { ConvertToDeviceCoordinates(aX, aY); }
00227   void              LocalToWindowCoordinate(nsRect& aRect)              { ConvertToDeviceCoordinates(aRect.x, aRect.y); }
00228 
00229   NS_IMETHOD        SetMenuBar(nsIMenuBar * aMenuBar);
00230   NS_IMETHOD        ShowMenuBar(PRBool aShow);
00231   virtual nsIMenuBar*   GetMenuBar();
00232   NS_IMETHOD        GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
00233   NS_IMETHOD        SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
00234   
00235   NS_IMETHOD        SetCursor(nsCursor aCursor);
00236   NS_IMETHOD        SetCursor(imgIContainer* aCursor, PRUint32 aHotspotX, PRUint32 aHotspotY);
00237   
00238   NS_IMETHOD        CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
00239   NS_IMETHOD        SetTitle(const nsAString& title);
00240 
00241   NS_IMETHOD        GetAttention(PRInt32 aCycleCount);
00242 
00243   // nsIPluginWidget
00244   NS_IMETHOD        GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigin, PRBool& outWidgetVisible);
00245   NS_IMETHOD        StartDrawPlugin();
00246   NS_IMETHOD        EndDrawPlugin();
00247   
00248   // Mac specific methods
00249   virtual void      CalcWindowRegions();
00250 
00251   virtual PRBool    PointInWidget(Point aThePoint);
00252   
00253   virtual PRBool    DispatchWindowEvent(nsGUIEvent& event);
00254   virtual PRBool    DispatchWindowEvent(nsGUIEvent &event,nsEventStatus &aStatus);
00255   virtual void      AcceptFocusOnClick(PRBool aBool) { mAcceptFocusOnClick = aBool;};
00256   PRBool            AcceptFocusOnClick() { return mAcceptFocusOnClick;};
00257   void              Flash(nsPaintEvent  &aEvent);
00258   
00259   void              RemovedFromWindow();
00260   void              AddedToWindow();
00261 
00262   void              LiveResizeStarted();
00263   void              LiveResizeEnded();
00264   
00265 protected:
00266 
00267   PRBool            ReportDestroyEvent();
00268   PRBool            ReportMoveEvent();
00269   PRBool            ReportSizeEvent();
00270 
00271   NS_IMETHOD        CalcOffset(PRInt32 &aX,PRInt32 &aY);
00272 
00273   virtual PRBool    OnPaint(nsPaintEvent & aEvent);
00274 
00275     // override to create different kinds of child views. Autoreleases, so
00276     // caller must retain.
00277   virtual NSView*   CreateCocoaView(NSRect inFrame);
00278   void              TearDownView();
00279 
00280     // Find a quickdraw port in which to draw (needed by GFX until it
00281     // is converted to Cocoa). This MUST be overridden if CreateCocoaView()
00282     // does not create something that inherits from NSQuickDrawView!
00283   virtual GrafPtr   GetQuickDrawPort();   // gets plugin port or view's port
00284 
00285   // return qdPort for a focussed ChildView, and null otherwise
00286   GrafPtr           GetChildViewQuickDrawPort();
00287 
00288 protected:
00289 
00290   NSView<mozView>*      mView;      // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
00291 
00292   NSView<mozView>*      mParentView;
00293   nsIWidget*            mParentWidget;
00294   
00295   nsIFontMetrics*       mFontMetrics;
00296   nsIRenderingContext*  mTempRenderingContext;
00297 
00298   PRPackedBool          mDestroyCalled;
00299   PRPackedBool          mDestructorCalled;
00300   PRPackedBool          mVisible;
00301 
00302   PRPackedBool          mDrawing;
00303   PRPackedBool          mTempRenderingContextMadeHere;
00304     
00305   PRPackedBool          mAcceptFocusOnClick;
00306   PRPackedBool          mLiveResizeInProgress;
00307   PRPackedBool          mPluginDrawing;
00308   
00309   nsPluginPort*         mPluginPort;
00310   RgnHandle             mVisRgn;
00311     
00312 };
00313 
00314 
00315 #endif // nsChildView_h__