Back to index

lightning-sunbird  0.9+nobinonly
nsWindow.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is Christopher Blizzard
00020  * <blizzard@mozilla.org>.  Portions created by the Initial Developer
00021  * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __nsWindow_h__
00040 
00041 #include "nsCommonWidget.h"
00042 
00043 #include "mozcontainer.h"
00044 #include "mozdrawingarea.h"
00045 #include "nsWeakReference.h"
00046 
00047 #include "nsIDragService.h"
00048 #include "nsITimer.h"
00049 
00050 #include <gtk/gtk.h>
00051 
00052 #include <gdk/gdkx.h>
00053 #include <gtk/gtkwindow.h>
00054 
00055 #ifdef ACCESSIBILITY
00056 #include "nsIAccessNode.h"
00057 #include "nsIAccessible.h"
00058 #endif
00059 
00060 #ifdef USE_XIM
00061 #include <gtk/gtkimmulticontext.h>
00062 #include "pldhash.h"
00063 #endif
00064 
00065 class nsWindow : public nsCommonWidget, public nsSupportsWeakReference {
00066 public:
00067     nsWindow();
00068     virtual ~nsWindow();
00069 
00070     static void ReleaseGlobals();
00071 
00072     NS_DECL_ISUPPORTS_INHERITED
00073 
00074     // nsIWidget
00075     NS_IMETHOD         Create(nsIWidget        *aParent,
00076                               const nsRect     &aRect,
00077                               EVENT_CALLBACK   aHandleEventFunction,
00078                               nsIDeviceContext *aContext,
00079                               nsIAppShell      *aAppShell,
00080                               nsIToolkit       *aToolkit,
00081                               nsWidgetInitData *aInitData);
00082     NS_IMETHOD         Create(nsNativeWidget aParent,
00083                               const nsRect     &aRect,
00084                               EVENT_CALLBACK   aHandleEventFunction,
00085                               nsIDeviceContext *aContext,
00086                               nsIAppShell      *aAppShell,
00087                               nsIToolkit       *aToolkit,
00088                               nsWidgetInitData *aInitData);
00089     NS_IMETHOD         Destroy(void);
00090     NS_IMETHOD         SetParent(nsIWidget* aNewParent);
00091     NS_IMETHOD         SetModal(PRBool aModal);
00092     NS_IMETHOD         IsVisible(PRBool & aState);
00093     NS_IMETHOD         ConstrainPosition(PRBool aAllowSlop,
00094                                          PRInt32 *aX,
00095                                          PRInt32 *aY);
00096     NS_IMETHOD         Move(PRInt32 aX,
00097                             PRInt32 aY);
00098     NS_IMETHOD         PlaceBehind(nsTopLevelWidgetZPlacement  aPlacement,
00099                                    nsIWidget                  *aWidget,
00100                                    PRBool                      aActivate);
00101     NS_IMETHOD         SetZIndex(PRInt32 aZIndex);
00102     NS_IMETHOD         SetSizeMode(PRInt32 aMode);
00103     NS_IMETHOD         Enable(PRBool aState);
00104     NS_IMETHOD         SetFocus(PRBool aRaise = PR_FALSE);
00105     NS_IMETHOD         GetScreenBounds(nsRect &aRect);
00106     NS_IMETHOD         SetForegroundColor(const nscolor &aColor);
00107     NS_IMETHOD         SetBackgroundColor(const nscolor &aColor);
00108     virtual            nsIFontMetrics* GetFont(void);
00109     NS_IMETHOD         SetFont(const nsFont &aFont);
00110     NS_IMETHOD         SetCursor(nsCursor aCursor);
00111     NS_IMETHOD         SetCursor(imgIContainer* aCursor,
00112                                  PRUint32 aHotspotX, PRUint32 aHotspotY);
00113     NS_IMETHOD         Validate();
00114     NS_IMETHOD         Invalidate(PRBool aIsSynchronous);
00115     NS_IMETHOD         Invalidate(const nsRect &aRect,
00116                                   PRBool        aIsSynchronous);
00117     NS_IMETHOD         InvalidateRegion(const nsIRegion *aRegion,
00118                                         PRBool           aIsSynchronous);
00119     NS_IMETHOD         Update();
00120     NS_IMETHOD         SetColorMap(nsColorMap *aColorMap);
00121     NS_IMETHOD         Scroll(PRInt32  aDx,
00122                               PRInt32  aDy,
00123                               nsRect  *aClipRect);
00124     NS_IMETHOD         ScrollWidgets(PRInt32 aDx,
00125                                      PRInt32 aDy);
00126     NS_IMETHOD         ScrollRect(nsRect  &aSrcRect,
00127                                   PRInt32  aDx,
00128                                   PRInt32  aDy);
00129     virtual void*      GetNativeData(PRUint32 aDataType);
00130     NS_IMETHOD         SetBorderStyle(nsBorderStyle aBorderStyle);
00131     NS_IMETHOD         SetTitle(const nsAString& aTitle);
00132     NS_IMETHOD         SetIcon(const nsAString& aIconSpec);
00133     NS_IMETHOD         SetMenuBar(nsIMenuBar * aMenuBar);
00134     NS_IMETHOD         ShowMenuBar(PRBool aShow);
00135     NS_IMETHOD         WidgetToScreen(const nsRect& aOldRect,
00136                                       nsRect& aNewRect);
00137     NS_IMETHOD         ScreenToWidget(const nsRect& aOldRect,
00138                                       nsRect& aNewRect);
00139     NS_IMETHOD         BeginResizingChildren(void);
00140     NS_IMETHOD         EndResizingChildren(void);
00141     NS_IMETHOD         EnableDragDrop(PRBool aEnable);
00142     virtual void       ConvertToDeviceCoordinates(nscoord &aX,
00143                                                   nscoord &aY);
00144     NS_IMETHOD         PreCreateWidget(nsWidgetInitData *aWidgetInitData);
00145     NS_IMETHOD         CaptureMouse(PRBool aCapture);
00146     NS_IMETHOD         CaptureRollupEvents(nsIRollupListener *aListener,
00147                                            PRBool aDoCapture,
00148                                            PRBool aConsumeRollupEvent);
00149     NS_IMETHOD         GetAttention(PRInt32 aCycleCount);
00150     NS_IMETHOD         MakeFullScreen(PRBool aFullScreen);
00151     NS_IMETHOD         HideWindowChrome(PRBool aShouldHide);
00152 
00153     // utility methods
00154     void               LoseFocus();
00155     gint               ConvertBorderStyles(nsBorderStyle aStyle);
00156 
00157     // event callbacks
00158     gboolean           OnExposeEvent(GtkWidget *aWidget,
00159                                      GdkEventExpose *aEvent);
00160     gboolean           OnConfigureEvent(GtkWidget *aWidget,
00161                                         GdkEventConfigure *aEvent);
00162     void               OnSizeAllocate(GtkWidget *aWidget,
00163                                       GtkAllocation *aAllocation);
00164     void               OnDeleteEvent(GtkWidget *aWidget,
00165                                      GdkEventAny *aEvent);
00166     void               OnEnterNotifyEvent(GtkWidget *aWidget,
00167                                           GdkEventCrossing *aEvent);
00168     void               OnLeaveNotifyEvent(GtkWidget *aWidget,
00169                                           GdkEventCrossing *aEvent);
00170     void               OnMotionNotifyEvent(GtkWidget *aWidget,
00171                                            GdkEventMotion *aEvent);
00172     void               OnButtonPressEvent(GtkWidget *aWidget,
00173                                           GdkEventButton *aEvent);
00174     void               OnButtonReleaseEvent(GtkWidget *aWidget,
00175                                             GdkEventButton *aEvent);
00176     void               OnContainerFocusInEvent(GtkWidget *aWidget,
00177                                                GdkEventFocus *aEvent);
00178     void               OnContainerFocusOutEvent(GtkWidget *aWidget,
00179                                                 GdkEventFocus *aEvent);
00180     gboolean           OnKeyPressEvent(GtkWidget *aWidget,
00181                                        GdkEventKey *aEvent);
00182     gboolean           OnKeyReleaseEvent(GtkWidget *aWidget,
00183                                          GdkEventKey *aEvent);
00184     void               OnScrollEvent(GtkWidget *aWidget,
00185                                      GdkEventScroll *aEvent);
00186     void               OnVisibilityNotifyEvent(GtkWidget *aWidget,
00187                                                GdkEventVisibility *aEvent);
00188     void               OnWindowStateEvent(GtkWidget *aWidget,
00189                                           GdkEventWindowState *aEvent);
00190     gboolean           OnDragMotionEvent(GtkWidget       *aWidget,
00191                                          GdkDragContext  *aDragContext,
00192                                          gint             aX,
00193                                          gint             aY,
00194                                          guint            aTime,
00195                                          void            *aData);
00196     void               OnDragLeaveEvent(GtkWidget *      aWidget,
00197                                         GdkDragContext   *aDragContext,
00198                                         guint            aTime,
00199                                         gpointer         aData);
00200     gboolean           OnDragDropEvent(GtkWidget        *aWidget,
00201                                        GdkDragContext   *aDragContext,
00202                                        gint             aX,
00203                                        gint             aY,
00204                                        guint            aTime,
00205                                        gpointer         *aData);
00206     void               OnDragDataReceivedEvent(GtkWidget       *aWidget,
00207                                                GdkDragContext  *aDragContext,
00208                                                gint             aX,
00209                                                gint             aY,
00210                                                GtkSelectionData*aSelectionData,
00211                                                guint            aInfo,
00212                                                guint            aTime,
00213                                                gpointer         aData);
00214     void               OnDragLeave(void);
00215     void               OnDragEnter(nscoord aX, nscoord aY);
00216 
00217 
00218     nsresult           NativeCreate(nsIWidget        *aParent,
00219                                     nsNativeWidget    aNativeParent,
00220                                     const nsRect     &aRect,
00221                                     EVENT_CALLBACK    aHandleEventFunction,
00222                                     nsIDeviceContext *aContext,
00223                                     nsIAppShell      *aAppShell,
00224                                     nsIToolkit       *aToolkit,
00225                                     nsWidgetInitData *aInitData);
00226 
00227     void               NativeResize(PRInt32 aWidth,
00228                                     PRInt32 aHeight,
00229                                     PRBool  aRepaint);
00230 
00231     void               NativeResize(PRInt32 aX,
00232                                     PRInt32 aY,
00233                                     PRInt32 aWidth,
00234                                     PRInt32 aHeight,
00235                                     PRBool  aRepaint);
00236 
00237     void               NativeShow  (PRBool  aAction);
00238 
00239     void               EnsureGrabs  (void);
00240     void               GrabPointer  (void);
00241     void               GrabKeyboard (void);
00242     void               ReleaseGrabs (void);
00243 
00244     enum PluginType {
00245         PluginType_NONE = 0,   /* do not have any plugin */
00246         PluginType_XEMBED,     /* the plugin support xembed */
00247         PluginType_NONXEMBED   /* the plugin does not support xembed */
00248     };
00249 
00250     void               SetPluginType(PluginType aPluginType);
00251     void               SetNonXEmbedPluginFocus(void);
00252     void               LoseNonXEmbedPluginFocus(void);
00253 
00254     void               ThemeChanged(void);
00255 
00256     Window             mOldFocusWindow;
00257 
00258     static guint32     mLastButtonPressTime;
00259     static guint32     mLastButtonReleaseTime;
00260 
00261 #ifdef USE_XIM
00262     void               IMEDestroyContext (void);
00263     void               IMESetFocus       (void);
00264     void               IMELoseFocus      (void);
00265     void               IMEComposeStart   (void);
00266     void               IMEComposeText    (const PRUnichar *aText,
00267                                           const PRInt32 aLen,
00268                                           const gchar *aPreeditString,
00269                                           const gint aCursorPos,
00270                                           const PangoAttrList *aFeedback);
00271     void               IMEComposeEnd     (void);
00272     GtkIMContext*      IMEGetContext     (void);
00273     void               IMECreateContext  (void);
00274     PRBool             IMEFilterEvent    (GdkEventKey *aEvent);
00275 
00276     GtkIMContext       *mIMContext;
00277     PRBool             mComposingText;
00278 
00279 #endif
00280 
00281    void                ResizeTransparencyBitmap(PRInt32 aNewWidth, PRInt32 aNewHeight);
00282    void                ApplyTransparencyBitmap();
00283 #ifdef MOZ_XUL
00284    NS_IMETHOD          SetWindowTranslucency(PRBool aTransparent);
00285    NS_IMETHOD          GetWindowTranslucency(PRBool& aTransparent);
00286    NS_IMETHOD          UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas);
00287 #endif
00288 
00289 private:
00290     void               GetToplevelWidget(GtkWidget **aWidget);
00291     void               GetContainerWindow(nsWindow  **aWindow);
00292     void               SetUrgencyHint(GtkWidget *top_window, PRBool state);
00293     void              *SetupPluginPort(void);
00294     nsresult           SetWindowIconList(const nsCStringArray &aIconList);
00295     void               SetDefaultIcon(void);
00296 
00297     GtkWidget          *mShell;
00298     MozContainer       *mContainer;
00299     MozDrawingarea     *mDrawingarea;
00300 
00301     GtkWindowGroup     *mWindowGroup;
00302 
00303     PRUint32            mContainerGotFocus : 1,
00304                         mContainerLostFocus : 1,
00305                         mContainerBlockFocus : 1,
00306                         mInKeyRepeat : 1,
00307                         mIsVisible : 1,
00308                         mRetryPointerGrab : 1,
00309                         mActivatePending : 1,
00310                         mRetryKeyboardGrab : 1;
00311     GtkWindow          *mTransientParent;
00312     PRInt32             mSizeState;
00313     PluginType          mPluginType;
00314 
00315 #ifdef ACCESSIBILITY
00316     nsCOMPtr<nsIAccessible> mRootAccessible;
00317     void                CreateRootAccessible();
00318     void                GetRootAccessible(nsIAccessible** aAccessible);
00319     void                DispatchActivateEvent(void);
00320     void                DispatchDeactivateEvent(void);
00321     NS_IMETHOD_(PRBool) DispatchAccessibleEvent(nsIAccessible** aAccessible);
00322 #endif
00323 
00324     // The cursor cache
00325     static GdkCursor   *gsGtkCursorCache[eCursorCount];
00326 
00327     // Transparency
00328     PRBool       mIsTranslucent;
00329     // This bitmap tracks which pixels are transparent. We don't support
00330     // full translucency at this time; each pixel is either fully opaque
00331     // or fully transparent.
00332     gchar*       mTransparencyBitmap;
00333  
00334     // all of our DND stuff
00335     // this is the last window that had a drag event happen on it.
00336     static nsWindow    *mLastDragMotionWindow;
00337     void   InitDragEvent         (nsMouseEvent &aEvent);
00338     void   UpdateDragStatus      (nsMouseEvent &aEvent,
00339                                   GdkDragContext *aDragContext,
00340                                   nsIDragService *aDragService);
00341 
00342     // this is everything we need to be able to fire motion events
00343     // repeatedly
00344     GtkWidget         *mDragMotionWidget;
00345     GdkDragContext    *mDragMotionContext;
00346     gint               mDragMotionX;
00347     gint               mDragMotionY;
00348     guint              mDragMotionTime;
00349     guint              mDragMotionTimerID;
00350     nsCOMPtr<nsITimer> mDragLeaveTimer;
00351 
00352     static PRBool      sIsDraggingOutOf;
00353     // drag in progress
00354     static PRBool DragInProgress(void);
00355 
00356     void         ResetDragMotionTimer     (GtkWidget      *aWidget,
00357                                            GdkDragContext *aDragContext,
00358                                            gint           aX,
00359                                            gint           aY,
00360                                            guint          aTime);
00361     void         FireDragMotionTimer      (void);
00362     void         FireDragLeaveTimer       (void);
00363     static guint DragMotionTimerCallback (gpointer aClosure);
00364     static void  DragLeaveTimerCallback  (nsITimer *aTimer, void *aClosure);
00365 
00366 };
00367 
00368 class nsChildWindow : public nsWindow {
00369 public:
00370     nsChildWindow();
00371     ~nsChildWindow();
00372 };
00373 
00374 #endif /* __nsWindow_h__ */
00375