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