2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Michael Lowe <michael.lowe@bigfoot.com>
|
|
|
|
* Darin Fisher <darin@meer.net>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsToolkit.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2009-10-06 14:42:45 -07:00
|
|
|
#include "WinTaskbar.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-05 10:17:44 -08:00
|
|
|
#ifdef WINCE
|
|
|
|
BOOL WaitMessage(VOID)
|
|
|
|
{
|
|
|
|
BOOL retval = TRUE;
|
|
|
|
|
|
|
|
HANDLE hThread = GetCurrentThread();
|
|
|
|
DWORD waitRes = MsgWaitForMultipleObjectsEx(1, &hThread, INFINITE, QS_ALLEVENTS, 0);
|
|
|
|
if((DWORD)-1 == waitRes)
|
|
|
|
{
|
|
|
|
retval = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static UINT sMsgId;
|
|
|
|
|
2009-10-05 19:26:54 -07:00
|
|
|
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
|
|
|
|
static UINT sTaskbarButtonCreatedMsg;
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
UINT nsAppShell::GetTaskbarButtonCreatedMessage() {
|
|
|
|
return sTaskbarButtonCreatedMsg;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static BOOL PeekKeyAndIMEMessage(LPMSG msg, HWND hwnd)
|
|
|
|
{
|
|
|
|
MSG msg1, msg2, *lpMsg;
|
|
|
|
BOOL b1, b2;
|
|
|
|
b1 = ::PeekMessageW(&msg1, NULL, WM_KEYFIRST, WM_IME_KEYLAST, PM_NOREMOVE);
|
|
|
|
b2 = ::PeekMessageW(&msg2, NULL, WM_IME_SETCONTEXT, WM_IME_KEYUP, PM_NOREMOVE);
|
|
|
|
if (b1 || b2) {
|
|
|
|
if (b1 && b2) {
|
|
|
|
if (msg1.time < msg2.time)
|
|
|
|
lpMsg = &msg1;
|
|
|
|
else
|
|
|
|
lpMsg = &msg2;
|
|
|
|
} else if (b1)
|
|
|
|
lpMsg = &msg1;
|
|
|
|
else
|
|
|
|
lpMsg = &msg2;
|
|
|
|
return ::PeekMessageW(msg, hwnd, lpMsg->message, lpMsg->message, PM_REMOVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ LRESULT CALLBACK
|
|
|
|
nsAppShell::EventWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (uMsg == sMsgId) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsAppShell *as = reinterpret_cast<nsAppShell *>(lParam);
|
2007-03-22 10:30:00 -07:00
|
|
|
as->NativeEventCallback();
|
|
|
|
NS_RELEASE(as);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
SendMessage(mEventWnd, WM_CLOSE, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
|
|
|
if (!sMsgId)
|
2008-08-29 14:26:56 -07:00
|
|
|
sMsgId = RegisterWindowMessageW(L"nsAppShell:EventID");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-05 19:26:54 -07:00
|
|
|
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
|
|
|
|
sTaskbarButtonCreatedMsg = ::RegisterWindowMessageW(L"TaskbarButtonCreated");
|
|
|
|
NS_ASSERTION(sTaskbarButtonCreatedMsg, "Could not register taskbar button creation message");
|
2009-10-06 14:42:45 -07:00
|
|
|
|
|
|
|
// Global app registration id for Win7 and up. See
|
|
|
|
// WinTaskbar.cpp for details.
|
|
|
|
mozilla::widget::WinTaskbar::SetAppUserModelID();
|
2009-10-05 19:26:54 -07:00
|
|
|
#endif
|
|
|
|
|
2008-08-29 14:26:56 -07:00
|
|
|
WNDCLASSW wc;
|
2007-03-22 10:30:00 -07:00
|
|
|
HINSTANCE module = GetModuleHandle(NULL);
|
|
|
|
|
2008-08-29 14:26:56 -07:00
|
|
|
const PRUnichar *const kWindowClass = L"nsAppShell:EventWindowClass";
|
|
|
|
if (!GetClassInfoW(module, kWindowClass, &wc)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
wc.style = 0;
|
|
|
|
wc.lpfnWndProc = EventWindowProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = module;
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hCursor = NULL;
|
|
|
|
wc.hbrBackground = (HBRUSH) NULL;
|
2008-08-29 14:26:56 -07:00
|
|
|
wc.lpszMenuName = (LPCWSTR) NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
wc.lpszClassName = kWindowClass;
|
2008-08-29 14:26:56 -07:00
|
|
|
RegisterClassW(&wc);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-29 14:26:56 -07:00
|
|
|
mEventWnd = CreateWindowW(kWindowClass, L"nsAppShell:EventWindow",
|
2007-03-22 10:30:00 -07:00
|
|
|
0, 0, 0, 10, 10, NULL, NULL, module, NULL);
|
|
|
|
NS_ENSURE_STATE(mEventWnd);
|
|
|
|
|
|
|
|
return nsBaseAppShell::Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::ScheduleNativeEventCallback()
|
|
|
|
{
|
|
|
|
// post a message to the native event queue...
|
|
|
|
NS_ADDREF_THIS();
|
2007-07-08 00:08:04 -07:00
|
|
|
::PostMessage(mEventWnd, sMsgId, 0, reinterpret_cast<LPARAM>(this));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
|
|
|
|
{
|
|
|
|
PRBool gotMessage = PR_FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
MSG msg;
|
|
|
|
// Give priority to system messages (in particular keyboard, mouse, timer,
|
|
|
|
// and paint messages).
|
|
|
|
if (PeekKeyAndIMEMessage(&msg, NULL) ||
|
|
|
|
::PeekMessageW(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) ||
|
|
|
|
::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
|
|
gotMessage = PR_TRUE;
|
|
|
|
if (msg.message == WM_QUIT) {
|
2008-08-09 11:49:42 -07:00
|
|
|
::PostQuitMessage(msg.wParam);
|
2007-03-22 10:30:00 -07:00
|
|
|
Exit();
|
|
|
|
} else {
|
|
|
|
::TranslateMessage(&msg);
|
|
|
|
::DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
} else if (mayWait) {
|
|
|
|
// Block and wait for any posted application message
|
|
|
|
::WaitMessage();
|
|
|
|
}
|
|
|
|
} while (!gotMessage && mayWait);
|
|
|
|
|
|
|
|
return gotMessage;
|
|
|
|
}
|