2003-08-25 22:29:22 +00:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
2005-12-31 16:02:07 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
1999-06-28 23:39:35 +00:00
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
2003-08-25 22:29:22 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
1999-06-28 23:39:35 +00:00
|
|
|
*
|
2005-12-31 16:02:07 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2003-08-25 22:29:22 +00:00
|
|
|
* IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-06-28 23:39:35 +00:00
|
|
|
*
|
2003-08-25 22:29:22 +00:00
|
|
|
* Contributor(s):
|
2005-12-31 16:02:07 +00:00
|
|
|
* Michael Lowe <michael.lowe@bigfoot.com>
|
|
|
|
* John Fairhurst <john_fairhurst@iname.com>
|
1999-06-28 23:39:35 +00:00
|
|
|
*
|
2003-08-25 22:29:22 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2005-12-31 16:02:07 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2003-08-25 22:29:22 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2005-12-31 16:02:07 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-08-25 22:29:22 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2005-12-31 16:02:07 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2000-04-03 23:30:26 +00:00
|
|
|
*
|
2003-08-25 22:29:22 +00:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-06-28 23:39:35 +00:00
|
|
|
|
|
|
|
#include "nsAppShell.h"
|
2006-05-11 17:24:22 +00:00
|
|
|
#include "nsThreadUtils.h"
|
1999-06-28 23:39:35 +00:00
|
|
|
|
2006-05-15 21:22:18 +00:00
|
|
|
static UINT sMsgId;
|
1999-06-28 23:39:35 +00:00
|
|
|
|
2003-08-25 22:29:22 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2006-05-11 17:24:22 +00:00
|
|
|
MRESULT EXPENTRY EventWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
1999-06-28 23:39:35 +00:00
|
|
|
{
|
2006-05-11 17:24:22 +00:00
|
|
|
if (msg == sMsgId) {
|
2007-07-08 07:08:04 +00:00
|
|
|
nsAppShell *as = reinterpret_cast<nsAppShell *>(mp2);
|
2006-05-11 17:24:22 +00:00
|
|
|
as->NativeEventCallback();
|
|
|
|
NS_RELEASE(as);
|
|
|
|
return (MRESULT)TRUE;
|
|
|
|
}
|
|
|
|
return WinDefWindowProc(hwnd, msg, mp1, mp2);
|
1999-06-28 23:39:35 +00:00
|
|
|
}
|
|
|
|
|
2006-05-11 17:24:22 +00:00
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
|
|
|
if (mEventWnd) {
|
|
|
|
// DestroyWindow doesn't do anything when called from a non UI thread.
|
|
|
|
// Since mEventWnd was created on the UI thread, it must be destroyed on
|
|
|
|
// the UI thread.
|
|
|
|
WinSendMsg(mEventWnd, WM_CLOSE, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2000-11-02 15:44:58 +00:00
|
|
|
|
2006-05-11 17:24:22 +00:00
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
2006-11-20 22:20:51 +00:00
|
|
|
// a message queue is required to create a window but
|
|
|
|
// it is not necessarily created yet
|
|
|
|
if (WinQueryQueueInfo(HMQ_CURRENT, NULL, 0) == FALSE) {
|
|
|
|
// Set our app to be a PM app before attempting Win calls
|
|
|
|
PPIB ppib;
|
|
|
|
PTIB ptib;
|
|
|
|
DosGetInfoBlocks(&ptib, &ppib);
|
|
|
|
ppib->pib_ultype = 3;
|
|
|
|
|
|
|
|
HAB hab = WinInitialize(0);
|
|
|
|
WinCreateMsgQueue(hab, 0);
|
|
|
|
}
|
|
|
|
|
2006-05-15 21:22:18 +00:00
|
|
|
if (!sMsgId) {
|
|
|
|
sMsgId = WinAddAtom( WinQuerySystemAtomTable(), "nsAppShell:EventID");
|
|
|
|
WinRegisterClass((HAB)0, "nsAppShell:EventWindowClass", EventWindowProc, NULL, 0);
|
|
|
|
}
|
2006-05-11 17:24:22 +00:00
|
|
|
|
|
|
|
mEventWnd = ::WinCreateWindow(HWND_DESKTOP,
|
|
|
|
"nsAppShell:EventWindowClass",
|
|
|
|
"nsAppShell:EventWindow",
|
|
|
|
0,
|
|
|
|
0, 0,
|
|
|
|
10, 10,
|
|
|
|
HWND_DESKTOP,
|
|
|
|
HWND_BOTTOM,
|
|
|
|
0, 0, 0);
|
|
|
|
NS_ENSURE_STATE(mEventWnd);
|
|
|
|
|
|
|
|
return nsBaseAppShell::Init();
|
|
|
|
}
|
2003-08-25 22:29:22 +00:00
|
|
|
|
2006-05-11 17:24:22 +00:00
|
|
|
void
|
|
|
|
nsAppShell::ScheduleNativeEventCallback()
|
2003-08-25 22:29:22 +00:00
|
|
|
{
|
2006-05-11 17:24:22 +00:00
|
|
|
// post a message to the native event queue...
|
2003-08-25 22:29:22 +00:00
|
|
|
NS_ADDREF_THIS();
|
2007-07-08 07:08:04 +00:00
|
|
|
WinPostMsg(mEventWnd, sMsgId, 0, reinterpret_cast<MPARAM>(this));
|
1999-06-28 23:39:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
1999-06-28 23:39:35 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotMessage = false;
|
2003-08-25 22:29:22 +00:00
|
|
|
|
|
|
|
do {
|
2006-05-11 17:24:22 +00:00
|
|
|
QMSG qmsg;
|
|
|
|
// Give priority to system messages (in particular keyboard, mouse, timer,
|
|
|
|
// and paint messages).
|
2003-08-25 22:29:22 +00:00
|
|
|
if (WinPeekMsg((HAB)0, &qmsg, NULL, WM_CHAR, WM_VIOCHAR, PM_REMOVE) ||
|
|
|
|
WinPeekMsg((HAB)0, &qmsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) ||
|
|
|
|
WinPeekMsg((HAB)0, &qmsg, NULL, 0, WM_USER-1, PM_REMOVE) ||
|
|
|
|
WinPeekMsg((HAB)0, &qmsg, NULL, 0, 0, PM_REMOVE)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
gotMessage = true;
|
2006-05-11 17:24:22 +00:00
|
|
|
::WinDispatchMsg((HAB)0, &qmsg);
|
|
|
|
} else if (mayWait) {
|
|
|
|
// Block and wait for any posted application message
|
|
|
|
::WinWaitMsg((HAB)0, 0, 0);
|
2003-08-25 22:29:22 +00:00
|
|
|
}
|
2006-05-11 17:24:22 +00:00
|
|
|
} while (!gotMessage && mayWait);
|
2000-11-02 15:44:58 +00:00
|
|
|
|
2006-05-11 17:24:22 +00:00
|
|
|
return gotMessage;
|
1999-06-28 23:39:35 +00:00
|
|
|
}
|