forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnsWindow.h
298 lines (266 loc) · 13.3 KB
/
nsWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* vim: set sw=2 sts=2 et cin: */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM are
* Copyright (c) International Business Machines Corporation, 2000
*
*/
//=============================================================================
/*
* nsWindow derives from nsIWidget via nsBaseWindow. With the aid
* of a helper class (os2FrameWindow) and a subclass (nsChildWindow),
* it implements the functionality of both toplevel and child widgets.
*
* Top-level widgets (windows surrounded by a frame with a titlebar, etc.)
* are created when NS_WINDOW_CID is used to identify the type of object
* needed. Child widgets (windows that either are children of other windows
* or are popups such as menus) are created when NS_CHILD_CID is specified.
* Since Mozilla expects these to be different classes, NS_CHILD_CID is
* mapped to a subclass (nsChildWindow) which acts solely as a wrapper for
* nsWindow and adds no functionality.
*
* While most of the methods inherited from nsIWidget are generic, some
* apply only to toplevel widgets (e.g. setting a title or icon). The
* nature of toplevel windows on OS/2 with their separate frame & client
* windows introduces the need for additional toplevel-specific methods,
* as well as for special handling in otherwise generic methods.
*
* Rather than incorporating these toplevel functions into the body of
* the class, nsWindow delegates them to a helper class, os2FrameWindow.
* An instance of this class is created when nsWindow is told to create
* a toplevel native window and is destroyed in nsWindow's destructor.
* The class's methods operate exclusively on the frame window and never
* deal with the frame's client other than to create it. Similarly,
* nsWindow never operates on frame windows except for a few trivial
* methods (e.g. Enable()). Neither class accesses the other's data
* though, of necessity, both call the other's methods.
*
*/
//=============================================================================
#ifndef _nswindow_h
#define _nswindow_h
#include "nsBaseWidget.h"
#include "gfxTypes.h"
#include "mozilla/MouseEvents.h"
#define INCL_DOS
#define INCL_WIN
#define INCL_NLS
#define INCL_GPI
#include <os2.h>
#include <os2im.h>
//-----------------------------------------------------------------------------
// Items that may not be in the OS/2 Toolkit headers
// For WM_MOUSEENTER/LEAVE, mp2 is the other window.
#ifndef WM_MOUSEENTER
#define WM_MOUSEENTER 0x041E
#endif
#ifndef WM_MOUSELEAVE
#define WM_MOUSELEAVE 0x041F
#endif
#ifndef WM_FOCUSCHANGED
#define WM_FOCUSCHANGED 0x000E
#endif
class gfxASurface;
extern "C" {
PVOID APIENTRY WinQueryProperty(HWND hwnd, PCSZ pszNameOrAtom);
PVOID APIENTRY WinRemoveProperty(HWND hwnd, PCSZ pszNameOrAtom);
BOOL APIENTRY WinSetProperty(HWND hwnd, PCSZ pszNameOrAtom,
PVOID pvData, ULONG ulFlags);
APIRET APIENTRY DosQueryModFromEIP(HMODULE* phMod, ULONG* pObjNum,
ULONG BuffLen, PCHAR pBuff,
ULONG* pOffset, ULONG Address);
}
//-----------------------------------------------------------------------------
// Macros
// nsWindow's PM window class name
#define kWindowClassName "MozillaWindowClass"
#define QWL_NSWINDOWPTR (QWL_USER+4)
// Miscellaneous global flags stored in gOS2Flags
#define kIsInitialized 0x0001
#define kIsDBCS 0x0002
#define kIsTrackPoint 0x0004
// Possible states of the window
#define nsWindowState_ePrecreate 0x0001 // Create() not called yet
#define nsWindowState_eInCreate 0x0002 // processing Create() method
#define nsWindowState_eLive 0x0004 // active, existing window
#define nsWindowState_eClosing 0x0008 // processing Close() method
#define nsWindowState_eDoingDelete 0x0010 // object destructor running
#define nsWindowState_eDead 0x0100 // window destroyed
//-----------------------------------------------------------------------------
// Debug
//#define DEBUG_FOCUS
//-----------------------------------------------------------------------------
// Forward declarations
class imgIContainer;
class gfxOS2Surface;
class os2FrameWindow;
MRESULT EXPENTRY fnwpNSWindow(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY fnwpFrame(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
//=============================================================================
// nsWindow
//=============================================================================
class nsWindow : public nsBaseWidget
{
public:
nsWindow();
virtual ~nsWindow();
// from nsIWidget
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const nsIntRect& aRect,
EVENT_CALLBACK aHandleEventFunction,
nsDeviceContext* aContext,
nsWidgetInitData* aInitData = nullptr);
NS_IMETHOD Destroy();
virtual nsIWidget* GetParent();
virtual float GetDPI();
NS_IMETHOD Enable(bool aState);
virtual bool IsEnabled() const;
NS_IMETHOD Show(bool aState);
virtual bool IsVisible() const;
NS_IMETHOD SetFocus(bool aRaise);
NS_IMETHOD Invalidate(const nsIntRect& aRect);
gfxASurface* GetThebesSurface();
virtual void* GetNativeData(uint32_t aDataType);
virtual void FreeNativeData(void* aDatum, uint32_t aDataType);
NS_IMETHOD CaptureMouse(bool aCapture);
virtual bool HasPendingInputEvent();
NS_IMETHOD GetBounds(nsIntRect& aRect);
NS_IMETHOD GetClientBounds(nsIntRect& aRect);
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD Move(double aX, double aY);
NS_IMETHOD Resize(double aWidth, double aHeight,
bool aRepaint);
NS_IMETHOD Resize(double aX, double aY,
double aWidth, double aHeight,
bool aRepaint);
NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
nsIWidget* aWidget, bool aActivate);
NS_IMETHOD SetZIndex(int32_t aZIndex);
virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
NS_IMETHOD SetSizeMode(int32_t aMode);
NS_IMETHOD HideWindowChrome(bool aShouldHide);
NS_IMETHOD SetTitle(const nsAString& aTitle);
NS_IMETHOD SetIcon(const nsAString& aIconSpec);
NS_IMETHOD ConstrainPosition(bool aAllowSlop,
int32_t* aX, int32_t* aY);
NS_IMETHOD SetCursor(nsCursor aCursor);
NS_IMETHOD SetCursor(imgIContainer* aCursor,
uint32_t aHotspotX, uint32_t aHotspotY);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener,
bool aDoCapture, bool aConsumeRollupEvent);
NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode,
bool* aLEDState);
NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
nsEventStatus& aStatus);
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
NS_IMETHOD_(void) SetInputContext(const InputContext& aInputContext,
const InputContextAction& aAction)
{
mInputContext = aInputContext;
}
NS_IMETHOD_(InputContext) GetInputContext();
// nsWindow
static void ReleaseGlobals();
protected:
// from nsBaseWidget
virtual void OnDestroy();
// nsWindow
static void InitGlobals();
nsresult CreateWindow(nsWindow* aParent,
HWND aParentWnd,
const nsIntRect& aRect,
nsWidgetInitData* aInitData);
gfxASurface* ConfirmThebesSurface();
HWND GetMainWindow();
static nsWindow* GetNSWindowPtr(HWND aWnd);
static bool SetNSWindowPtr(HWND aWnd, nsWindow* aPtr);
void NS2PM(POINTL& ptl);
void NS2PM(RECTL& rcl);
void NS2PM_PARENT(POINTL& ptl);
void ActivatePlugin(HWND aWnd);
void SetPluginClipRegion(const Configuration& aConfiguration);
HWND GetPluginClipWindow(HWND aParentWnd);
void ActivateTopLevelWidget();
HBITMAP DataToBitmap(uint8_t* aImageData, uint32_t aWidth,
uint32_t aHeight, uint32_t aDepth);
HBITMAP CreateBitmapRGB(uint8_t* aImageData,
uint32_t aWidth, uint32_t aHeight);
HBITMAP CreateTransparencyMask(gfxImageFormat format,
uint8_t* aImageData,
uint32_t aWidth, uint32_t aHeight);
static bool EventIsInsideWindow(nsWindow* aWindow);
static bool RollupOnButtonDown(ULONG aMsg);
static void RollupOnFocusLost(HWND aFocus);
MRESULT ProcessMessage(ULONG msg, MPARAM mp1, MPARAM mp2);
bool OnReposition(PSWP pNewSwp);
bool OnPaint();
bool OnMouseChord(MPARAM mp1, MPARAM mp2);
bool OnDragDropMsg(ULONG msg, MPARAM mp1, MPARAM mp2,
MRESULT& mr);
bool CheckDragStatus(uint32_t aAction, HPS* aHps);
bool ReleaseIfDragHPS(HPS aHps);
bool OnTranslateAccelerator(PQMSG pQmsg);
bool OnQueryConvertPos(MPARAM mp1, MRESULT& mresult);
bool ImeResultString(HIMI himi);
bool ImeConversionString(HIMI himi);
bool OnImeRequest(MPARAM mp1, MPARAM mp2);
bool DispatchKeyEvent(MPARAM mp1, MPARAM mp2);
void InitEvent(mozilla::WidgetGUIEvent& aEvent,
nsIntPoint* pt = 0);
bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent);
bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent,
nsEventStatus& aStatus);
bool DispatchCommandEvent(uint32_t aEventCommand);
bool DispatchDragDropEvent(uint32_t aMsg);
bool DispatchMoveEvent(int32_t aX, int32_t aY);
bool DispatchResizeEvent(int32_t aClientX,
int32_t aClientY);
bool DispatchMouseEvent(uint32_t aEventType,
MPARAM mp1, MPARAM mp2,
bool aIsContextMenuKey = false,
int16_t aButton = mozilla::WidgetMouseEvent::eLeftButton);
bool DispatchActivationEvent(uint32_t aEventType);
bool DispatchScrollEvent(ULONG msg, MPARAM mp1, MPARAM mp2);
friend MRESULT EXPENTRY fnwpNSWindow(HWND hwnd, ULONG msg,
MPARAM mp1, MPARAM mp2);
friend MRESULT EXPENTRY fnwpFrame(HWND hwnd, ULONG msg,
MPARAM mp1, MPARAM mp2);
friend class os2FrameWindow;
HWND mWnd; // window handle
nsWindow* mParent; // parent widget
os2FrameWindow* mFrame; // ptr to os2FrameWindow helper object
int32_t mWindowState; // current nsWindowState_* value
bool mIsDestroying; // in destructor
bool mInSetFocus; // prevent recursive calls
bool mNoPaint; // true if window is never visible
HPS mDragHps; // retrieved by DrgGetPS() during a drag
uint32_t mDragStatus; // set when object is being dragged over
HWND mClipWnd; // used to clip plugin windows
HPOINTER mCssCursorHPtr; // created by SetCursor(imgIContainer*)
nsCOMPtr<imgIContainer> mCssCursorImg;// saved by SetCursor(imgIContainer*)
nsRefPtr<gfxOS2Surface> mThebesSurface;
bool mIsComposing;
nsString mLastDispatchedCompositionString;
#ifdef DEBUG_FOCUS
int mWindowIdentifier; // a serial number for each new window
#endif
InputContext mInputContext;
};
//=============================================================================
// nsChildWindow
//=============================================================================
// This only purpose of this subclass is to map NS_CHILD_CID to
// some class other than nsWindow which is mapped to NS_WINDOW_CID.
class nsChildWindow : public nsWindow {
public:
nsChildWindow() {}
~nsChildWindow() {}
};
#endif // _nswindow_h
//=============================================================================