1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsAppShell.h"
7 #include "nsThreadUtils.h"
11 //-------------------------------------------------------------------------
13 MRESULT EXPENTRY
EventWindowProc(HWND hwnd
, ULONG msg
, MPARAM mp1
, MPARAM mp2
)
16 nsAppShell
*as
= reinterpret_cast<nsAppShell
*>(mp2
);
17 as
->NativeEventCallback();
21 return WinDefWindowProc(hwnd
, msg
, mp1
, mp2
);
24 nsAppShell::~nsAppShell()
27 // DestroyWindow doesn't do anything when called from a non UI thread.
28 // Since mEventWnd was created on the UI thread, it must be destroyed on
30 WinSendMsg(mEventWnd
, WM_CLOSE
, 0, 0);
37 // a message queue is required to create a window but
38 // it is not necessarily created yet
39 if (WinQueryQueueInfo(HMQ_CURRENT
, nullptr, 0) == FALSE
) {
40 // Set our app to be a PM app before attempting Win calls
43 DosGetInfoBlocks(&ptib
, &ppib
);
46 HAB hab
= WinInitialize(0);
47 WinCreateMsgQueue(hab
, 0);
51 sMsgId
= WinAddAtom( WinQuerySystemAtomTable(), "nsAppShell:EventID");
52 WinRegisterClass((HAB
)0, "nsAppShell:EventWindowClass", EventWindowProc
,
56 mEventWnd
= ::WinCreateWindow(HWND_DESKTOP
,
57 "nsAppShell:EventWindowClass",
58 "nsAppShell:EventWindow",
65 NS_ENSURE_STATE(mEventWnd
);
67 return nsBaseAppShell::Init();
71 nsAppShell::ScheduleNativeEventCallback()
73 // post a message to the native event queue...
75 WinPostMsg(mEventWnd
, sMsgId
, 0, reinterpret_cast<MPARAM
>(this));
79 nsAppShell::ProcessNextNativeEvent(bool mayWait
)
81 bool gotMessage
= false;
85 // Give priority to system messages (in particular keyboard, mouse, timer,
86 // and paint messages).
87 if (WinPeekMsg((HAB
)0, &qmsg
, nullptr, WM_CHAR
, WM_VIOCHAR
, PM_REMOVE
) ||
88 WinPeekMsg((HAB
)0, &qmsg
, nullptr, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
) ||
89 WinPeekMsg((HAB
)0, &qmsg
, nullptr, 0, WM_USER
-1, PM_REMOVE
) ||
90 WinPeekMsg((HAB
)0, &qmsg
, nullptr, 0, 0, PM_REMOVE
)) {
92 ::WinDispatchMsg((HAB
)0, &qmsg
);
94 // Block and wait for any posted application message
95 ::WinWaitMsg((HAB
)0, 0, 0);
97 } while (!gotMessage
&& mayWait
);