1 /* vim: set sw=2 sts=2 et cin: */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
17 * The Original Code is the Mozilla OS/2 libraries.
19 * The Initial Developer of the Original Code is
20 * John Fairhurst, <john_fairhurst@iname.com>.
21 * Portions created by the Initial Developer are Copyright (C) 1999
22 * the Initial Developer. All Rights Reserved.
25 * Rich Walsh <dragtext@e-vertise.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK *****
41 * This Original Code has been modified by IBM Corporation.
42 * Modifications made by IBM are
43 * Copyright (c) International Business Machines Corporation, 2000
47 //=============================================================================
49 * nsWindow derives from nsIWidget via nsBaseWindow. With the aid
50 * of a helper class (os2FrameWindow) and a subclass (nsChildWindow),
51 * it implements the functionality of both toplevel and child widgets.
53 * Top-level widgets (windows surrounded by a frame with a titlebar, etc.)
54 * are created when NS_WINDOW_CID is used to identify the type of object
55 * needed. Child widgets (windows that either are children of other windows
56 * or are popups such as menus) are created when NS_CHILD_CID is specified.
57 * Since Mozilla expects these to be different classes, NS_CHILD_CID is
58 * mapped to a subclass (nsChildWindow) which acts solely as a wrapper for
59 * nsWindow and adds no functionality.
61 * While most of the methods inherited from nsIWidget are generic, some
62 * apply only to toplevel widgets (e.g. setting a title or icon). The
63 * nature of toplevel windows on OS/2 with their separate frame & client
64 * windows introduces the need for additional toplevel-specific methods,
65 * as well as for special handling in otherwise generic methods.
67 * Rather than incorporating these toplevel functions into the body of
68 * the class, nsWindow delegates them to a helper class, os2FrameWindow.
69 * An instance of this class is created when nsWindow is told to create
70 * a toplevel native window and is destroyed in nsWindow's destructor.
71 * The class's methods operate exclusively on the frame window and never
72 * deal with the frame's client other than to create it. Similarly,
73 * nsWindow never operates on frame windows except for a few trivial
74 * methods (e.g. Enable()). Neither class accesses the other's data
75 * though, of necessity, both call the other's methods.
78 //=============================================================================
83 #include "nsBaseWidget.h"
84 #include "gfxASurface.h"
92 //-----------------------------------------------------------------------------
93 // Items that may not be in the OS/2 Toolkit headers
95 // For WM_MOUSEENTER/LEAVE, mp2 is the other window.
97 #define WM_MOUSEENTER 0x041E
100 #ifndef WM_MOUSELEAVE
101 #define WM_MOUSELEAVE 0x041F
104 #ifndef WM_FOCUSCHANGED
105 #define WM_FOCUSCHANGED 0x000E
109 PVOID APIENTRY
WinQueryProperty(HWND hwnd
, PCSZ pszNameOrAtom
);
110 PVOID APIENTRY
WinRemoveProperty(HWND hwnd
, PCSZ pszNameOrAtom
);
111 BOOL APIENTRY
WinSetProperty(HWND hwnd
, PCSZ pszNameOrAtom
,
112 PVOID pvData
, ULONG ulFlags
);
113 APIRET APIENTRY
DosQueryModFromEIP(HMODULE
* phMod
, ULONG
* pObjNum
,
114 ULONG BuffLen
, PCHAR pBuff
,
115 ULONG
* pOffset
, ULONG Address
);
118 //-----------------------------------------------------------------------------
121 // nsWindow's PM window class name
122 #define kWindowClassName "MozillaWindowClass"
123 #define QWL_NSWINDOWPTR (QWL_USER+4)
125 // Miscellaneous global flags stored in gOS2Flags
126 #define kIsInitialized 0x0001
127 #define kIsDBCS 0x0002
128 #define kIsTrackPoint 0x0004
130 // Possible states of the window
131 #define nsWindowState_ePrecreate 0x0001 // Create() not called yet
132 #define nsWindowState_eInCreate 0x0002 // processing Create() method
133 #define nsWindowState_eLive 0x0004 // active, existing window
134 #define nsWindowState_eClosing 0x0008 // processing Close() method
135 #define nsWindowState_eDoingDelete 0x0010 // object destructor running
136 #define nsWindowState_eDead 0x0100 // window destroyed
138 //-----------------------------------------------------------------------------
141 //#define DEBUG_FOCUS
143 //-----------------------------------------------------------------------------
144 // Forward declarations
148 class os2FrameWindow
;
150 MRESULT EXPENTRY
fnwpNSWindow(HWND hwnd
, ULONG msg
, MPARAM mp1
, MPARAM mp2
);
151 MRESULT EXPENTRY
fnwpFrame(HWND hwnd
, ULONG msg
, MPARAM mp1
, MPARAM mp2
);
153 //=============================================================================
155 //=============================================================================
157 class nsWindow
: public nsBaseWidget
164 NS_IMETHOD
Create(nsIWidget
* aParent
,
165 nsNativeWidget aNativeParent
,
166 const nsIntRect
& aRect
,
167 EVENT_CALLBACK aHandleEventFunction
,
168 nsIDeviceContext
* aContext
,
169 nsIAppShell
* aAppShell
= nsnull
,
170 nsIToolkit
* aToolkit
= nsnull
,
171 nsWidgetInitData
* aInitData
= nsnull
);
172 NS_IMETHOD
Destroy();
173 virtual nsIWidget
* GetParent();
174 virtual float GetDPI();
175 NS_IMETHOD
Enable(PRBool aState
);
176 NS_IMETHOD
IsEnabled(PRBool
* aState
);
177 NS_IMETHOD
Show(PRBool aState
);
178 NS_IMETHOD
IsVisible(PRBool
& aState
);
179 NS_IMETHOD
SetFocus(PRBool aRaise
);
180 NS_IMETHOD
Invalidate(const nsIntRect
& aRect
,
181 PRBool aIsSynchronous
);
183 gfxASurface
* GetThebesSurface();
184 virtual void* GetNativeData(PRUint32 aDataType
);
185 virtual void FreeNativeData(void* aDatum
, PRUint32 aDataType
);
186 NS_IMETHOD
CaptureMouse(PRBool aCapture
);
187 virtual PRBool
HasPendingInputEvent();
188 NS_IMETHOD
GetBounds(nsIntRect
& aRect
);
189 NS_IMETHOD
GetClientBounds(nsIntRect
& aRect
);
190 virtual nsIntPoint
WidgetToScreenOffset();
191 NS_IMETHOD
Move(PRInt32 aX
, PRInt32 aY
);
192 NS_IMETHOD
Resize(PRInt32 aWidth
, PRInt32 aHeight
,
194 NS_IMETHOD
Resize(PRInt32 aX
, PRInt32 aY
,
195 PRInt32 aWidth
, PRInt32 aHeight
,
197 NS_IMETHOD
PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
,
198 nsIWidget
* aWidget
, PRBool aActivate
);
199 NS_IMETHOD
SetZIndex(PRInt32 aZIndex
);
200 virtual nsresult
ConfigureChildren(const nsTArray
<Configuration
>& aConfigurations
);
201 NS_IMETHOD
SetSizeMode(PRInt32 aMode
);
202 NS_IMETHOD
HideWindowChrome(PRBool aShouldHide
);
203 NS_IMETHOD
SetTitle(const nsAString
& aTitle
);
204 NS_IMETHOD
SetIcon(const nsAString
& aIconSpec
);
205 NS_IMETHOD
ConstrainPosition(PRBool aAllowSlop
,
206 PRInt32
* aX
, PRInt32
* aY
);
207 NS_IMETHOD
SetCursor(nsCursor aCursor
);
208 NS_IMETHOD
SetCursor(imgIContainer
* aCursor
,
209 PRUint32 aHotspotX
, PRUint32 aHotspotY
);
210 NS_IMETHOD
CaptureRollupEvents(nsIRollupListener
* aListener
,
211 nsIMenuRollup
* aMenuRollup
,
212 PRBool aDoCapture
, PRBool aConsumeRollupEvent
);
213 NS_IMETHOD
GetToggledKeyState(PRUint32 aKeyCode
,
215 NS_IMETHOD
DispatchEvent(nsGUIEvent
* event
,
216 nsEventStatus
& aStatus
);
217 NS_IMETHOD
ReparentNativeWidget(nsIWidget
* aNewParent
);
220 static void ReleaseGlobals();
223 virtual void OnDestroy();
226 static void InitGlobals();
227 nsresult
CreateWindow(nsWindow
* aParent
,
229 const nsIntRect
& aRect
,
230 nsWidgetInitData
* aInitData
);
231 gfxASurface
* ConfirmThebesSurface();
232 HWND
GetMainWindow();
233 static nsWindow
* GetNSWindowPtr(HWND aWnd
);
234 static PRBool
SetNSWindowPtr(HWND aWnd
, nsWindow
* aPtr
);
235 void NS2PM(POINTL
& ptl
);
236 void NS2PM(RECTL
& rcl
);
237 void NS2PM_PARENT(POINTL
& ptl
);
238 void ActivatePlugin(HWND aWnd
);
239 void SetPluginClipRegion(const Configuration
& aConfiguration
);
240 HWND
GetPluginClipWindow(HWND aParentWnd
);
241 void ActivateTopLevelWidget();
242 HBITMAP
DataToBitmap(PRUint8
* aImageData
, PRUint32 aWidth
,
243 PRUint32 aHeight
, PRUint32 aDepth
);
244 HBITMAP
CreateBitmapRGB(PRUint8
* aImageData
,
245 PRUint32 aWidth
, PRUint32 aHeight
);
246 HBITMAP
CreateTransparencyMask(gfxASurface::gfxImageFormat format
,
248 PRUint32 aWidth
, PRUint32 aHeight
);
249 static PRBool
EventIsInsideWindow(nsWindow
* aWindow
);
250 static PRBool
RollupOnButtonDown(ULONG aMsg
);
251 static void RollupOnFocusLost(HWND aFocus
);
252 MRESULT
ProcessMessage(ULONG msg
, MPARAM mp1
, MPARAM mp2
);
253 PRBool
OnReposition(PSWP pNewSwp
);
255 PRBool
OnMouseChord(MPARAM mp1
, MPARAM mp2
);
256 PRBool
OnDragDropMsg(ULONG msg
, MPARAM mp1
, MPARAM mp2
,
258 PRBool
CheckDragStatus(PRUint32 aAction
, HPS
* aHps
);
259 PRBool
ReleaseIfDragHPS(HPS aHps
);
260 PRBool
OnTranslateAccelerator(PQMSG pQmsg
);
261 PRBool
DispatchKeyEvent(MPARAM mp1
, MPARAM mp2
);
262 void InitEvent(nsGUIEvent
& event
, nsIntPoint
* pt
= 0);
263 PRBool
DispatchWindowEvent(nsGUIEvent
* event
);
264 PRBool
DispatchWindowEvent(nsGUIEvent
* event
,
265 nsEventStatus
& aStatus
);
266 PRBool
DispatchCommandEvent(PRUint32 aEventCommand
);
267 PRBool
DispatchDragDropEvent(PRUint32 aMsg
);
268 PRBool
DispatchMoveEvent(PRInt32 aX
, PRInt32 aY
);
269 PRBool
DispatchResizeEvent(PRInt32 aClientX
,
271 PRBool
DispatchMouseEvent(PRUint32 aEventType
,
272 MPARAM mp1
, MPARAM mp2
,
273 PRBool aIsContextMenuKey
= PR_FALSE
,
274 PRInt16 aButton
= nsMouseEvent::eLeftButton
);
275 PRBool
DispatchActivationEvent(PRUint32 aEventType
);
276 PRBool
DispatchScrollEvent(ULONG msg
, MPARAM mp1
, MPARAM mp2
);
278 friend MRESULT EXPENTRY
fnwpNSWindow(HWND hwnd
, ULONG msg
,
279 MPARAM mp1
, MPARAM mp2
);
280 friend MRESULT EXPENTRY
fnwpFrame(HWND hwnd
, ULONG msg
,
281 MPARAM mp1
, MPARAM mp2
);
282 friend class os2FrameWindow
;
284 HWND mWnd
; // window handle
285 nsWindow
* mParent
; // parent widget
286 os2FrameWindow
* mFrame
; // ptr to os2FrameWindow helper object
287 PRInt32 mWindowState
; // current nsWindowState_* value
288 PRBool mIsDestroying
; // in destructor
289 PRBool mInSetFocus
; // prevent recursive calls
290 PRBool mNoPaint
; // true if window is never visible
291 HPS mDragHps
; // retrieved by DrgGetPS() during a drag
292 PRUint32 mDragStatus
; // set when object is being dragged over
293 HWND mClipWnd
; // used to clip plugin windows
294 HPOINTER mCssCursorHPtr
; // created by SetCursor(imgIContainer*)
295 nsCOMPtr
<imgIContainer
> mCssCursorImg
;// saved by SetCursor(imgIContainer*)
296 nsRefPtr
<gfxOS2Surface
> mThebesSurface
;
298 int mWindowIdentifier
; // a serial number for each new window
302 //=============================================================================
304 //=============================================================================
306 // This only purpose of this subclass is to map NS_CHILD_CID to
307 // some class other than nsWindow which is mapped to NS_WINDOW_CID.
309 class nsChildWindow
: public nsWindow
{
315 #endif // _nswindow_h
317 //=============================================================================