~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/widget/src/gtk2/nsWindow.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* vim:expandtab:shiftwidth=4:tabstop=4:
 
3
 */
 
4
/* ***** BEGIN LICENSE BLOCK *****
 
5
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
6
 *
 
7
 * The contents of this file are subject to the Mozilla Public License Version
 
8
 * 1.1 (the "License"); you may not use this file except in compliance with
 
9
 * the License. You may obtain a copy of the License at
 
10
 * http://www.mozilla.org/MPL/
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS" basis,
 
13
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
14
 * for the specific language governing rights and limitations under the
 
15
 * License.
 
16
 *
 
17
 * The Original Code mozilla.org code.
 
18
 *
 
19
 * The Initial Developer of the Original Code Christopher Blizzard
 
20
 * <blizzard@mozilla.org>.  Portions created by the Initial Developer
 
21
 * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
 
22
 *
 
23
 * Contributor(s):
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the MPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the MPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#ifndef __nsWindow_h__
 
40
 
 
41
#include "nsCommonWidget.h"
 
42
 
 
43
#include "mozcontainer.h"
 
44
#include "mozdrawingarea.h"
 
45
#include "nsWeakReference.h"
 
46
 
 
47
#include "nsIDragService.h"
 
48
#include "nsITimer.h"
 
49
 
 
50
#include <gtk/gtk.h>
 
51
 
 
52
#include <gdk/gdkx.h>
 
53
#include <gtk/gtkwindow.h>
 
54
 
 
55
#ifdef ACCESSIBILITY
 
56
#include "nsIAccessNode.h"
 
57
#include "nsIAccessible.h"
 
58
#endif
 
59
 
 
60
#ifdef USE_XIM
 
61
#include <gtk/gtkimmulticontext.h>
 
62
#include "pldhash.h"
 
63
#endif
 
64
 
 
65
class nsWindow : public nsCommonWidget, public nsSupportsWeakReference {
 
66
public:
 
67
    nsWindow();
 
68
    virtual ~nsWindow();
 
69
 
 
70
    static void ReleaseGlobals();
 
71
 
 
72
    NS_DECL_ISUPPORTS_INHERITED
 
73
 
 
74
    // nsIWidget
 
75
    NS_IMETHOD         Create(nsIWidget        *aParent,
 
76
                              const nsRect     &aRect,
 
77
                              EVENT_CALLBACK   aHandleEventFunction,
 
78
                              nsIDeviceContext *aContext,
 
79
                              nsIAppShell      *aAppShell,
 
80
                              nsIToolkit       *aToolkit,
 
81
                              nsWidgetInitData *aInitData);
 
82
    NS_IMETHOD         Create(nsNativeWidget aParent,
 
83
                              const nsRect     &aRect,
 
84
                              EVENT_CALLBACK   aHandleEventFunction,
 
85
                              nsIDeviceContext *aContext,
 
86
                              nsIAppShell      *aAppShell,
 
87
                              nsIToolkit       *aToolkit,
 
88
                              nsWidgetInitData *aInitData);
 
89
    NS_IMETHOD         Destroy(void);
 
90
    NS_IMETHOD         SetModal(PRBool aModal);
 
91
    NS_IMETHOD         IsVisible(PRBool & aState);
 
92
    NS_IMETHOD         ConstrainPosition(PRBool aAllowSlop,
 
93
                                         PRInt32 *aX,
 
94
                                         PRInt32 *aY);
 
95
    NS_IMETHOD         Move(PRInt32 aX,
 
96
                            PRInt32 aY);
 
97
    NS_IMETHOD         PlaceBehind(nsTopLevelWidgetZPlacement  aPlacement,
 
98
                                   nsIWidget                  *aWidget,
 
99
                                   PRBool                      aActivate);
 
100
    NS_IMETHOD         SetSizeMode(PRInt32 aMode);
 
101
    NS_IMETHOD         Enable(PRBool aState);
 
102
    NS_IMETHOD         SetFocus(PRBool aRaise = PR_FALSE);
 
103
    NS_IMETHOD         GetScreenBounds(nsRect &aRect);
 
104
    NS_IMETHOD         SetForegroundColor(const nscolor &aColor);
 
105
    NS_IMETHOD         SetBackgroundColor(const nscolor &aColor);
 
106
    virtual            nsIFontMetrics* GetFont(void);
 
107
    NS_IMETHOD         SetFont(const nsFont &aFont);
 
108
    NS_IMETHOD         SetCursor(nsCursor aCursor);
 
109
    NS_IMETHOD         Validate();
 
110
    NS_IMETHOD         Invalidate(PRBool aIsSynchronous);
 
111
    NS_IMETHOD         Invalidate(const nsRect &aRect,
 
112
                                  PRBool        aIsSynchronous);
 
113
    NS_IMETHOD         InvalidateRegion(const nsIRegion *aRegion,
 
114
                                        PRBool           aIsSynchronous);
 
115
    NS_IMETHOD         Update();
 
116
    NS_IMETHOD         SetColorMap(nsColorMap *aColorMap);
 
117
    NS_IMETHOD         Scroll(PRInt32  aDx,
 
118
                              PRInt32  aDy,
 
119
                              nsRect  *aClipRect);
 
120
    NS_IMETHOD         ScrollWidgets(PRInt32 aDx,
 
121
                                     PRInt32 aDy);
 
122
    NS_IMETHOD         ScrollRect(nsRect  &aSrcRect,
 
123
                                  PRInt32  aDx,
 
124
                                  PRInt32  aDy);
 
125
    virtual void*      GetNativeData(PRUint32 aDataType);
 
126
    NS_IMETHOD         SetBorderStyle(nsBorderStyle aBorderStyle);
 
127
    NS_IMETHOD         SetTitle(const nsString& aTitle);
 
128
    NS_IMETHOD         SetIcon(const nsAString& aIconSpec);
 
129
    NS_IMETHOD         SetMenuBar(nsIMenuBar * aMenuBar);
 
130
    NS_IMETHOD         ShowMenuBar(PRBool aShow);
 
131
    NS_IMETHOD         WidgetToScreen(const nsRect& aOldRect,
 
132
                                      nsRect& aNewRect);
 
133
    NS_IMETHOD         ScreenToWidget(const nsRect& aOldRect,
 
134
                                      nsRect& aNewRect);
 
135
    NS_IMETHOD         BeginResizingChildren(void);
 
136
    NS_IMETHOD         EndResizingChildren(void);
 
137
    NS_IMETHOD         EnableDragDrop(PRBool aEnable);
 
138
    virtual void       ConvertToDeviceCoordinates(nscoord &aX,
 
139
                                                  nscoord &aY);
 
140
    NS_IMETHOD         PreCreateWidget(nsWidgetInitData *aWidgetInitData);
 
141
    NS_IMETHOD         CaptureMouse(PRBool aCapture);
 
142
    NS_IMETHOD         CaptureRollupEvents(nsIRollupListener *aListener,
 
143
                                           PRBool aDoCapture,
 
144
                                           PRBool aConsumeRollupEvent);
 
145
    NS_IMETHOD         GetAttention(PRInt32 aCycleCount);
 
146
    NS_IMETHOD         HideWindowChrome(PRBool aShouldHide);
 
147
 
 
148
    // utility methods
 
149
    void               LoseFocus();
 
150
    gint               ConvertBorderStyles(nsBorderStyle aStyle);
 
151
 
 
152
    // event callbacks
 
153
    gboolean           OnExposeEvent(GtkWidget *aWidget,
 
154
                                     GdkEventExpose *aEvent);
 
155
    gboolean           OnConfigureEvent(GtkWidget *aWidget,
 
156
                                        GdkEventConfigure *aEvent);
 
157
    void               OnSizeAllocate(GtkWidget *aWidget,
 
158
                                      GtkAllocation *aAllocation);
 
159
    void               OnDeleteEvent(GtkWidget *aWidget,
 
160
                                     GdkEventAny *aEvent);
 
161
    void               OnEnterNotifyEvent(GtkWidget *aWidget,
 
162
                                          GdkEventCrossing *aEvent);
 
163
    void               OnLeaveNotifyEvent(GtkWidget *aWidget,
 
164
                                          GdkEventCrossing *aEvent);
 
165
    void               OnMotionNotifyEvent(GtkWidget *aWidget,
 
166
                                           GdkEventMotion *aEvent);
 
167
    void               OnButtonPressEvent(GtkWidget *aWidget,
 
168
                                          GdkEventButton *aEvent);
 
169
    void               OnButtonReleaseEvent(GtkWidget *aWidget,
 
170
                                            GdkEventButton *aEvent);
 
171
    void               OnContainerFocusInEvent(GtkWidget *aWidget,
 
172
                                               GdkEventFocus *aEvent);
 
173
    void               OnContainerFocusOutEvent(GtkWidget *aWidget,
 
174
                                                GdkEventFocus *aEvent);
 
175
    gboolean           OnKeyPressEvent(GtkWidget *aWidget,
 
176
                                       GdkEventKey *aEvent);
 
177
    gboolean           OnKeyReleaseEvent(GtkWidget *aWidget,
 
178
                                         GdkEventKey *aEvent);
 
179
    void               OnScrollEvent(GtkWidget *aWidget,
 
180
                                     GdkEventScroll *aEvent);
 
181
    void               OnVisibilityNotifyEvent(GtkWidget *aWidget,
 
182
                                               GdkEventVisibility *aEvent);
 
183
    void               OnWindowStateEvent(GtkWidget *aWidget,
 
184
                                          GdkEventWindowState *aEvent);
 
185
    gboolean           OnDragMotionEvent(GtkWidget       *aWidget,
 
186
                                         GdkDragContext  *aDragContext,
 
187
                                         gint             aX,
 
188
                                         gint             aY,
 
189
                                         guint            aTime,
 
190
                                         void            *aData);
 
191
    void               OnDragLeaveEvent(GtkWidget *      aWidget,
 
192
                                        GdkDragContext   *aDragContext,
 
193
                                        guint            aTime,
 
194
                                        gpointer         aData);
 
195
    gboolean           OnDragDropEvent(GtkWidget        *aWidget,
 
196
                                       GdkDragContext   *aDragContext,
 
197
                                       gint             aX,
 
198
                                       gint             aY,
 
199
                                       guint            aTime,
 
200
                                       gpointer         *aData);
 
201
    void               OnDragDataReceivedEvent(GtkWidget       *aWidget,
 
202
                                               GdkDragContext  *aDragContext,
 
203
                                               gint             aX,
 
204
                                               gint             aY,
 
205
                                               GtkSelectionData*aSelectionData,
 
206
                                               guint            aInfo,
 
207
                                               guint            aTime,
 
208
                                               gpointer         aData);
 
209
    void               OnDragLeave(void);
 
210
    void               OnDragEnter(nscoord aX, nscoord aY);
 
211
 
 
212
 
 
213
    nsresult           NativeCreate(nsIWidget        *aParent,
 
214
                                    nsNativeWidget    aNativeParent,
 
215
                                    const nsRect     &aRect,
 
216
                                    EVENT_CALLBACK    aHandleEventFunction,
 
217
                                    nsIDeviceContext *aContext,
 
218
                                    nsIAppShell      *aAppShell,
 
219
                                    nsIToolkit       *aToolkit,
 
220
                                    nsWidgetInitData *aInitData);
 
221
 
 
222
    void               NativeResize(PRInt32 aWidth,
 
223
                                    PRInt32 aHeight,
 
224
                                    PRBool  aRepaint);
 
225
 
 
226
    void               NativeResize(PRInt32 aX,
 
227
                                    PRInt32 aY,
 
228
                                    PRInt32 aWidth,
 
229
                                    PRInt32 aHeight,
 
230
                                    PRBool  aRepaint);
 
231
 
 
232
    void               NativeShow  (PRBool  aAction);
 
233
 
 
234
    void               EnsureGrabs  (void);
 
235
    void               GrabPointer  (void);
 
236
    void               GrabKeyboard (void);
 
237
    void               ReleaseGrabs (void);
 
238
 
 
239
    enum PluginType {
 
240
        PluginType_NONE = 0,   /* do not have any plugin */
 
241
        PluginType_XEMBED,     /* the plugin support xembed */
 
242
        PluginType_NONXEMBED   /* the plugin does not support xembed */
 
243
    };
 
244
 
 
245
    void               SetPluginType(PluginType aPluginType);
 
246
    void               SetNonXEmbedPluginFocus(void);
 
247
    void               LoseNonXEmbedPluginFocus(void);
 
248
 
 
249
    Window             mOldFocusWindow;
 
250
 
 
251
    static guint32     mLastButtonPressTime;
 
252
 
 
253
#ifdef USE_XIM
 
254
    void               IMEDestroyContext (void);
 
255
    void               IMESetFocus       (void);
 
256
    void               IMELoseFocus      (void);
 
257
    void               IMEComposeStart   (void);
 
258
    void               IMEComposeText    (const PRUnichar *aText,
 
259
                                          const PRInt32 aLen,
 
260
                                          const gchar *aPreeditString,
 
261
                                          const PangoAttrList *aFeedback);
 
262
    void               IMEComposeEnd     (void);
 
263
    GtkIMContext*      IMEGetContext     (void);
 
264
    void               IMECreateContext  (void);
 
265
    PRBool             IMEFilterEvent    (GdkEventKey *aEvent);
 
266
 
 
267
    GtkIMContext       *mIMContext;
 
268
    PRBool             mComposingText;
 
269
 
 
270
#endif
 
271
 
 
272
private:
 
273
    void               GetToplevelWidget(GtkWidget **aWidget);
 
274
    void               GetContainerWindow(nsWindow  **aWindow);
 
275
    void              *SetupPluginPort(void);
 
276
    nsresult           SetWindowIconList(const nsCStringArray &aIconList);
 
277
    void               SetDefaultIcon(void);
 
278
 
 
279
    GtkWidget          *mShell;
 
280
    MozContainer       *mContainer;
 
281
    MozDrawingarea     *mDrawingarea;
 
282
 
 
283
    GtkWindowGroup     *mWindowGroup;
 
284
 
 
285
    PRUint32            mContainerGotFocus : 1,
 
286
                        mContainerLostFocus : 1,
 
287
                        mContainerBlockFocus : 1,
 
288
                        mInKeyRepeat : 1,
 
289
                        mIsVisible : 1,
 
290
                        mRetryPointerGrab : 1,
 
291
                        mActivatePending : 1,
 
292
                        mRetryKeyboardGrab : 1;
 
293
    GtkWindow          *mTransientParent;
 
294
    PRInt32             mSizeState;
 
295
    PluginType          mPluginType;
 
296
 
 
297
#ifdef ACCESSIBILITY
 
298
    nsCOMPtr<nsIAccessible> mRootAccessible;
 
299
    void                CreateRootAccessible();
 
300
    void                GetRootAccessible(nsIAccessible** aAccessible);
 
301
    void                DispatchActivateEvent(void);
 
302
    void                DispatchDeactivateEvent(void);
 
303
    NS_IMETHOD_(PRBool) DispatchAccessibleEvent(nsIAccessible** aAccessible);
 
304
#endif
 
305
 
 
306
    // The cursor cache
 
307
    static GdkCursor   *gsGtkCursorCache[eCursorCount];
 
308
 
 
309
    // all of our DND stuff
 
310
    // this is the last window that had a drag event happen on it.
 
311
    static nsWindow    *mLastDragMotionWindow;
 
312
    void   InitDragEvent         (nsMouseEvent &aEvent);
 
313
    void   UpdateDragStatus      (nsMouseEvent &aEvent,
 
314
                                  GdkDragContext *aDragContext,
 
315
                                  nsIDragService *aDragService);
 
316
 
 
317
    // this is everything we need to be able to fire motion events
 
318
    // repeatedly
 
319
    GtkWidget         *mDragMotionWidget;
 
320
    GdkDragContext    *mDragMotionContext;
 
321
    gint               mDragMotionX;
 
322
    gint               mDragMotionY;
 
323
    guint              mDragMotionTime;
 
324
    guint              mDragMotionTimerID;
 
325
    nsCOMPtr<nsITimer> mDragLeaveTimer;
 
326
 
 
327
    static PRBool      sIsDraggingOutOf;
 
328
    // drag in progress
 
329
    static PRBool DragInProgress(void);
 
330
 
 
331
    void         ResetDragMotionTimer     (GtkWidget      *aWidget,
 
332
                                           GdkDragContext *aDragContext,
 
333
                                           gint           aX,
 
334
                                           gint           aY,
 
335
                                           guint          aTime);
 
336
    void         FireDragMotionTimer      (void);
 
337
    void         FireDragLeaveTimer       (void);
 
338
    static guint DragMotionTimerCallback (gpointer aClosure);
 
339
    static void  DragLeaveTimerCallback  (nsITimer *aTimer, void *aClosure);
 
340
 
 
341
};
 
342
 
 
343
class nsChildWindow : public nsWindow {
 
344
public:
 
345
    nsChildWindow();
 
346
    ~nsChildWindow();
 
347
};
 
348
 
 
349
#endif /* __nsWindow_h__ */
 
350