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 nsWindow_h__
00038 #define nsWindow_h__
00039 
00040 #include "nsISupports.h"
00041 
00042 #include "nsWidget.h"
00043 
00044 #include "nsString.h"
00045 
00046 #include "nsIDragService.h"
00047 
00048 #include "gtkmozarea.h"
00049 #include "gdksuperwin.h"
00050 
00051 #ifdef USE_XIM
00052 #include "pldhash.h"
00053 class nsIMEGtkIC;
00054 class nsIMEPreedit;
00055 #endif // USE_XIM
00056 
00057 class nsFont;
00058 class nsIAppShell;
00059 
00064 class nsWindow : public nsWidget
00065 {
00066 
00067 public:
00068   // nsIWidget interface
00069 
00070   nsWindow();
00071   virtual ~nsWindow();
00072 
00073   static void ReleaseGlobals();
00074 
00075   NS_DECL_ISUPPORTS_INHERITED
00076 
00077   NS_IMETHOD           WidgetToScreen(const nsRect &aOldRect, nsRect &aNewRect);
00078 
00079   NS_IMETHOD           PreCreateWidget(nsWidgetInitData *aWidgetInitData);
00080 
00081   virtual void*        GetNativeData(PRUint32 aDataType);
00082 
00083   NS_IMETHOD           Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
00084   NS_IMETHOD           ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
00085   NS_IMETHOD           ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy);
00086 
00087   NS_IMETHOD           SetTitle(const nsAString& aTitle);
00088   NS_IMETHOD           Show(PRBool aShow);
00089   NS_IMETHOD           CaptureMouse(PRBool aCapture);
00090 
00091   NS_IMETHOD           ConstrainPosition(PRBool aAllowSlop,
00092                                          PRInt32 *aX, PRInt32 *aY);
00093   NS_IMETHOD           Move(PRInt32 aX, PRInt32 aY);
00094 
00095   NS_IMETHOD           Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
00096   NS_IMETHOD           Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth,
00097                               PRInt32 aHeight, PRBool aRepaint);
00098 
00099   NS_IMETHOD           BeginResizingChildren(void);
00100   NS_IMETHOD           EndResizingChildren(void);
00101 
00102   NS_IMETHOD           GetScreenBounds(nsRect &aRect);
00103 
00104   NS_IMETHOD           CaptureRollupEvents(nsIRollupListener * aListener,
00105                                            PRBool aDoCapture,
00106                                            PRBool aConsumeRollupEvent);
00107   NS_IMETHOD           Validate();
00108   NS_IMETHOD           Invalidate(PRBool aIsSynchronous);
00109   NS_IMETHOD           Invalidate(const nsRect &aRect, PRBool aIsSynchronous);
00110   NS_IMETHOD           InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous);
00111   NS_IMETHOD           SetBackgroundColor(const nscolor &aColor);
00112   NS_IMETHOD           SetCursor(nsCursor aCursor);
00113   NS_IMETHOD           Enable (PRBool aState);
00114   NS_IMETHOD           IsEnabled (PRBool *aState);
00115   NS_IMETHOD           SetFocus(PRBool aRaise);
00116   NS_IMETHOD           GetAttention(PRInt32 aCycleCount);
00117   NS_IMETHOD           Destroy();
00118   NS_IMETHOD           SetParent(nsIWidget* aNewParent);
00119   void                 ResizeTransparencyBitmap(PRInt32 aNewWidth, PRInt32 aNewHeight);
00120   void                 ApplyTransparencyBitmap();
00121 #ifdef MOZ_XUL
00122   NS_IMETHOD           SetWindowTranslucency(PRBool aTransparent);
00123   NS_IMETHOD           GetWindowTranslucency(PRBool& aTransparent);
00124   NS_IMETHOD           UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas);
00125   NS_IMETHOD           HideWindowChrome(PRBool aShouldHide);
00126   NS_IMETHOD           MakeFullScreen(PRBool aFullScreen);
00127 #endif
00128   NS_IMETHOD           SetIcon(const nsAString& aIcon);
00129   GdkCursor           *GtkCreateCursor(nsCursor aCursorType);
00130   virtual void         LoseFocus(void);
00131 
00132   // nsIKBStateControl
00133   NS_IMETHOD           ResetInputState();
00134 
00135   void                 QueueDraw();
00136   void                 UnqueueDraw();
00137   void                 DoPaint(nsIRegion *aClipRegion);
00138   static gboolean      UpdateIdle (gpointer data);
00139   // get the toplevel window for this widget
00140   virtual GtkWindow   *GetTopLevelWindow(void);
00141   NS_IMETHOD           Update(void);
00142   virtual void         OnMotionNotifySignal(GdkEventMotion *aGdkMotionEvent);
00143   virtual void         OnEnterNotifySignal(GdkEventCrossing *aGdkCrossingEvent);
00144   virtual void         OnLeaveNotifySignal(GdkEventCrossing *aGdkCrossingEvent);
00145   virtual void         OnButtonPressSignal(GdkEventButton *aGdkButtonEvent);
00146   virtual void         OnButtonReleaseSignal(GdkEventButton *aGdkButtonEvent);
00147   virtual void         OnFocusInSignal(GdkEventFocus * aGdkFocusEvent);
00148   virtual void         OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent);
00149   virtual void         InstallFocusInSignal(GtkWidget * aWidget);
00150   virtual void         InstallFocusOutSignal(GtkWidget * aWidget);
00151   void                 HandleGDKEvent(GdkEvent *event);
00152 
00153   gint                 ConvertBorderStyles(nsBorderStyle bs);
00154 
00155   void                 InvalidateWindowPos(void);
00156 
00157 
00158   // in nsWidget now
00159   //    virtual  PRBool OnResize(nsSizeEvent &aEvent);
00160   
00161   void HandleXlibConfigureNotifyEvent(XEvent *event);
00162 
00163   // Return the GtkMozArea that is the nearest parent of this widget
00164   virtual GtkWidget *GetOwningWidget();
00165 
00166   // Get the owning window for this window
00167   nsWindow *GetOwningWindow();
00168 
00169   // Return the type of the window that is the toplevel mozilla window
00170   // for this (possibly) inner window
00171   nsWindowType GetOwningWindowType();
00172 
00173   // Return the Gdk window used for rendering
00174   virtual GdkWindow * GetRenderWindow(GtkObject * aGtkWidget);
00175 
00176   // this is the "native" destroy code that will destroy any
00177   // native windows / widgets for this logical widget
00178   virtual void DestroyNative(void);
00179 
00180   // grab in progress
00181   PRBool GrabInProgress(void);
00182   // drag in progress
00183   static PRBool DragInProgress(void);
00184 
00185   //  XXX Chris - fix these
00186   //  virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent);
00187 
00188   // this will get the nsWindow with the grab.  The return will not be
00189   // addrefed.
00190   static nsWindow *GetGrabWindow(void);
00191   GdkWindow *GetGdkGrabWindow(void);
00192   
00193   // Return the Gdk window used for positioning, raising and lowering
00194   virtual GdkWindow* GetLayeringWindow();
00195 
00196   virtual void DispatchSetFocusEvent(void);
00197   virtual void DispatchLostFocusEvent(void);
00198   virtual void DispatchActivateEvent(void);
00199   virtual void DispatchDeactivateEvent(void);
00200 
00201   PRBool mBlockMozAreaFocusIn;
00202 
00203   void HandleMozAreaFocusIn(void);
00204   void HandleMozAreaFocusOut(void);
00205 
00206   // Window icon cache
00207   static PRBool IconEntryMatches(PLDHashTable* aTable,
00208                                  const PLDHashEntryHdr* aHdr,
00209                                  const void* aKey);
00210   static void ClearIconEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr);
00211 
00212 protected:
00213   virtual void ResetInternalVisibility();
00214   virtual void SetInternalVisibility(PRBool aVisible);
00215 
00216   virtual void OnRealize(GtkWidget *aWidget);
00217 
00218   virtual void OnDestroySignal(GtkWidget* aGtkWidget);
00219 
00221 
00222   virtual void InitCallbacks(char * aName = nsnull);
00223   NS_IMETHOD CreateNative(GtkObject *parentWidget);
00224 
00225   PRBool      mIsTooSmall;
00226 
00227   GtkWidget *mShell;  /* used for toplevel windows */
00228   GdkSuperWin *mSuperWin;
00229   GtkWidget   *mMozArea;
00230   GtkWidget   *mMozAreaClosestParent;
00231 
00232   PRBool      GetWindowPos(nscoord &x, nscoord &y);
00233   nscoord     mCachedX, mCachedY; 
00234 
00235   // are we doing a grab?
00236   static PRBool      sIsGrabbing;
00237   static nsWindow   *sGrabWindow;
00238   static PRBool      sIsDraggingOutOf;
00239 
00240   // our wonderful hash table with our window -> nsWindow * lookup
00241   static GHashTable *mWindowLookupTable;
00242 
00243   // this will query all of it's children trying to find a child
00244   // that has a containing rectangle and return it.
00245   static Window     GetInnerMostWindow(Window aOriginWindow,
00246                                        Window aWindow,
00247                                        nscoord x, nscoord y,
00248                                        nscoord *retx, nscoord *rety,
00249                                        int depth);
00250   // given an X window this will find the nsWindow * for it.
00251   static nsWindow  *GetnsWindowFromXWindow(Window aWindow);
00252 
00253   static gint ClientEventSignal(GtkWidget* widget, GdkEventClient* event, void* data);
00254   virtual void ThemeChanged();
00255 
00256   // all of our DND stuff
00257 
00258   // this is the last window that had a drag event happen on it.
00259   static nsWindow  *mLastDragMotionWindow;
00260   static GdkCursor *gsGtkCursorCache[eCursorCount];
00261 
00262   void   InitDragEvent(nsMouseEvent &aEvent);
00263   void   UpdateDragStatus(nsMouseEvent &aEvent,
00264                           GdkDragContext *aDragContext,
00265                           nsIDragService *aDragService);
00266 
00267   // DragBegin not needed ?
00268   // always returns TRUE
00269   static gint DragMotionSignal (GtkWidget *      aWidget,
00270                                 GdkDragContext   *aDragContext,
00271                                 gint             aX,
00272                                 gint             aY,
00273                                 guint            aTime,
00274                                 void             *aData);
00275   gint OnDragMotionSignal      (GtkWidget *      aWidget,
00276                                 GdkDragContext   *aDragContext,
00277                                 gint             aX,
00278                                 gint             aY,
00279                                 guint            aTime,
00280                                 void             *aData);
00281 
00282   static void DragLeaveSignal  (GtkWidget *      aWidget,
00283                                 GdkDragContext   *aDragContext,
00284                                 guint            aTime,
00285                                 gpointer         aData);
00286   void OnDragLeaveSignal       (GtkWidget *      aWidget,
00287                                 GdkDragContext   *aDragContext,
00288                                 guint            aTime,
00289                                 gpointer         aData);
00290 
00291   // always returns TRUE
00292   static gint DragDropSignal   (GtkWidget        *aWidget,
00293                                 GdkDragContext   *aDragContext,
00294                                 gint             aX,
00295                                 gint             aY,
00296                                 guint            aTime,
00297                                 void             *aData);
00298   gint OnDragDropSignal        (GtkWidget        *aWidget,
00299                                 GdkDragContext   *aDragContext,
00300                                 gint             aX,
00301                                 gint             aY,
00302                                 guint            aTime,
00303                                 void             *aData);
00304   // when the data has been received
00305   static void DragDataReceived (GtkWidget         *aWidget,
00306                                 GdkDragContext    *aDragContext,
00307                                 gint               aX,
00308                                 gint               aY,
00309                                 GtkSelectionData  *aSelectionData,
00310                                 guint              aInfo,
00311                                 guint32            aTime,
00312                                 gpointer           aData);
00313   void OnDragDataReceived      (GtkWidget         *aWidget,
00314                                 GdkDragContext    *aDragContext,
00315                                 gint               aX,
00316                                 gint               aY,
00317                                 GtkSelectionData  *aSelectionData,
00318                                 guint              aInfo,
00319                                 guint32            aTime,
00320                                 gpointer           aData);
00321 
00322   // these are drag and drop events that aren't generated by widget
00323   // events but we do synthesize
00324 
00325   void OnDragLeave(void);
00326   void OnDragEnter(nscoord aX, nscoord aY);
00327 
00328   // this is everything we need to be able to fire motion events
00329   // repeatedly
00330   GtkWidget         *mDragMotionWidget;
00331   GdkDragContext    *mDragMotionContext;
00332   gint               mDragMotionX;
00333   gint               mDragMotionY;
00334   guint              mDragMotionTime;
00335   guint              mDragMotionTimerID;
00336   nsCOMPtr<nsITimer> mDragLeaveTimer;
00337 
00338   void        ResetDragMotionTimer    (GtkWidget      *aWidget,
00339                                        GdkDragContext *aDragContext,
00340                                        gint           aX,
00341                                        gint           aY,
00342                                        guint          aTime);
00343   void        FireDragMotionTimer     (void);
00344   void        FireDragLeaveTimer      (void);
00345   static guint DragMotionTimerCallback (gpointer aClosure);
00346   static void  DragLeaveTimerCallback  (nsITimer *aTimer, void *aClosure);
00347 
00348   // Hash table for icon spec -> icon set lookup
00349   static PLDHashTable* sIconCache;
00350 
00351 #ifdef USE_XIM
00352 protected:
00353   static GdkFont      *gPreeditFontset;
00354   static GdkFont      *gStatusFontset;
00355   static GdkIMStyle   gInputStyle;
00356   static PLDHashTable gXICLookupTable;
00357   PRPackedBool        mIMEEnable;
00358   PRPackedBool        mIMECallComposeStart;
00359   PRPackedBool        mIMECallComposeEnd;
00360   PRPackedBool        mIMEIsBeingActivate;
00361   nsWindow*           mIMEShellWindow;
00362   void                SetXICSpotLocation(nsIMEGtkIC* aXIC, nsPoint aPoint);
00363   void                SetXICBaseFontSize(nsIMEGtkIC* aXIC, int height);
00364   nsCOMPtr<nsITimer>  mICSpotTimer;
00365   static void         ICSpotCallback(nsITimer* aTimer, void* aClosure);
00366   nsresult            KillICSpotTimer();
00367   nsresult            PrimeICSpotTimer();
00368   nsresult            UpdateICSpot(nsIMEGtkIC* aXIC);
00369   int                 mXICFontSize;
00370 
00371 public:
00372   nsIMEGtkIC*        IMEGetInputContext(PRBool aCreate);
00373 
00374   void        ime_preedit_start();
00375   void        ime_preedit_draw(nsIMEGtkIC* aXIC);
00376   void        ime_preedit_done();
00377   void        ime_status_draw();
00378 
00379   void         IMEUnsetFocusWindow();
00380   void         IMESetFocusWindow();
00381   void         IMEGetShellWindow();
00382   void         IMEDestroyIC();
00383   void         IMEBeingActivate(PRBool aActive);
00384 #endif // USE_XIM 
00385 
00386 protected:
00387   void              IMEComposeStart(guint aTime);
00388   void              IMEComposeText(GdkEventKey*,
00389                              const PRUnichar *aText,
00390                              const PRInt32 aLen,
00391                              const char *aFeedback);
00392   void              IMEComposeEnd(guint aTime);
00393 
00394 public:
00395   virtual void IMECommitEvent(GdkEventKey *aEvent);
00396 
00397 private:
00398   PRUnichar*   mIMECompositionUniString;
00399   PRInt32      mIMECompositionUniStringSize;
00400 
00401   nsresult     SetMiniIcon(GdkPixmap *window_pixmap,
00402                            GdkBitmap *window_mask);
00403   nsresult     SetIcon(GdkPixmap *window_pixmap, 
00404                        GdkBitmap *window_mask);
00405 
00406   void         NativeGrab(PRBool aGrab);
00407 
00408   PRPackedBool mLastGrabFailed;
00409   PRPackedBool mIsUpdating;
00410   PRPackedBool mLeavePending;
00411   PRPackedBool mRestoreFocus;
00412 
00417   PRPackedBool mHasAnonymousChildren;
00418   PRPackedBool mIsTranslucent;
00419 
00420   // This bitmap tracks which pixels are transparent. We don't support
00421   // full translucency at this time; each pixel is either fully opaque
00422   // or fully transparent.
00423   gchar*       mTransparencyBitmap;
00424 
00425   void DestroyNativeChildren(void);
00426 
00427   GtkWindow *mTransientParent;
00428 };
00429 
00430 //
00431 // A child window is a window with different style
00432 //
00433 class ChildWindow : public nsWindow {
00434 public:
00435   ChildWindow();
00436   ~ChildWindow();
00437 };
00438 
00439 #endif // Window_h__