2007-03-22 10:30:00 -07:00
|
|
|
/* vim: set sw=2 sts=2 et cin: */
|
2010-03-04 10:19:41 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
/*
|
|
|
|
* This file is divided into the following major sections:
|
|
|
|
*
|
|
|
|
* - Macros
|
|
|
|
* - Variables & Forward declarations
|
|
|
|
* - nsWindow Create / Destroy
|
|
|
|
* - Standard Window Operations
|
|
|
|
* - Window Positioning
|
|
|
|
* - Plugin Operations
|
|
|
|
* - Top-level (frame window) Operations
|
|
|
|
* - Mouse Pointers
|
|
|
|
* - Rollup Event Handlers
|
|
|
|
* - nsWindow's Window Procedure
|
|
|
|
* - Window Message Handlers
|
|
|
|
* - Drag & Drop - Target methods
|
|
|
|
* - Keyboard Handlers
|
2012-06-20 03:09:05 -07:00
|
|
|
* - IME
|
2010-03-04 10:19:41 -08:00
|
|
|
* - Event Dispatch
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsWindow.h"
|
2010-03-06 09:52:10 -08:00
|
|
|
#include "os2FrameWindow.h"
|
2010-03-04 10:19:41 -08:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxOS2Surface.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "npapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDragService.h"
|
2010-03-04 10:19:41 -08:00
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsIScreenManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsOS2Uni.h"
|
2009-07-26 11:28:24 -07:00
|
|
|
#include "nsTHashtable.h"
|
2011-10-14 11:11:22 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2010-03-04 10:19:41 -08:00
|
|
|
#include "wdgtos2rc.h"
|
2012-08-11 18:42:37 -07:00
|
|
|
#include "nsIDOMWheelEvent.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2011-06-07 00:38:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2012-06-20 03:09:05 -07:00
|
|
|
#include <os2im.h>
|
2013-06-11 05:12:07 -07:00
|
|
|
#include <algorithm> // std::max
|
2011-06-07 00:38:00 -07:00
|
|
|
using namespace mozilla;
|
2012-08-11 18:42:37 -07:00
|
|
|
using namespace mozilla::widget;
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Macros
|
|
|
|
//=============================================================================
|
|
|
|
// Drag and Drop
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// d&d flags - actions that might cause problems during d&d
|
|
|
|
#define ACTION_PAINT 1
|
|
|
|
#define ACTION_DRAW 2
|
|
|
|
#define ACTION_SCROLL 3
|
|
|
|
#define ACTION_SHOW 4
|
|
|
|
#define ACTION_PTRPOS 5
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// d&d status - shorten these references a bit
|
|
|
|
#define DND_None (nsIDragSessionOS2::DND_NONE)
|
|
|
|
#define DND_NativeDrag (nsIDragSessionOS2::DND_NATIVEDRAG)
|
|
|
|
#define DND_MozDrag (nsIDragSessionOS2::DND_MOZDRAG)
|
|
|
|
#define DND_InDrop (nsIDragSessionOS2::DND_INDROP)
|
|
|
|
#define DND_DragStatus (nsIDragSessionOS2::DND_DRAGSTATUS)
|
|
|
|
#define DND_DispatchEnterEvent (nsIDragSessionOS2::DND_DISPATCHENTEREVENT)
|
|
|
|
#define DND_DispatchEvent (nsIDragSessionOS2::DND_DISPATCHEVENT)
|
|
|
|
#define DND_GetDragoverResult (nsIDragSessionOS2::DND_GETDRAGOVERRESULT)
|
|
|
|
#define DND_ExitSession (nsIDragSessionOS2::DND_EXITSESSION)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// App Command messages for IntelliMouse and Natural Keyboard Pro
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
#define WM_APPCOMMAND 0x0319
|
|
|
|
|
|
|
|
#define APPCOMMAND_BROWSER_BACKWARD 1
|
|
|
|
#define APPCOMMAND_BROWSER_FORWARD 2
|
|
|
|
#define APPCOMMAND_BROWSER_REFRESH 3
|
|
|
|
#define APPCOMMAND_BROWSER_STOP 4
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Keyboard-related macros
|
|
|
|
|
|
|
|
// Used for character-to-keycode translation
|
|
|
|
#define PMSCAN_PADMULT 0x37
|
|
|
|
#define PMSCAN_PAD7 0x47
|
|
|
|
#define PMSCAN_PAD8 0x48
|
|
|
|
#define PMSCAN_PAD9 0x49
|
|
|
|
#define PMSCAN_PADMINUS 0x4A
|
|
|
|
#define PMSCAN_PAD4 0x4B
|
|
|
|
#define PMSCAN_PAD5 0x4C
|
|
|
|
#define PMSCAN_PAD6 0x4D
|
|
|
|
#define PMSCAN_PADPLUS 0x4E
|
|
|
|
#define PMSCAN_PAD1 0x4F
|
|
|
|
#define PMSCAN_PAD2 0x50
|
|
|
|
#define PMSCAN_PAD3 0x51
|
|
|
|
#define PMSCAN_PAD0 0x52
|
|
|
|
#define PMSCAN_PADPERIOD 0x53
|
|
|
|
#define PMSCAN_PADDIV 0x5c
|
|
|
|
|
|
|
|
#define isNumPadScanCode(scanCode) !((scanCode < PMSCAN_PAD7) || \
|
|
|
|
(scanCode > PMSCAN_PADPERIOD) || \
|
|
|
|
(scanCode == PMSCAN_PADMULT) || \
|
|
|
|
(scanCode == PMSCAN_PADDIV) || \
|
|
|
|
(scanCode == PMSCAN_PADMINUS) || \
|
|
|
|
(scanCode == PMSCAN_PADPLUS))
|
|
|
|
|
|
|
|
#define isNumlockOn (WinGetKeyState(HWND_DESKTOP, VK_NUMLOCK) & 0x0001)
|
|
|
|
#define isKeyDown(vk) ((WinGetKeyState(HWND_DESKTOP,vk) & 0x8000) == 0x8000)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Miscellanea
|
|
|
|
|
|
|
|
// extract X & Y from a mouse msg mparam
|
|
|
|
#define XFROMMP(m) (SHORT(LOUSHORT(m)))
|
|
|
|
#define YFROMMP(m) (SHORT(HIUSHORT(m)))
|
|
|
|
|
|
|
|
// make these methods seem more appropriate in context
|
|
|
|
#define PM2NS_PARENT NS2PM_PARENT
|
|
|
|
#define PM2NS NS2PM
|
|
|
|
// used to identify plugin widgets (copied from nsPluginNativeWindowOS2.cpp)
|
|
|
|
#define NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION \
|
|
|
|
"MozillaPluginWindowPropertyAssociation"
|
|
|
|
// name of the window class used to clip plugins
|
|
|
|
#define kClipWndClass "nsClipWnd"
|
2013-06-11 05:12:07 -07:00
|
|
|
// IME caret not exist
|
|
|
|
#define NO_IME_CARET (static_cast<ULONG>(-1))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Debug
|
|
|
|
#ifdef DEBUG_FOCUS
|
|
|
|
#define DEBUGFOCUS(what) fprintf(stderr, "[%8x] %8lx (%02d) "#what"\n", \
|
|
|
|
(int)this, mWnd, mWindowIdentifier)
|
|
|
|
#else
|
|
|
|
#define DEBUGFOCUS(what)
|
|
|
|
#endif
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Variables & Forward declarations
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Miscellaneous global flags
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t gOS2Flags = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Mouse pointers
|
|
|
|
static HPOINTER sPtrArray[IDC_COUNT];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// location of last MB1 down - used for mouse-based copy/paste
|
|
|
|
static POINTS sLastButton1Down = {0,0};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// set when any nsWindow is being dragged over
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t sDragStatus = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
#ifdef DEBUG_FOCUS
|
|
|
|
int currentWindowIdentifier = 0;
|
|
|
|
#endif
|
2012-06-20 03:09:05 -07:00
|
|
|
// IME stuffs
|
|
|
|
static HMODULE sIm32Mod = NULLHANDLE;
|
|
|
|
static APIRET (APIENTRY *spfnImGetInstance)(HWND, PHIMI);
|
|
|
|
static APIRET (APIENTRY *spfnImReleaseInstance)(HWND, HIMI);
|
|
|
|
static APIRET (APIENTRY *spfnImGetConversionString)(HIMI, ULONG, PVOID,
|
|
|
|
PULONG);
|
|
|
|
static APIRET (APIENTRY *spfnImGetResultString)(HIMI, ULONG, PVOID, PULONG);
|
|
|
|
static APIRET (APIENTRY *spfnImRequestIME)(HIMI, ULONG, ULONG, ULONG);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t WMChar2KeyCode(MPARAM mp1, MPARAM mp2);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// nsWindow Create / Destroy
|
|
|
|
//=============================================================================
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow::nsWindow() : nsBaseWidget()
|
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
mWnd = 0;
|
|
|
|
mParent = 0;
|
2010-03-06 09:52:10 -08:00
|
|
|
mFrame = 0;
|
|
|
|
mWindowType = eWindowType_toplevel;
|
2010-03-04 10:19:41 -08:00
|
|
|
mBorderStyle = eBorderStyle_default;
|
|
|
|
mWindowState = nsWindowState_ePrecreate;
|
2011-10-17 07:59:28 -07:00
|
|
|
mOnDestroyCalled = false;
|
|
|
|
mIsDestroying = false;
|
|
|
|
mInSetFocus = false;
|
|
|
|
mNoPaint = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
mDragHps = 0;
|
|
|
|
mDragStatus = 0;
|
|
|
|
mClipWnd = 0;
|
|
|
|
mCssCursorHPtr = 0;
|
|
|
|
mThebesSurface = 0;
|
2012-06-20 03:09:05 -07:00
|
|
|
mIsComposing = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!gOS2Flags) {
|
|
|
|
InitGlobals();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
|
|
|
// How destruction works: A call of Destroy() destroys the PM window. This
|
|
|
|
// triggers an OnDestroy(), which frees resources. If not Destroy'd at
|
|
|
|
// delete time, Destroy() gets called anyway.
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// NOTE: Calling virtual functions from destructors is bad; they always
|
|
|
|
// bind in the current object (ie. as if they weren't virtual). It
|
|
|
|
// may even be illegal to call them from here.
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsDestroying = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mCssCursorHPtr) {
|
|
|
|
WinDestroyPointer(mCssCursorHPtr);
|
|
|
|
mCssCursorHPtr = 0;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If the widget was released without calling Destroy() then
|
|
|
|
// the native window still exists, and we need to destroy it
|
|
|
|
if (!(mWindowState & nsWindowState_eDead)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mWindowState |= nsWindowState_eDoingDelete;
|
2010-03-04 10:19:41 -08:00
|
|
|
mWindowState &= ~(nsWindowState_eLive | nsWindowState_ePrecreate |
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowState_eInCreate);
|
2007-08-26 13:41:33 -07:00
|
|
|
Destroy();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-06 09:52:10 -08:00
|
|
|
|
2010-04-22 05:58:49 -07:00
|
|
|
// Once a plugin window has been destroyed,
|
|
|
|
// its parent, the clipping window, can be destroyed.
|
|
|
|
if (mClipWnd) {
|
|
|
|
WinDestroyWindow(mClipWnd);
|
|
|
|
mClipWnd = 0;
|
|
|
|
}
|
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// If it exists, destroy our os2FrameWindow helper object.
|
|
|
|
if (mFrame) {
|
|
|
|
delete mFrame;
|
|
|
|
mFrame = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Init Module-level variables.
|
|
|
|
|
|
|
|
// static
|
|
|
|
void nsWindow::InitGlobals()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
gOS2Flags = kIsInitialized;
|
|
|
|
|
|
|
|
// Register the MozillaWindowClass with PM.
|
|
|
|
WinRegisterClass(0, kWindowClassName, fnwpNSWindow, 0, 8);
|
|
|
|
|
|
|
|
// Register the dummy window class used to clip plugins.
|
|
|
|
WinRegisterClass(0, kClipWndClass, WinDefWindowProc, 0, 4);
|
|
|
|
|
|
|
|
// Load the mouse pointers from the dll containing 'gOS2Flags'.
|
|
|
|
HMODULE hModResources = 0;
|
|
|
|
DosQueryModFromEIP(&hModResources, 0, 0, 0, 0, (ULONG)&gOS2Flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (int i = 0; i < IDC_COUNT; i++) {
|
2010-03-04 10:19:41 -08:00
|
|
|
sPtrArray[i] = WinLoadPointer(HWND_DESKTOP, hModResources, IDC_BASE+i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work out if the system is DBCS.
|
|
|
|
char buffer[16];
|
|
|
|
COUNTRYCODE cc = { 0 };
|
|
|
|
DosQueryDBCSEnv(sizeof(buffer), &cc, buffer);
|
|
|
|
if (buffer[0] || buffer[1]) {
|
|
|
|
gOS2Flags |= kIsDBCS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is ugly. The Thinkpad TrackPoint driver checks to see whether
|
|
|
|
// or not a window actually has a scroll bar as a child before sending
|
|
|
|
// it scroll messages. Needless to say, no Mozilla window has real scroll
|
|
|
|
// bars. So if you have the "os2.trackpoint" preference set, we put an
|
|
|
|
// invisible scroll bar on every child window so we can scroll.
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("os2.trackpoint", false)) {
|
2011-06-07 00:38:00 -07:00
|
|
|
gOS2Flags |= kIsTrackPoint;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-20 03:09:05 -07:00
|
|
|
|
|
|
|
InitIME();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-20 03:09:05 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Determine whether to use IME
|
|
|
|
static
|
|
|
|
void InitIME()
|
|
|
|
{
|
|
|
|
if (!getenv("MOZ_IME_OVERTHESPOT")) {
|
|
|
|
CHAR szName[CCHMAXPATH];
|
|
|
|
ULONG rc;
|
|
|
|
|
|
|
|
rc = DosLoadModule(szName, sizeof(szName), "os2im", &sIm32Mod);
|
|
|
|
|
|
|
|
if (!rc)
|
2013-10-08 11:47:49 -07:00
|
|
|
rc = DosQueryProcAddr(sIm32Mod, 104, nullptr,
|
2012-06-20 03:09:05 -07:00
|
|
|
(PFN *)&spfnImGetInstance);
|
|
|
|
|
|
|
|
if (!rc)
|
2013-10-08 11:47:49 -07:00
|
|
|
rc = DosQueryProcAddr(sIm32Mod, 106, nullptr,
|
2012-06-20 03:09:05 -07:00
|
|
|
(PFN *)&spfnImReleaseInstance);
|
|
|
|
|
|
|
|
if (!rc)
|
2013-10-08 11:47:49 -07:00
|
|
|
rc = DosQueryProcAddr(sIm32Mod, 118, nullptr,
|
2012-06-20 03:09:05 -07:00
|
|
|
(PFN *)&spfnImGetConversionString);
|
|
|
|
|
|
|
|
if (!rc)
|
2013-10-08 11:47:49 -07:00
|
|
|
rc = DosQueryProcAddr(sIm32Mod, 122, nullptr,
|
2012-06-20 03:09:05 -07:00
|
|
|
(PFN *)&spfnImGetResultString);
|
|
|
|
|
|
|
|
if (!rc)
|
2013-10-08 11:47:49 -07:00
|
|
|
rc = DosQueryProcAddr(sIm32Mod, 131, nullptr,
|
2012-06-20 03:09:05 -07:00
|
|
|
(PFN *)&spfnImRequestIME);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
DosFreeModule(sIm32Mod);
|
|
|
|
|
|
|
|
sIm32Mod = NULLHANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Release Module-level variables.
|
|
|
|
|
|
|
|
// static
|
|
|
|
void nsWindow::ReleaseGlobals()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
for (int i = 0; i < IDC_COUNT; i++) {
|
|
|
|
WinDestroyPointer(sPtrArray[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-03-06 09:52:10 -08:00
|
|
|
// Init an nsWindow & create the appropriate native window.
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
NS_METHOD nsWindow::Create(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext* aContext,
|
2010-03-04 10:19:41 -08:00
|
|
|
nsWidgetInitData* aInitData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
mWindowState = nsWindowState_eInCreate;
|
|
|
|
|
|
|
|
// Identify the parent's nsWindow & native window. Only one of these
|
|
|
|
// should be supplied. Note: only nsWindow saves pParent as mParent;
|
2010-03-06 09:52:10 -08:00
|
|
|
// os2FrameWindow discards it since toplevel widgets have no parent.
|
2010-03-04 10:19:41 -08:00
|
|
|
HWND hParent;
|
|
|
|
nsWindow* pParent;
|
|
|
|
if (aParent) {
|
|
|
|
hParent = (HWND)aParent->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
pParent = (nsWindow*)aParent;
|
|
|
|
} else {
|
|
|
|
if (aNativeParent && (HWND)aNativeParent != HWND_DESKTOP) {
|
|
|
|
hParent = (HWND)aNativeParent;
|
|
|
|
pParent = GetNSWindowPtr(hParent);
|
|
|
|
} else {
|
|
|
|
hParent = HWND_DESKTOP;
|
|
|
|
pParent = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aInitData);
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
#ifdef DEBUG_FOCUS
|
|
|
|
mWindowIdentifier = currentWindowIdentifier;
|
|
|
|
currentWindowIdentifier++;
|
|
|
|
#endif
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Some basic initialization.
|
|
|
|
if (aInitData) {
|
2010-08-21 12:51:00 -07:00
|
|
|
// Suppress creation of a Thebes surface for windows that will never
|
|
|
|
// be painted because they're always covered by another window.
|
|
|
|
if (mWindowType == eWindowType_toplevel ||
|
2010-09-20 06:40:13 -07:00
|
|
|
mWindowType == eWindowType_invisible) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNoPaint = true;
|
2010-08-21 12:51:00 -07:00
|
|
|
}
|
2010-10-14 14:12:26 -07:00
|
|
|
// Popup windows should not have an nsWindow parent.
|
|
|
|
else if (mWindowType == eWindowType_popup) {
|
|
|
|
pParent = 0;
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// For toplevel windows, create an instance of our helper class,
|
|
|
|
// then have it create a frame & client window; otherwise,
|
|
|
|
// call our own CreateWindow() method to create a child window.
|
|
|
|
if (mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog ||
|
|
|
|
mWindowType == eWindowType_invisible) {
|
|
|
|
mFrame = new os2FrameWindow(this);
|
|
|
|
NS_ENSURE_TRUE(mFrame, NS_ERROR_FAILURE);
|
|
|
|
mWnd = mFrame->CreateFrameWindow(pParent, hParent, aRect,
|
|
|
|
mWindowType, mBorderStyle);
|
|
|
|
NS_ENSURE_TRUE(mWnd, NS_ERROR_FAILURE);
|
|
|
|
} else {
|
|
|
|
nsresult rv = CreateWindow(pParent, hParent, aRect, aInitData);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// Store a pointer to this object in the window's extra bytes.
|
2010-03-04 10:19:41 -08:00
|
|
|
SetNSWindowPtr(mWnd, this);
|
|
|
|
|
|
|
|
// Finalize the widget creation process.
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent event(true, NS_CREATE, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
InitEvent(event);
|
|
|
|
DispatchWindowEvent(&event);
|
|
|
|
|
|
|
|
mWindowState = nsWindowState_eLive;
|
2010-03-06 09:52:10 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Create a native window for an nsWindow object.
|
|
|
|
|
|
|
|
nsresult nsWindow::CreateWindow(nsWindow* aParent,
|
|
|
|
HWND aParentWnd,
|
|
|
|
const nsIntRect& aRect,
|
2010-03-06 09:52:10 -08:00
|
|
|
nsWidgetInitData* aInitData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
// For pop-ups, the Desktop is the parent and aParentWnd is the owner.
|
|
|
|
HWND hOwner = 0;
|
|
|
|
if (mWindowType == eWindowType_popup && aParentWnd != HWND_DESKTOP) {
|
|
|
|
hOwner = aParentWnd;
|
|
|
|
aParentWnd = HWND_DESKTOP;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// While we comply with the clipSiblings flag, we always set
|
|
|
|
// clipChildren regardless of the flag for performance reasons.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
|
2010-03-06 09:52:10 -08:00
|
|
|
if (aInitData && !aInitData->clipSiblings) {
|
|
|
|
style &= ~WS_CLIPSIBLINGS;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Create the window hidden; it will be resized below.
|
|
|
|
mWnd = WinCreateWindow(aParentWnd,
|
|
|
|
kWindowClassName,
|
|
|
|
0,
|
2010-03-06 09:52:10 -08:00
|
|
|
style,
|
2010-03-04 10:19:41 -08:00
|
|
|
0, 0, 0, 0,
|
|
|
|
hOwner,
|
|
|
|
HWND_TOP,
|
|
|
|
0,
|
|
|
|
0, 0);
|
|
|
|
NS_ENSURE_TRUE(mWnd, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// If a TrackPoint is in use, create dummy scrollbars.
|
|
|
|
// XXX Popups may need this also to scroll comboboxes.
|
|
|
|
if ((gOS2Flags & kIsTrackPoint) && mWindowType == eWindowType_child) {
|
|
|
|
WinCreateWindow(mWnd, WC_SCROLLBAR, 0, SBS_VERT,
|
|
|
|
0, 0, 0, 0, mWnd, HWND_TOP,
|
|
|
|
FID_VERTSCROLL, 0, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
// Store the window's dimensions, then resize accordingly.
|
|
|
|
mBounds = aRect;
|
|
|
|
nsIntRect parRect;
|
|
|
|
if (aParent) {
|
|
|
|
aParent->GetBounds(parRect);
|
|
|
|
} else {
|
|
|
|
parRect.height = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
WinSetWindowPos(mWnd, 0,
|
|
|
|
aRect.x, parRect.height - aRect.y - aRect.height,
|
|
|
|
aRect.width, aRect.height, SWP_SIZE | SWP_MOVE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Store the widget's parent and add it to the parent's list of children.
|
|
|
|
// Don't ADDREF mParent because AddChild() ADDREFs us.
|
|
|
|
mParent = aParent;
|
|
|
|
if (mParent) {
|
|
|
|
mParent->AddChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGFOCUS(Create nsWindow);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Close this nsWindow.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_METHOD nsWindow::Destroy()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
// avoid calling into other objects if we're being deleted, 'cos
|
|
|
|
// they must have no references to us.
|
|
|
|
if ((mWindowState & nsWindowState_eLive) && mParent) {
|
|
|
|
nsBaseWidget::Destroy();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// just to be safe. If we're going away and for some reason we're still
|
|
|
|
// the rollup widget, rollup and turn off capture.
|
2012-10-26 06:15:22 -07:00
|
|
|
nsIRollupListener* rollupListener = GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget;
|
|
|
|
if (rollupListener) {
|
|
|
|
rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
}
|
2012-10-26 06:15:22 -07:00
|
|
|
if (this == rollupWidget) {
|
|
|
|
rollupListener->Rollup(UINT32_MAX);
|
2012-07-30 07:20:58 -07:00
|
|
|
CaptureRollupEvents(nullptr, false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
HWND hMain = GetMainWindow();
|
2010-03-04 10:19:41 -08:00
|
|
|
if (hMain) {
|
|
|
|
DEBUGFOCUS(Destroy);
|
|
|
|
if (hMain == WinQueryFocus(HWND_DESKTOP)) {
|
|
|
|
WinSetFocus(HWND_DESKTOP, WinQueryWindow(hMain, QW_PARENT));
|
|
|
|
}
|
|
|
|
WinDestroyWindow(hMain);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Standard Window Operations
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// This can't be inlined in nsWindow.h because it doesn't know about
|
|
|
|
// GetFrameWnd().
|
|
|
|
|
|
|
|
inline HWND nsWindow::GetMainWindow()
|
|
|
|
{
|
|
|
|
return mFrame ? mFrame->GetFrameWnd() : mWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Inline this here for consistency (and a cleaner looking .h).
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// static
|
2010-03-06 09:52:10 -08:00
|
|
|
inline nsWindow* nsWindow::GetNSWindowPtr(HWND aWnd)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
return (nsWindow*)WinQueryWindowPtr(aWnd, QWL_NSWINDOWPTR);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool nsWindow::SetNSWindowPtr(HWND aWnd, nsWindow* aPtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
return WinSetWindowPtr(aWnd, QWL_NSWINDOWPTR, aPtr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsIWidget* nsWindow::GetParent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
// if this window isn't supposed to have a parent or it doesn't have
|
|
|
|
// a parent, or if it or its parent is being destroyed, return null
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame || mIsDestroying || mOnDestroyCalled ||
|
2010-03-04 10:19:41 -08:00
|
|
|
!mParent || mParent->mIsDestroying) {
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return mParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsWindow::Enable(bool aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
HWND hMain = GetMainWindow();
|
|
|
|
if (hMain) {
|
|
|
|
WinEnableWindow(hMain, aState);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-22 22:19:08 -07:00
|
|
|
bool nsWindow::IsEnabled() const
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
HWND hMain = GetMainWindow();
|
2012-07-22 22:19:08 -07:00
|
|
|
return !hMain || WinIsWindowEnabled(hMain);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsWindow::Show(bool aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame) {
|
|
|
|
return mFrame->Show(aState);
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
if (mWnd) {
|
|
|
|
if (aState) {
|
|
|
|
// don't try to show new windows (e.g. the Bookmark menu)
|
|
|
|
// during a native dragover because they'll remain invisible;
|
|
|
|
if (CheckDragStatus(ACTION_SHOW, 0)) {
|
2012-07-19 01:57:50 -07:00
|
|
|
if (!IsVisible()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
PlaceBehind(eZPlacementTop, 0, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
WinShowWindow(mWnd, true);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
WinShowWindow(mWnd, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
bool nsWindow::IsVisible() const
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2012-07-19 01:57:50 -07:00
|
|
|
return WinIsWindowVisible(GetMainWindow());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsWindow::SetFocus(bool aRaise)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
// for toplevel windows, this is directed to the client (i.e. mWnd)
|
|
|
|
if (mWnd) {
|
|
|
|
if (!mInSetFocus) {
|
|
|
|
DEBUGFOCUS(SetFocus);
|
2011-10-17 07:59:28 -07:00
|
|
|
mInSetFocus = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
WinSetFocus(HWND_DESKTOP, mWnd);
|
2011-10-17 07:59:28 -07:00
|
|
|
mInSetFocus = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-23 19:52:21 -08:00
|
|
|
NS_METHOD nsWindow::Invalidate(const nsIntRect& aRect)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
if (mWnd) {
|
|
|
|
RECTL rcl = {aRect.x, aRect.y, aRect.x + aRect.width, aRect.y + aRect.height};
|
|
|
|
NS2PM(rcl);
|
2011-10-17 07:59:28 -07:00
|
|
|
WinInvalidateRect(mWnd, &rcl, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Create a Thebes surface using the current window handle.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
gfxASurface* nsWindow::GetThebesSurface()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
if (mWnd && !mThebesSurface) {
|
|
|
|
mThebesSurface = new gfxOS2Surface(mWnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
return mThebesSurface;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-21 12:51:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Internal-only method that suppresses creation of a Thebes surface
|
|
|
|
// for windows that aren't supposed to be visible. If one was created
|
|
|
|
// by an external call to GetThebesSurface(), it will be returned.
|
|
|
|
|
|
|
|
gfxASurface* nsWindow::ConfirmThebesSurface()
|
|
|
|
{
|
|
|
|
if (!mThebesSurface && !mNoPaint && mWnd) {
|
|
|
|
mThebesSurface = new gfxOS2Surface(mWnd);
|
|
|
|
}
|
|
|
|
return mThebesSurface;
|
|
|
|
}
|
|
|
|
|
2010-10-14 14:12:26 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
float nsWindow::GetDPI()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t sDPI = 0;
|
2010-10-14 14:12:26 -07:00
|
|
|
|
|
|
|
// Create DC compatible with the screen, then query the DPI setting.
|
|
|
|
// If this fails, fall back to something sensible.
|
|
|
|
if (!sDPI) {
|
|
|
|
HDC dc = DevOpenDC(0, OD_MEMORY,"*",0L, 0, 0);
|
|
|
|
if (dc > 0) {
|
|
|
|
LONG lDPI;
|
|
|
|
if (DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &lDPI))
|
|
|
|
sDPI = lDPI;
|
|
|
|
DevCloseDC(dc);
|
|
|
|
}
|
|
|
|
if (sDPI <= 0) {
|
|
|
|
sDPI = 96;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sDPI;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Return some native data according to aDataType.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void* nsWindow::GetNativeData(uint32_t aDataType)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
switch(aDataType) {
|
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
return (void*)mWnd;
|
|
|
|
|
|
|
|
// during a native drag over the current window or any drag
|
|
|
|
// originating in Moz, return a drag HPS to avoid screen corruption;
|
|
|
|
case NS_NATIVE_GRAPHIC: {
|
|
|
|
HPS hps = 0;
|
|
|
|
CheckDragStatus(ACTION_DRAW, &hps);
|
|
|
|
if (!hps) {
|
|
|
|
hps = WinGetPS(mWnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
return (void*)hps;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void nsWindow::FreeNativeData(void* data, uint32_t aDataType)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
// an HPS is the only native data that needs to be freed
|
|
|
|
if (aDataType == NS_NATIVE_GRAPHIC &&
|
|
|
|
data &&
|
|
|
|
!ReleaseIfDragHPS((HPS)data)) {
|
|
|
|
WinReleasePS((HPS)data);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsWindow::CaptureMouse(bool aCapture)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
if (aCapture) {
|
|
|
|
WinSetCapture(HWND_DESKTOP, mWnd);
|
|
|
|
} else {
|
|
|
|
WinSetCapture(HWND_DESKTOP, 0);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::HasPendingInputEvent()
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
return (WinQueryQueueStatus(HWND_DESKTOP) & (QS_KEY | QS_MOUSE)) != 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Window Positioning
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// For toplevel windows, mBounds contains the dimensions of the client
|
|
|
|
// window. os2FrameWindow's "override" returns the size of the frame.
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_METHOD nsWindow::GetBounds(nsIntRect& aRect)
|
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame) {
|
|
|
|
return mFrame->GetBounds(aRect);
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
aRect = mBounds;
|
2009-09-23 23:18:10 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-03-06 09:52:10 -08:00
|
|
|
// Since mBounds contains the dimensions of the client, os2FrameWindow
|
|
|
|
// doesn't have to provide any special handling for this method.
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
NS_METHOD nsWindow::GetClientBounds(nsIntRect& aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-01 13:35:42 -08:00
|
|
|
aRect = mBounds;
|
2010-03-04 10:19:41 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
nsIntPoint nsWindow::WidgetToScreenOffset()
|
|
|
|
{
|
|
|
|
POINTL point = { 0, 0 };
|
|
|
|
NS2PM(point);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
WinMapWindowPoints(mWnd, HWND_DESKTOP, &point, 1);
|
|
|
|
return nsIntPoint(point.x,
|
|
|
|
WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) - point.y - 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Transform Y values between PM & XP coordinate systems.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// ptl is in this window's space
|
|
|
|
void nsWindow::NS2PM(POINTL& ptl)
|
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
ptl.y = mBounds.height - ptl.y - 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// rcl is in this window's space
|
|
|
|
void nsWindow::NS2PM(RECTL& rcl)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
LONG height = rcl.yTop - rcl.yBottom;
|
2010-03-06 09:52:10 -08:00
|
|
|
rcl.yTop = mBounds.height - rcl.yBottom;
|
2010-03-04 10:19:41 -08:00
|
|
|
rcl.yBottom = rcl.yTop - height;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ptl is in parent's space
|
2010-03-04 10:19:41 -08:00
|
|
|
void nsWindow::NS2PM_PARENT(POINTL& ptl)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
if (mParent) {
|
|
|
|
mParent->NS2PM(ptl);
|
|
|
|
} else {
|
2010-03-06 09:52:10 -08:00
|
|
|
HWND hParent = WinQueryWindow(mWnd, QW_PARENT);
|
2010-03-04 10:19:41 -08:00
|
|
|
SWP swp;
|
|
|
|
WinQueryWindowPos(hParent, &swp);
|
|
|
|
ptl.y = swp.cy - ptl.y - 1;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_METHOD nsWindow::Move(double aX, double aY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame) {
|
2012-12-12 01:57:38 -08:00
|
|
|
nsresult rv = mFrame->Move(NSToIntRound(aX), NSToIntRound(aY));
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2012-06-22 18:13:56 -07:00
|
|
|
return rv;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
Resize(aX, aY, mBounds.width, mBounds.height, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_METHOD nsWindow::Resize(double aWidth, double aHeight, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame) {
|
2012-12-12 01:57:38 -08:00
|
|
|
nsresult rv = mFrame->Resize(NSToIntRound(aWidth), NSToIntRound(aHeight),
|
|
|
|
aRepaint);
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2012-06-22 18:13:56 -07:00
|
|
|
return rv;
|
2010-03-06 09:52:10 -08:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
Resize(mBounds.x, mBounds.y, aWidth, aHeight, aRepaint);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_METHOD nsWindow::Resize(double aX, double aY,
|
|
|
|
double aWidth, double aHeight, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-12 01:57:38 -08:00
|
|
|
int32_t x = NSToIntRound(aX);
|
|
|
|
int32_t y = NSToIntRound(aY);
|
|
|
|
int32_t width = NSToIntRound(aWidth);
|
|
|
|
int32_t height = NSToIntRound(aHeight);
|
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame) {
|
2012-12-12 01:57:38 -08:00
|
|
|
nsresult rv = mFrame->Resize(x, y, width, height, aRepaint);
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2012-06-22 18:13:56 -07:00
|
|
|
return rv;
|
2010-03-06 09:52:10 -08:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// For mWnd & eWindowType_child set the cached values upfront, see bug 286555.
|
|
|
|
// For other mWnd types we defer transfer of values to mBounds to
|
|
|
|
// WinSetWindowPos(), see bug 391421.
|
|
|
|
|
|
|
|
if (!mWnd ||
|
|
|
|
mWindowType == eWindowType_child ||
|
|
|
|
mWindowType == eWindowType_plugin) {
|
2012-12-12 01:57:38 -08:00
|
|
|
mBounds.x = x;
|
|
|
|
mBounds.y = y;
|
|
|
|
mBounds.width = width;
|
|
|
|
mBounds.height = height;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// To keep top-left corner in the same place, use the new height
|
|
|
|
// to calculate the coordinates for the top & bottom left corners.
|
2008-03-18 02:35:49 -07:00
|
|
|
if (mWnd) {
|
2012-12-12 01:57:38 -08:00
|
|
|
POINTL ptl = { x, y };
|
2010-03-04 10:19:41 -08:00
|
|
|
NS2PM_PARENT(ptl);
|
2012-12-12 01:57:38 -08:00
|
|
|
ptl.y -= height - 1;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
// For popups, aX already gives the correct position.
|
|
|
|
if (mWindowType == eWindowType_popup) {
|
2012-12-12 01:57:38 -08:00
|
|
|
ptl.y = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) - height - 1 - y;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
else if (mParent) {
|
|
|
|
WinMapWindowPoints(mParent->mWnd, WinQueryWindow(mWnd, QW_PARENT),
|
|
|
|
&ptl, 1);
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
if (!WinSetWindowPos(mWnd, 0, ptl.x, ptl.y, width, height,
|
2010-03-04 10:19:41 -08:00
|
|
|
SWP_MOVE | SWP_SIZE) && aRepaint) {
|
|
|
|
WinInvalidateRect(mWnd, 0, FALSE);
|
2008-03-18 02:35:49 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2008-03-18 02:35:49 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_METHOD nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIWidget* aWidget, bool aActivate)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
HWND hBehind = HWND_TOP;
|
|
|
|
|
|
|
|
if (aPlacement == eZPlacementBottom) {
|
|
|
|
hBehind = HWND_BOTTOM;
|
|
|
|
} else
|
|
|
|
if (aPlacement == eZPlacementBelow && aWidget) {
|
|
|
|
hBehind = (static_cast<nsWindow*>(aWidget))->GetMainWindow();
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = SWP_ZORDER;
|
2010-03-04 10:19:41 -08:00
|
|
|
if (aActivate) {
|
2007-03-22 10:30:00 -07:00
|
|
|
flags |= SWP_ACTIVATE;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
WinSetWindowPos(GetMainWindow(), hBehind, 0, 0, 0, 0, flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Set widget's position within its parent child list.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_METHOD nsWindow::SetZIndex(int32_t aZIndex)
|
2008-03-18 02:35:49 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
// nsBaseWidget::SetZIndex() never has done anything sensible but
|
|
|
|
// has randomly placed widgets behind others (see bug 117730#c25).
|
2008-03-18 02:35:49 -07:00
|
|
|
// To get bug #353011 solved simply override it here to do nothing.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Plugin Operations
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Fire an NS_PLUGIN_ACTIVATE event whenever a window associated
|
|
|
|
// with a plugin widget get the focus.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
void nsWindow::ActivatePlugin(HWND aWnd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
// avoid acting on recursive WM_FOCUSCHANGED msgs
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool inPluginActivate = FALSE;
|
2010-03-04 10:19:41 -08:00
|
|
|
if (inPluginActivate) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// This property is used by the plugin window to store a pointer
|
|
|
|
// to its plugin object. We just use it as a convenient marker.
|
|
|
|
if (!WinQueryProperty(mWnd, NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION)) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Fire a plugin activation event on the plugin widget.
|
|
|
|
inPluginActivate = TRUE;
|
|
|
|
DEBUGFOCUS(NS_PLUGIN_ACTIVATE);
|
|
|
|
DispatchActivationEvent(NS_PLUGIN_ACTIVATE);
|
|
|
|
|
|
|
|
// Activating the plugin moves the focus off the child that had it,
|
|
|
|
// so try to restore it. If the WM_FOCUSCHANGED msg was synthesized
|
|
|
|
// by the plugin, then mp1 contains the child window that lost focus.
|
|
|
|
// Otherwise, just move it to the plugin's first child unless this
|
|
|
|
// is the mplayer plugin - doing so will put us into an endless loop.
|
|
|
|
// Since its children belong to another process, use the PID as a test.
|
|
|
|
HWND hFocus = 0;
|
|
|
|
if (WinIsChild(aWnd, mWnd)) {
|
|
|
|
hFocus = aWnd;
|
|
|
|
} else {
|
|
|
|
hFocus = WinQueryWindow(mWnd, QW_TOP);
|
|
|
|
if (hFocus) {
|
|
|
|
PID pidFocus, pidThis;
|
|
|
|
TID tid;
|
|
|
|
WinQueryWindowProcess(hFocus, &pidFocus, &tid);
|
|
|
|
WinQueryWindowProcess(mWnd, &pidThis, &tid);
|
|
|
|
if (pidFocus != pidThis) {
|
|
|
|
hFocus = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hFocus) {
|
|
|
|
WinSetFocus(HWND_DESKTOP, hFocus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
inPluginActivate = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This is invoked on a window that has plugin widget children
|
|
|
|
// to resize and clip those child windows.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
nsresult nsWindow::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
|
2010-03-04 10:19:41 -08:00
|
|
|
const Configuration& configuration = aConfigurations[i];
|
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
|
|
|
w->SetPluginClipRegion(configuration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This is invoked on a plugin window to resize it and set a persistent
|
|
|
|
// clipping region for it. Since the latter isn't possible on OS/2, it
|
|
|
|
// inserts a dummy window between the plugin widget and its parent to
|
|
|
|
// act as a clipping rectangle. The dummy window's dimensions and the
|
|
|
|
// plugin widget's position within the window are adjusted to correspond
|
|
|
|
// to the bounding box of the supplied array of clipping rectangles.
|
|
|
|
// Note: this uses PM calls rather than existing methods like Resize()
|
|
|
|
// and Update() because none of them support the options needed here.
|
|
|
|
|
|
|
|
void nsWindow::SetPluginClipRegion(const Configuration& aConfiguration)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_ASSERTION((mParent && mParent->mWnd), "Child window has no parent");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If nothing has changed, exit.
|
|
|
|
if (!StoreWindowClipRegion(aConfiguration.mClipRegion) &&
|
2011-04-18 20:07:23 -07:00
|
|
|
mBounds.IsEqualInterior(aConfiguration.mBounds)) {
|
2010-03-04 10:19:41 -08:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Set the widget's x/y to its nominal unclipped value. It doesn't
|
|
|
|
// affect our calculations but other code relies on it being correct.
|
|
|
|
mBounds.MoveTo(aConfiguration.mBounds.TopLeft());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Get or create the PM window we use as a clipping rectangle.
|
|
|
|
HWND hClip = GetPluginClipWindow(mParent->mWnd);
|
|
|
|
NS_ASSERTION(hClip, "No clipping window for plugin");
|
|
|
|
if (!hClip) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Create the bounding box for the clip region.
|
|
|
|
const nsTArray<nsIntRect>& rects = aConfiguration.mClipRegion;
|
|
|
|
nsIntRect r;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < rects.Length(); ++i) {
|
2010-03-04 10:19:41 -08:00
|
|
|
r.UnionRect(r, rects[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Size and position hClip to match the bounding box.
|
|
|
|
SWP swp;
|
|
|
|
POINTL ptl;
|
|
|
|
WinQueryWindowPos(hClip, &swp);
|
|
|
|
ptl.x = aConfiguration.mBounds.x + r.x;
|
|
|
|
ptl.y = mParent->mBounds.height
|
|
|
|
- (aConfiguration.mBounds.y + r.y + r.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
ULONG clipFlags = 0;
|
|
|
|
if (swp.x != ptl.x || swp.y != ptl.y) {
|
|
|
|
clipFlags |= SWP_MOVE;
|
|
|
|
}
|
|
|
|
if (swp.cx != r.width || swp.cy != r.height) {
|
|
|
|
clipFlags |= SWP_SIZE;
|
|
|
|
}
|
|
|
|
if (clipFlags) {
|
|
|
|
WinSetWindowPos(hClip, 0, ptl.x, ptl.y, r.width, r.height, clipFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Reducing the size of hClip clips the right & top sides of the
|
|
|
|
// plugin widget. To clip the left & bottom sides, we have to move
|
|
|
|
// the widget so its origin's x and/or y is negative wrt hClip.
|
|
|
|
WinQueryWindowPos(mWnd, &swp);
|
|
|
|
ptl.x = -r.x;
|
|
|
|
ptl.y = r.height + r.y - aConfiguration.mBounds.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
ULONG wndFlags = 0;
|
|
|
|
if (swp.x != ptl.x || swp.y != ptl.y) {
|
|
|
|
wndFlags |= SWP_MOVE;
|
|
|
|
}
|
|
|
|
if (mBounds.Size() != aConfiguration.mBounds.Size()) {
|
|
|
|
wndFlags |= SWP_SIZE;
|
|
|
|
}
|
|
|
|
if (wndFlags) {
|
|
|
|
WinSetWindowPos(mWnd, 0, ptl.x, ptl.y,
|
|
|
|
aConfiguration.mBounds.width,
|
|
|
|
aConfiguration.mBounds.height, wndFlags);
|
2009-11-02 11:10:07 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Some plugins don't resize themselves when the plugin widget changes
|
|
|
|
// size, so help them out by resizing the first child (usually a frame).
|
|
|
|
if (wndFlags & SWP_SIZE) {
|
|
|
|
HWND hChild = WinQueryWindow(mWnd, QW_TOP);
|
|
|
|
if (hChild) {
|
|
|
|
WinSetWindowPos(hChild, 0, 0, 0,
|
|
|
|
aConfiguration.mBounds.width,
|
|
|
|
aConfiguration.mBounds.height,
|
|
|
|
SWP_MOVE | SWP_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When hClip is resized, mWnd and its children may not get updated
|
|
|
|
// automatically, so invalidate & repaint them
|
|
|
|
if (clipFlags & SWP_SIZE) {
|
|
|
|
WinInvalidateRect(mWnd, 0, TRUE);
|
|
|
|
WinUpdateWindow(mWnd);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This gets or creates a window that's inserted between the main window
|
|
|
|
// and its plugin children. This window does nothing except act as a
|
|
|
|
// clipping rectangle for the plugin widget.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
HWND nsWindow::GetPluginClipWindow(HWND aParentWnd)
|
|
|
|
{
|
|
|
|
if (mClipWnd) {
|
|
|
|
return mClipWnd;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Insert a new clip window in the hierarchy between mWnd & aParentWnd.
|
|
|
|
mClipWnd = WinCreateWindow(aParentWnd, kClipWndClass, "",
|
|
|
|
WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
|
|
|
|
0, 0, 0, 0, 0, mWnd, 0, 0, 0);
|
|
|
|
if (mClipWnd) {
|
|
|
|
if (!WinSetParent(mWnd, mClipWnd, FALSE)) {
|
|
|
|
WinDestroyWindow(mClipWnd);
|
|
|
|
mClipWnd = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return mClipWnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Top-level (frame window) Operations
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// When a window gets the focus, call os2FrameWindow's version of this
|
2010-03-04 10:19:41 -08:00
|
|
|
// method. It will fire an NS_ACTIVATE event on the top-level widget
|
|
|
|
// if appropriate.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
void nsWindow::ActivateTopLevelWidget()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
if (mFrame) {
|
|
|
|
mFrame->ActivateTopLevelWidget();
|
|
|
|
} else {
|
|
|
|
nsWindow* top = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (top && top->mFrame) {
|
|
|
|
top->mFrame->ActivateTopLevelWidget();
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-03-06 09:52:10 -08:00
|
|
|
// All of these methods are inherently toplevel-only, and are in fact
|
|
|
|
// only invoked on toplevel widgets. If they're invoked on a child
|
|
|
|
// window, there's an error upstream.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsWindow::SetSizeMode(int32_t aMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
NS_ENSURE_TRUE(mFrame, NS_ERROR_UNEXPECTED);
|
|
|
|
return mFrame->SetSizeMode(aMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsWindow::HideWindowChrome(bool aShouldHide)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
NS_ENSURE_TRUE(mFrame, NS_ERROR_UNEXPECTED);
|
|
|
|
return mFrame->HideWindowChrome(aShouldHide);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_METHOD nsWindow::SetTitle(const nsAString& aTitle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
NS_ENSURE_TRUE(mFrame, NS_ERROR_UNEXPECTED);
|
|
|
|
return mFrame->SetTitle(aTitle);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsWindow::SetIcon(const nsAString& aIconSpec)
|
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
NS_ENSURE_TRUE(mFrame, NS_ERROR_UNEXPECTED);
|
|
|
|
return mFrame->SetIcon(aIconSpec);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsWindow::ConstrainPosition(bool aAllowSlop,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aX, int32_t* aY)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2010-03-06 09:52:10 -08:00
|
|
|
NS_ENSURE_TRUE(mFrame, NS_ERROR_UNEXPECTED);
|
|
|
|
return mFrame->ConstrainPosition(aAllowSlop, aX, aY);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// Mouse Pointers
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
// Set one of the standard mouse pointers.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
HPOINTER newPointer = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aCursor) {
|
|
|
|
case eCursor_select:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_TEXT, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_wait:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_hyperlink:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_SELECTANCHOR-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_standard:
|
2013-07-31 18:15:25 -07:00
|
|
|
case eCursor_context_menu: // XXX See bug 258960.
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_n_resize:
|
|
|
|
case eCursor_s_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZENS, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_w_resize:
|
|
|
|
case eCursor_e_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZEWE, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_nw_resize:
|
|
|
|
case eCursor_se_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZENWSE, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_ne_resize:
|
|
|
|
case eCursor_sw_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZENESW, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_crosshair:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_CROSS-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_move:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_MOVE, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_help:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_HELP-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_copy: // CSS3
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_COPY-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_alias:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_ALIAS-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_cell:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_CELL-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_grab:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_GRAB-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_grabbing:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_GRABBING-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_spinning:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_ARROWWAIT-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_zoom_in:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_ZOOMIN-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_zoom_out:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_ZOOMOUT-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_not_allowed:
|
|
|
|
case eCursor_no_drop:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_ILLEGAL, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_col_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_COLRESIZE-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_row_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_ROWRESIZE-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_vertical_text:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_VERTICALTEXT-IDC_BASE];
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_all_scroll:
|
|
|
|
// XXX not 100% appropriate perhaps
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_MOVE, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_nesw_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZENESW, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_nwse_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZENWSE, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_ns_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZENS, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_ew_resize:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = WinQuerySysPointer(HWND_DESKTOP, SPTR_SIZEWE, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2008-01-18 10:39:49 -08:00
|
|
|
case eCursor_none:
|
2010-03-04 10:19:41 -08:00
|
|
|
newPointer = sPtrArray[IDC_NONE-IDC_BASE];
|
2008-01-18 10:39:49 -08:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2009-08-14 07:09:00 -07:00
|
|
|
NS_ERROR("Invalid cursor type");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newPointer) {
|
|
|
|
WinSetPointer(HWND_DESKTOP, newPointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Create a mouse pointer on the fly to support the CSS 'cursor' style.
|
|
|
|
// This code is based on the Win version by C. Biesinger but has been
|
2007-03-22 10:30:00 -07:00
|
|
|
// substantially modified to accommodate platform differences and to
|
2010-03-04 10:19:41 -08:00
|
|
|
// improve efficiency.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsWindow::SetCursor(imgIContainer* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
// if this is the same image as last time, reuse the saved hptr;
|
|
|
|
// it will be destroyed when we create a new one or when the
|
|
|
|
// current window is destroyed
|
|
|
|
if (mCssCursorImg == aCursor && mCssCursorHPtr) {
|
|
|
|
WinSetPointer(HWND_DESKTOP, mCssCursorHPtr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-13 00:34:24 -08:00
|
|
|
nsRefPtr<gfxASurface> surface =
|
|
|
|
aCursor->GetFrame(imgIContainer::FRAME_CURRENT,
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE);
|
2013-03-05 15:39:48 -08:00
|
|
|
NS_ENSURE_TRUE(surface, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> frame(surface->GetAsReadableARGB32ImageSurface());
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_NOT_AVAILABLE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if the image is ridiculously large, exit because
|
|
|
|
// it will be unrecognizable when shrunk to 32x32
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t width = frame->Width();
|
|
|
|
int32_t height = frame->Height();
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_ENSURE_TRUE(width <= 128 && height <= 128, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t* data = frame->Data();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// create the color bitmap
|
2007-09-04 15:05:22 -07:00
|
|
|
HBITMAP hBmp = CreateBitmapRGB(data, width, height);
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_ENSURE_TRUE(hBmp, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-04 15:05:22 -07:00
|
|
|
// create a transparency mask from the alpha bytes
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
HBITMAP hAlpha = CreateTransparencyMask(frame->Format(), data, width, height);
|
2007-09-04 15:05:22 -07:00
|
|
|
if (!hAlpha) {
|
|
|
|
GpiDeleteBitmap(hBmp);
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
POINTERINFO info = {0};
|
|
|
|
info.fPointer = TRUE;
|
|
|
|
info.xHotspot = aHotspotX;
|
|
|
|
info.yHotspot = height - aHotspotY - 1;
|
|
|
|
info.hbmPointer = hAlpha;
|
|
|
|
info.hbmColor = hBmp;
|
|
|
|
|
|
|
|
// create the pointer
|
|
|
|
HPOINTER cursor = WinCreatePointerIndirect(HWND_DESKTOP, &info);
|
|
|
|
GpiDeleteBitmap(hBmp);
|
|
|
|
GpiDeleteBitmap(hAlpha);
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_ENSURE_TRUE(cursor, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// use it
|
|
|
|
WinSetPointer(HWND_DESKTOP, cursor);
|
|
|
|
|
|
|
|
// destroy the previous hptr; this has to be done after the
|
|
|
|
// new pointer is set or else WinDestroyPointer() will fail
|
2010-03-04 10:19:41 -08:00
|
|
|
if (mCssCursorHPtr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
WinDestroyPointer(mCssCursorHPtr);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// save the hptr and a reference to the image for next time
|
|
|
|
mCssCursorHPtr = cursor;
|
|
|
|
mCssCursorImg = aCursor;
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Render image or modified alpha data as a native bitmap.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// aligned bytes per row, rounded up to next dword bounday
|
|
|
|
#define ALIGNEDBPR(cx,bits) ( ( ( ((cx)*(bits)) + 31) / 32) * 4)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
HBITMAP nsWindow::DataToBitmap(uint8_t* aImageData, uint32_t aWidth,
|
|
|
|
uint32_t aHeight, uint32_t aDepth)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
// get a presentation space for this window
|
|
|
|
HPS hps = (HPS)GetNativeData(NS_NATIVE_GRAPHIC);
|
|
|
|
if (!hps) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// a handy structure that does double duty
|
|
|
|
// as both BITMAPINFOHEADER2 & BITMAPINFO2
|
|
|
|
struct {
|
|
|
|
BITMAPINFOHEADER2 head;
|
|
|
|
RGB2 black;
|
|
|
|
RGB2 white;
|
|
|
|
} bi;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
memset(&bi, 0, sizeof(bi));
|
|
|
|
bi.white.bBlue = (BYTE)255;
|
|
|
|
bi.white.bGreen = (BYTE)255;
|
|
|
|
bi.white.bRed = (BYTE)255;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// fill in the particulars
|
|
|
|
bi.head.cbFix = sizeof(bi.head);
|
|
|
|
bi.head.cx = aWidth;
|
|
|
|
bi.head.cy = aHeight;
|
|
|
|
bi.head.cPlanes = 1;
|
|
|
|
bi.head.cBitCount = aDepth;
|
|
|
|
bi.head.ulCompression = BCA_UNCOMP;
|
|
|
|
bi.head.cbImage = ALIGNEDBPR(aWidth, aDepth) * aHeight;
|
|
|
|
bi.head.cclrUsed = (aDepth == 1 ? 2 : 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// create a bitmap from the image data
|
|
|
|
HBITMAP hBmp = GpiCreateBitmap(hps, &bi.head, CBM_INIT,
|
|
|
|
reinterpret_cast<BYTE*>(aImageData),
|
|
|
|
(BITMAPINFO2*)&bi);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// free the hps, then return the bitmap
|
|
|
|
FreeNativeData((void*)hps, NS_NATIVE_GRAPHIC);
|
|
|
|
return hBmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Create an RGB24 bitmap from Cairo image data.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
HBITMAP nsWindow::CreateBitmapRGB(uint8_t* aImageData,
|
|
|
|
uint32_t aWidth,
|
|
|
|
uint32_t aHeight)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
// calc width in bytes, rounding up to a dword boundary
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t bpr = ALIGNEDBPR(aWidth, 24);
|
|
|
|
uint8_t* bmp = (uint8_t*)malloc(bpr * aHeight);
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!bmp) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* pSrc = (uint32_t*)aImageData;
|
|
|
|
for (uint32_t row = aHeight; row > 0; --row) {
|
|
|
|
uint8_t* pDst = bmp + bpr * (row - 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t col = aWidth; col > 0; --col) {
|
2010-03-04 10:19:41 -08:00
|
|
|
// In Cairo a color is encoded as ARGB in a DWORD
|
|
|
|
// stored in machine endianess.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t color = *pSrc++;
|
2010-03-04 10:19:41 -08:00
|
|
|
*pDst++ = color; // Blue
|
|
|
|
*pDst++ = color >> 8; // Green
|
|
|
|
*pDst++ = color >> 16; // Red
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// create the bitmap
|
|
|
|
HBITMAP hAlpha = DataToBitmap(bmp, aWidth, aHeight, 24);
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// free the buffer, then return the bitmap
|
|
|
|
free(bmp);
|
|
|
|
return hAlpha;
|
2009-10-12 02:10:38 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Create a monochrome AND/XOR bitmap from 0, 1, or 8-bit alpha data.
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2013-09-24 13:45:13 -07:00
|
|
|
HBITMAP nsWindow::CreateTransparencyMask(gfxImageFormat format,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t* aImageData,
|
|
|
|
uint32_t aWidth,
|
|
|
|
uint32_t aHeight)
|
2009-10-12 02:10:38 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
// calc width in bytes, rounding up to a dword boundary
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t abpr = ALIGNEDBPR(aWidth, 1);
|
|
|
|
uint32_t cbData = abpr * aHeight;
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// alloc and clear space to hold both the AND & XOR bitmaps
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t* mono = (uint8_t*)calloc(cbData, 2);
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!mono) {
|
|
|
|
return 0;
|
2009-10-12 02:10:38 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Non-alpha formats are already taken care of
|
|
|
|
// by initializing the XOR and AND masks to zero
|
2013-09-24 13:45:13 -07:00
|
|
|
if (format == gfxImageFormatARGB32) {
|
2009-10-12 02:10:38 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// make the AND mask the inverse of the 8-bit alpha data
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* pSrc = (int32_t*)aImageData;
|
|
|
|
for (uint32_t row = aHeight; row > 0; --row) {
|
2010-03-04 10:19:41 -08:00
|
|
|
// Point to the right row in the AND mask
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t* pDst = mono + cbData + abpr * (row - 1);
|
|
|
|
uint8_t mask = 0x80;
|
|
|
|
for (uint32_t col = aWidth; col > 0; --col) {
|
2010-03-04 10:19:41 -08:00
|
|
|
// Use the sign bit to test for transparency, as the alpha byte
|
|
|
|
// is highest byte. Positive means, alpha < 128, so consider it
|
|
|
|
// as transparent and set the AND mask.
|
|
|
|
if (*pSrc++ >= 0) {
|
|
|
|
*pDst |= mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask >>= 1;
|
|
|
|
if (!mask) {
|
|
|
|
pDst++;
|
|
|
|
mask = 0x80;
|
|
|
|
}
|
2009-10-12 02:10:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// create the bitmap
|
|
|
|
HBITMAP hAlpha = DataToBitmap(mono, aWidth, aHeight * 2, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// free the buffer, then return the bitmap
|
|
|
|
free(mono);
|
|
|
|
return hAlpha;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Rollup Event Handlers
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener* aListener,
|
2012-10-26 06:15:22 -07:00
|
|
|
bool aDoCapture)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-26 06:15:22 -07:00
|
|
|
gRollupListener = aDoCapture ? aListener : nullptr;
|
2010-03-04 10:19:41 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::EventIsInsideWindow(nsWindow* aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
RECTL rcl;
|
|
|
|
POINTL ptl;
|
2012-12-31 09:27:04 -08:00
|
|
|
NS_ENSURE_TRUE(aWindow, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
if (WinQueryMsgPos(0, &ptl)) {
|
|
|
|
WinMapWindowPoints(HWND_DESKTOP, aWindow->mWnd, &ptl, 1);
|
|
|
|
WinQueryWindowRect(aWindow->mWnd, &rcl);
|
|
|
|
|
|
|
|
// now make sure that it wasn't one of our children
|
|
|
|
if (ptl.x < rcl.xLeft || ptl.x > rcl.xRight ||
|
|
|
|
ptl.y > rcl.yTop || ptl.y < rcl.yBottom) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Handle events that would cause a popup (combobox, menu, etc) to rollup.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::RollupOnButtonDown(ULONG aMsg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-26 06:15:22 -07:00
|
|
|
nsIRollupListener* rollupListener = nsBaseWidget::GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget;
|
|
|
|
if (rollupListener) {
|
|
|
|
rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
}
|
2012-10-26 06:15:22 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Exit if the event is inside the most recent popup.
|
2012-10-26 06:15:22 -07:00
|
|
|
if (EventIsInsideWindow((nsWindow*)rollupWidget)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// See if we're dealing with a menu. If so, exit if the
|
|
|
|
// event was inside a parent of the current submenu.
|
2012-09-27 23:57:33 -07:00
|
|
|
uint32_t popupsToRollup = UINT32_MAX;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
if (rollupListener) {
|
2010-03-04 10:19:41 -08:00
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
2012-10-26 06:15:22 -07:00
|
|
|
uint32_t sameTypeCount = rollupListener->GetSubmenuWidgetChain(&widgetChain);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < widgetChain.Length(); ++i) {
|
2010-03-04 10:19:41 -08:00
|
|
|
nsIWidget* widget = widgetChain[i];
|
|
|
|
if (EventIsInsideWindow((nsWindow*)widget)) {
|
|
|
|
if (i < sameTypeCount) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // for each parent menu widget
|
|
|
|
} // if rollup listener knows about menus
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// We only need to deal with the last rollup for left mouse down events.
|
2011-11-08 11:59:07 -08:00
|
|
|
NS_ASSERTION(!mLastRollup, "mLastRollup is null");
|
2012-10-26 06:15:22 -07:00
|
|
|
bool consumeRollupEvent =
|
|
|
|
rollupListener->Rollup(popupsToRollup, aMsg == WM_LBUTTONDOWN ? &mLastRollup : nullptr);
|
2011-11-08 11:59:07 -08:00
|
|
|
NS_IF_ADDREF(mLastRollup);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If true, the buttondown event won't be passed on to the wndproc.
|
2012-10-26 06:15:22 -07:00
|
|
|
return consumeRollupEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// static
|
|
|
|
void nsWindow::RollupOnFocusLost(HWND aFocus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-26 06:15:22 -07:00
|
|
|
nsIRollupListener* rollupListener = nsBaseWidget::GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget;
|
|
|
|
if (rollupListener) {
|
|
|
|
rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
}
|
2013-10-08 11:47:49 -07:00
|
|
|
HWND hRollup = rollupWidget ? ((nsWindow*)rollupWidget)->mWnd : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Exit if focus was lost to the most recent popup.
|
|
|
|
if (hRollup == aFocus) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Exit if focus was lost to a parent of the current submenu.
|
2012-10-26 06:15:22 -07:00
|
|
|
if (rollupListener) {
|
2010-03-04 10:19:41 -08:00
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
2012-10-26 06:15:22 -07:00
|
|
|
rollupListener->GetSubmenuWidgetChain(&widgetChain);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < widgetChain.Length(); ++i) {
|
2010-03-04 10:19:41 -08:00
|
|
|
if (((nsWindow*)widgetChain[i])->mWnd == aFocus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
// Rollup all popups.
|
|
|
|
rollupListener->Rollup(UINT32_MAX);
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// nsWindow's Window Procedure
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// This is the actual wndproc; it does some preprocessing then passes
|
|
|
|
// the msgs to the ProcessMessage() method which does most of the work.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
MRESULT EXPENTRY fnwpNSWindow(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|
|
|
{
|
|
|
|
nsAutoRollup autoRollup;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If this window doesn't have an object ptr,
|
|
|
|
// send the msg to the default wndproc.
|
|
|
|
nsWindow* wnd = nsWindow::GetNSWindowPtr(hwnd);
|
|
|
|
if (!wnd) {
|
|
|
|
return WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If we're not in the destructor, hold on to the object for the
|
|
|
|
// life of this method, in case it gets deleted during processing.
|
|
|
|
// Yes, it's a double hack since someWindow is not really an interface.
|
|
|
|
nsCOMPtr<nsISupports> kungFuDeathGrip;
|
|
|
|
if (!wnd->mIsDestroying) {
|
|
|
|
kungFuDeathGrip = do_QueryInterface((nsBaseWidget*)wnd);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Pre-process msgs that may cause a rollup.
|
2012-10-26 06:15:22 -07:00
|
|
|
}
|
|
|
|
switch (msg) {
|
|
|
|
case WM_BUTTON1DOWN:
|
|
|
|
case WM_BUTTON2DOWN:
|
|
|
|
case WM_BUTTON3DOWN:
|
|
|
|
if (nsWindow::RollupOnButtonDown(msg)) {
|
|
|
|
return (MRESULT)true;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
case WM_SETFOCUS:
|
|
|
|
if (!mp2) {
|
|
|
|
nsWindow::RollupOnFocusLost((HWND)mp1);
|
|
|
|
}
|
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return wnd->ProcessMessage(msg, mp1, mp2);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// In effect, nsWindow's real wndproc.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
MRESULT nsWindow::ProcessMessage(ULONG msg, MPARAM mp1, MPARAM mp2)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isDone = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
MRESULT mresult = 0;
|
|
|
|
|
|
|
|
switch (msg) {
|
|
|
|
|
|
|
|
// Interpret WM_QUIT as a close request so that
|
|
|
|
// windows can be closed from the Window List
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_QUIT: {
|
|
|
|
mWindowState |= nsWindowState_eClosing;
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent event(true, NS_XUL_CLOSE, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
InitEvent(event);
|
|
|
|
DispatchWindowEvent(&event);
|
|
|
|
// abort window closure
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_DESTROY:
|
|
|
|
OnDestroy();
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_PAINT:
|
|
|
|
isDone = OnPaint();
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_TRANSLATEACCEL:
|
|
|
|
isDone = OnTranslateAccelerator((PQMSG)mp1);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_CHAR:
|
|
|
|
isDone = DispatchKeyEvent(mp1, mp2);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Mouseclicks: we don't dispatch CLICK events because they just cause
|
|
|
|
// trouble: gecko seems to expect EITHER buttondown/up OR click events
|
|
|
|
// and so that's what we give it.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON1DOWN:
|
|
|
|
WinSetCapture(HWND_DESKTOP, mWnd);
|
2011-04-09 20:32:52 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, mp1, mp2);
|
|
|
|
// If this msg is forwarded to a popup's owner, Moz will cause the
|
|
|
|
// popup to be rolled-up in error when the owner processes the msg.
|
|
|
|
if (mWindowType == eWindowType_popup) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = true;
|
2011-04-09 20:32:52 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
// there's no need to clear this on button-up
|
|
|
|
sLastButton1Down.x = XFROMMP(mp1);
|
|
|
|
sLastButton1Down.y = YFROMMP(mp1);
|
|
|
|
break;
|
2007-10-22 10:59:24 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON1UP:
|
|
|
|
WinSetCapture(HWND_DESKTOP, 0);
|
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, mp1, mp2);
|
|
|
|
break;
|
2007-10-22 10:59:24 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON1DBLCLK:
|
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, mp1, mp2);
|
|
|
|
break;
|
2007-10-22 10:59:24 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON2DOWN:
|
|
|
|
WinSetCapture(HWND_DESKTOP, mWnd);
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, mp1, mp2, false,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eRightButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON2UP:
|
|
|
|
WinSetCapture(HWND_DESKTOP, 0);
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, mp1, mp2, false,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eRightButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON2DBLCLK:
|
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, mp1, mp2,
|
2013-10-01 23:38:27 -07:00
|
|
|
false, WidgetMouseEvent::eRightButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON3DOWN:
|
|
|
|
WinSetCapture(HWND_DESKTOP, mWnd);
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, mp1, mp2, false,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eMiddleButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON3UP:
|
|
|
|
WinSetCapture(HWND_DESKTOP, 0);
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, mp1, mp2, false,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eMiddleButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_BUTTON3DBLCLK:
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, mp1, mp2, false,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eMiddleButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_CONTEXTMENU:
|
|
|
|
if (SHORT2FROMMP(mp2)) {
|
|
|
|
HWND hFocus = WinQueryFocus(HWND_DESKTOP);
|
|
|
|
if (hFocus != mWnd) {
|
|
|
|
WinSendMsg(hFocus, msg, mp1, mp2);
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_CONTEXTMENU, mp1, mp2, true,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eLeftButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = DispatchMouseEvent(NS_CONTEXTMENU, mp1, mp2, false,
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent::eRightButton);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If MB1 & MB2 are both pressed, perform a copy or paste.
|
|
|
|
case WM_CHORD:
|
|
|
|
isDone = OnMouseChord(mp1, mp2);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_MOUSEMOVE: {
|
|
|
|
static POINTL ptlLastPos = { -1, -1 };
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If mouse has actually moved, remember the new position,
|
|
|
|
// then dispatch the event.
|
|
|
|
if (ptlLastPos.x != (SHORT)SHORT1FROMMP(mp1) ||
|
|
|
|
ptlLastPos.y != (SHORT)SHORT2FROMMP(mp1)) {
|
|
|
|
ptlLastPos.x = (SHORT)SHORT1FROMMP(mp1);
|
|
|
|
ptlLastPos.y = (SHORT)SHORT2FROMMP(mp1);
|
|
|
|
DispatchMouseEvent(NS_MOUSE_MOVE, mp1, mp2);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// don't propagate mouse move or the OS will change the pointer
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_MOUSEENTER:
|
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_ENTER, mp1, mp2);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
isDone = DispatchMouseEvent(NS_MOUSE_EXIT, mp1, mp2);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
case WM_APPCOMMAND: {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t appCommand = SHORT2FROMMP(mp2) & 0xfff;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
switch (appCommand) {
|
|
|
|
case APPCOMMAND_BROWSER_BACKWARD:
|
|
|
|
case APPCOMMAND_BROWSER_FORWARD:
|
|
|
|
case APPCOMMAND_BROWSER_REFRESH:
|
|
|
|
case APPCOMMAND_BROWSER_STOP:
|
|
|
|
DispatchCommandEvent(appCommand);
|
|
|
|
// tell the driver that we handled the event
|
|
|
|
mresult = (MRESULT)1;
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_HSCROLL:
|
|
|
|
case WM_VSCROLL:
|
|
|
|
isDone = DispatchScrollEvent(msg, mp1, mp2);
|
|
|
|
break;
|
|
|
|
|
2010-03-06 09:52:10 -08:00
|
|
|
// Do not act on WM_ACTIVATE - it is handled by os2FrameWindow.
|
2010-03-04 10:19:41 -08:00
|
|
|
// case WM_ACTIVATE:
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// This msg is used to activate top-level and plugin widgets
|
|
|
|
// after PM is done changing the focus. We're only interested
|
|
|
|
// in windows gaining focus, not in those losing it.
|
|
|
|
case WM_FOCUSCHANGED:
|
|
|
|
DEBUGFOCUS(WM_FOCUSCHANGED);
|
|
|
|
if (SHORT1FROMMP(mp2)) {
|
|
|
|
ActivateTopLevelWidget();
|
|
|
|
ActivatePlugin(HWNDFROMMP(mp1));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
case WM_WINDOWPOSCHANGED:
|
|
|
|
isDone = OnReposition((PSWP) mp1);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
// all msgs that occur when this window is the target of a drag
|
|
|
|
case DM_DRAGOVER:
|
|
|
|
case DM_DRAGLEAVE:
|
|
|
|
case DM_DROP:
|
|
|
|
case DM_RENDERCOMPLETE:
|
|
|
|
case DM_DROPHELP:
|
|
|
|
OnDragDropMsg(msg, mp1, mp2, mresult);
|
2011-10-17 07:59:28 -07:00
|
|
|
isDone = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2012-06-19 00:33:42 -07:00
|
|
|
case WM_QUERYCONVERTPOS:
|
|
|
|
isDone = OnQueryConvertPos(mp1, mresult);
|
|
|
|
break;
|
2012-06-20 03:09:05 -07:00
|
|
|
|
|
|
|
case WM_IMEREQUEST:
|
|
|
|
isDone = OnImeRequest(mp1, mp2);
|
|
|
|
break;
|
2012-06-19 00:33:42 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
// If an event handler signalled that we should consume the event,
|
|
|
|
// return. Otherwise, pass it on to the default wndproc.
|
|
|
|
if (!isDone) {
|
|
|
|
mresult = WinDefWindowProc(mWnd, msg, mp1, mp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mresult;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// Window Message Handlers
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
// WM_DESTROY has been called.
|
|
|
|
|
|
|
|
void nsWindow::OnDestroy()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mOnDestroyCalled = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
SetNSWindowPtr(mWnd, 0);
|
|
|
|
mWnd = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
// release references to context and children
|
2010-03-04 10:19:41 -08:00
|
|
|
nsBaseWidget::OnDestroy();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// dispatching of the event may cause the reference count to drop to 0
|
|
|
|
// and result in this object being deleted. To avoid that, add a
|
|
|
|
// reference and then release it after dispatching the event.
|
|
|
|
//
|
|
|
|
// It's important *not* to do this if we're being called from the
|
|
|
|
// destructor -- this would result in our destructor being called *again*
|
|
|
|
// from the Release() below. This is very bad...
|
|
|
|
if (!(nsWindowState_eDoingDelete & mWindowState)) {
|
|
|
|
AddRef();
|
2012-08-15 11:52:41 -07:00
|
|
|
NotifyWindowDestroyed();
|
2010-03-04 10:19:41 -08:00
|
|
|
Release();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// dead widget
|
|
|
|
mWindowState |= nsWindowState_eDead;
|
|
|
|
mWindowState &= ~(nsWindowState_eLive|nsWindowState_ePrecreate|
|
|
|
|
nsWindowState_eInCreate);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::OnReposition(PSWP pSwp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool result = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
if (pSwp->fl & SWP_MOVE && !(pSwp->fl & SWP_MINIMIZE)) {
|
|
|
|
HWND hParent = mParent ? mParent->mWnd : WinQueryWindow(mWnd, QW_PARENT);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// need screen coords.
|
|
|
|
POINTL ptl = { pSwp->x, pSwp->y + pSwp->cy - 1 };
|
|
|
|
// XXX - this is peculiar...
|
|
|
|
WinMapWindowPoints(WinQueryWindow(mWnd, QW_PARENT), hParent, &ptl, 1);
|
|
|
|
PM2NS_PARENT(ptl);
|
|
|
|
mBounds.x = ptl.x;
|
|
|
|
mBounds.y = ptl.y;
|
|
|
|
WinMapWindowPoints(hParent, HWND_DESKTOP, &ptl, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
result = DispatchMoveEvent(ptl.x, ptl.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pSwp->fl & SWP_SIZE && !(pSwp->fl & SWP_MINIMIZE)) {
|
|
|
|
mBounds.width = pSwp->cx;
|
|
|
|
mBounds.height = pSwp->cy;
|
|
|
|
|
2010-08-21 12:51:00 -07:00
|
|
|
// If the window is supposed to have a thebes surface, resize it.
|
|
|
|
if (ConfirmThebesSurface()) {
|
|
|
|
mThebesSurface->Resize(gfxIntSize(mBounds.width, mBounds.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
result = DispatchResizeEvent(mBounds.width, mBounds.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::OnPaint()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-28 08:46:08 -07:00
|
|
|
HPS hPS;
|
|
|
|
HPS hpsDrag;
|
|
|
|
HRGN hrgn;
|
2010-03-04 10:19:41 -08:00
|
|
|
nsEventStatus eventStatus = nsEventStatus_eIgnore;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
#ifdef DEBUG_PAINT
|
2010-03-04 10:19:41 -08:00
|
|
|
HRGN debugPaintFlashRegion = 0;
|
2010-03-28 08:46:08 -07:00
|
|
|
HPS debugPaintFlashPS = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
if (debug_WantPaintFlashing()) {
|
|
|
|
debugPaintFlashPS = WinGetPS(mWnd);
|
|
|
|
debugPaintFlashRegion = GpiCreateRegion(debugPaintFlashPS, 0, 0);
|
|
|
|
WinQueryUpdateRegion(mWnd, debugPaintFlashRegion);
|
2010-03-28 08:46:08 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
// Use a dummy do..while(0) loop to facilitate error handling & early-outs.
|
|
|
|
do {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
// Get the current drag status. If we're in a Moz-originated drag,
|
|
|
|
// it will return a special drag HPS to pass to WinBeginPaint().
|
|
|
|
// Oherwise, get a cached micro PS.
|
|
|
|
CheckDragStatus(ACTION_PAINT, &hpsDrag);
|
|
|
|
hPS = hpsDrag ? hpsDrag : WinGetPS(mWnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
// If we can't get an HPS, validate the window so we don't
|
|
|
|
// keep getting the same WM_PAINT msg over & over again.
|
|
|
|
RECTL rcl = { 0 };
|
|
|
|
if (!hPS) {
|
|
|
|
WinQueryWindowRect(mWnd, &rcl);
|
|
|
|
WinValidateRect(mWnd, &rcl, FALSE);
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
// Get the update region before WinBeginPaint() resets it.
|
|
|
|
hrgn = GpiCreateRegion(hPS, 0, 0);
|
|
|
|
WinQueryUpdateRegion(mWnd, hrgn);
|
|
|
|
WinBeginPaint(mWnd, hPS, &rcl);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-21 12:51:00 -07:00
|
|
|
// Exit if the update rect is empty.
|
|
|
|
if (WinIsRectEmpty(0, &rcl)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit if a thebes surface can not/should not be created,
|
|
|
|
// but first fill the area with the default background color
|
|
|
|
// to erase any visual artifacts.
|
|
|
|
if (!ConfirmThebesSurface()) {
|
|
|
|
WinDrawBorder(hPS, &rcl, 0, 0, 0, 0, DB_INTERIOR | DB_AREAATTRS);
|
2010-03-28 08:46:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Even if there is no callback to update the content (unlikely)
|
|
|
|
// we still want to update the screen with whatever's available.
|
|
|
|
if (!mEventCallback) {
|
|
|
|
mThebesSurface->Refresh(&rcl, hPS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an event & a Thebes context.
|
2011-10-17 07:59:28 -07:00
|
|
|
nsPaintEvent event(true, NS_PAINT, this);
|
2010-03-28 08:46:08 -07:00
|
|
|
InitEvent(event);
|
|
|
|
nsRefPtr<gfxContext> thebesContext = new gfxContext(mThebesSurface);
|
|
|
|
|
2010-08-21 12:51:00 -07:00
|
|
|
// Intersect the update region with the paint rectangle to clip areas
|
|
|
|
// that aren't visible (e.g. offscreen or covered by another window).
|
|
|
|
HRGN hrgnPaint;
|
|
|
|
hrgnPaint = GpiCreateRegion(hPS, 1, &rcl);
|
|
|
|
if (hrgnPaint) {
|
|
|
|
GpiCombineRegion(hPS, hrgn, hrgn, hrgnPaint, CRGN_AND);
|
|
|
|
GpiDestroyRegion(hPS, hrgnPaint);
|
|
|
|
}
|
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
// See how many rects comprise the update region. If there are 8
|
|
|
|
// or fewer, update them individually. If there are more or the call
|
|
|
|
// failed, update the bounding rectangle returned by WinBeginPaint().
|
|
|
|
#define MAX_CLIPRECTS 8
|
|
|
|
RGNRECT rgnrect = { 1, MAX_CLIPRECTS, 0, RECTDIR_LFRT_TOPBOT };
|
|
|
|
RECTL arect[MAX_CLIPRECTS];
|
|
|
|
RECTL* pr = arect;
|
|
|
|
|
|
|
|
if (!GpiQueryRegionRects(hPS, hrgn, 0, &rgnrect, 0) ||
|
|
|
|
rgnrect.crcReturned > MAX_CLIPRECTS) {
|
|
|
|
rgnrect.crcReturned = 1;
|
|
|
|
arect[0] = rcl;
|
|
|
|
} else {
|
|
|
|
GpiQueryRegionRects(hPS, hrgn, 0, &rgnrect, arect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create clipping regions for the event & the Thebes context.
|
|
|
|
thebesContext->NewPath();
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < rgnrect.crcReturned; i++, pr++) {
|
2010-03-28 08:46:08 -07:00
|
|
|
event.region.Or(event.region,
|
|
|
|
nsIntRect(pr->xLeft,
|
|
|
|
mBounds.height - pr->yTop,
|
|
|
|
pr->xRight - pr->xLeft,
|
|
|
|
pr->yTop - pr->yBottom));
|
|
|
|
|
|
|
|
thebesContext->Rectangle(gfxRect(pr->xLeft,
|
|
|
|
mBounds.height - pr->yTop,
|
|
|
|
pr->xRight - pr->xLeft,
|
|
|
|
pr->yTop - pr->yBottom));
|
|
|
|
}
|
|
|
|
thebesContext->Clip();
|
|
|
|
|
|
|
|
#ifdef DEBUG_PAINT
|
2012-09-01 19:35:17 -07:00
|
|
|
debug_DumpPaintEvent(stdout, this, &event, nsAutoCString("noname"),
|
2012-08-22 08:56:38 -07:00
|
|
|
(int32_t)mWnd);
|
2010-03-28 08:46:08 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Init the Layers manager then dispatch the event.
|
|
|
|
// If it returns false there's nothing to paint, so exit.
|
2010-07-15 14:08:04 -07:00
|
|
|
AutoLayerManagerSetup
|
|
|
|
setupLayerManager(this, thebesContext, BasicLayerManager::BUFFER_NONE);
|
2010-03-28 08:46:08 -07:00
|
|
|
if (!DispatchWindowEvent(&event, eventStatus)) {
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
// Paint the surface, then use Refresh() to blit each rect to the screen.
|
|
|
|
thebesContext->PopGroupToSource();
|
|
|
|
thebesContext->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
thebesContext->Paint();
|
|
|
|
pr = arect;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < rgnrect.crcReturned; i++, pr++) {
|
2010-03-28 08:46:08 -07:00
|
|
|
mThebesSurface->Refresh(pr, hPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
// Cleanup.
|
|
|
|
if (hPS) {
|
2010-03-04 10:19:41 -08:00
|
|
|
WinEndPaint(hPS);
|
2010-03-28 08:46:08 -07:00
|
|
|
if (hrgn) {
|
|
|
|
GpiDestroyRegion(hPS, hrgn);
|
|
|
|
}
|
|
|
|
if (!hpsDrag || !ReleaseIfDragHPS(hpsDrag)) {
|
|
|
|
WinReleasePS(hPS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-28 08:46:08 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 08:46:08 -07:00
|
|
|
#ifdef DEBUG_PAINT
|
2010-03-04 10:19:41 -08:00
|
|
|
if (debug_WantPaintFlashing()) {
|
|
|
|
// Only flash paint events which have not ignored the paint message.
|
|
|
|
// Those that ignore the paint message aren't painting anything so there
|
|
|
|
// is only the overhead of the dispatching the paint event.
|
|
|
|
if (eventStatus != nsEventStatus_eIgnore) {
|
|
|
|
LONG CurMix = GpiQueryMix(debugPaintFlashPS);
|
|
|
|
GpiSetMix(debugPaintFlashPS, FM_INVERT);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
GpiPaintRegion(debugPaintFlashPS, debugPaintFlashRegion);
|
|
|
|
PR_Sleep(PR_MillisecondsToInterval(30));
|
|
|
|
GpiPaintRegion(debugPaintFlashPS, debugPaintFlashRegion);
|
|
|
|
PR_Sleep(PR_MillisecondsToInterval(30));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
GpiSetMix(debugPaintFlashPS, CurMix);
|
2010-03-28 08:46:08 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
GpiDestroyRegion(debugPaintFlashPS, debugPaintFlashRegion);
|
|
|
|
WinReleasePS(debugPaintFlashPS);
|
2010-03-28 08:46:08 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// If MB1 & MB2 are both pressed, perform a copy or paste.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::OnMouseChord(MPARAM mp1, MPARAM mp2)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!isKeyDown(VK_BUTTON1) || !isKeyDown(VK_BUTTON2)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2009-06-23 02:26:45 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// See how far the mouse has moved since MB1-down to determine
|
|
|
|
// the operation (this really ought to look for selected content).
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCopy = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
if (abs(XFROMMP(mp1) - sLastButton1Down.x) >
|
|
|
|
(WinQuerySysValue(HWND_DESKTOP, SV_CXMOTIONSTART) / 2) ||
|
|
|
|
abs(YFROMMP(mp1) - sLastButton1Down.y) >
|
|
|
|
(WinQuerySysValue(HWND_DESKTOP, SV_CYMOTIONSTART) / 2)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isCopy = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2009-06-23 02:26:45 -07:00
|
|
|
|
2013-07-24 23:09:28 -07:00
|
|
|
// XXX Using keypress event here is wrong approach, this should be replaced
|
|
|
|
// with content command event.
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
nsIntPoint point(0,0);
|
|
|
|
InitEvent(event, &point);
|
2009-06-23 02:26:45 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
event.keyCode = NS_VK_INSERT;
|
|
|
|
if (isCopy) {
|
2013-09-13 19:39:41 -07:00
|
|
|
event.modifiers = MODIFIER_CONTROL;
|
2010-03-04 10:19:41 -08:00
|
|
|
} else {
|
2013-09-13 19:39:41 -07:00
|
|
|
event.modifiers = MODIFIER_SHIFT;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
event.eventStructType = NS_KEY_EVENT;
|
|
|
|
event.charCode = 0;
|
|
|
|
|
|
|
|
// OS/2 does not set the Shift, Ctrl, or Alt on keyup
|
|
|
|
if (SHORT1FROMMP(mp1) & (KC_VIRTUALKEY | KC_KEYUP | KC_LONEKEY)) {
|
|
|
|
USHORT usVKey = SHORT2FROMMP(mp2);
|
|
|
|
if (usVKey == VK_SHIFT) {
|
2013-09-13 19:39:41 -07:00
|
|
|
event.modifiers |= MODIFIER_SHIFT;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
if (usVKey == VK_CTRL) {
|
2013-09-13 19:39:41 -07:00
|
|
|
event.modifiers |= MODIFIER_CONTROL;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
if (usVKey == VK_ALTGRAF || usVKey == VK_ALT) {
|
2013-09-13 19:39:41 -07:00
|
|
|
event.modifiers |= MODIFIER_ALT;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2009-06-23 02:26:45 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return DispatchWindowEvent(&event);
|
2009-06-23 02:26:45 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Drag & Drop - Target methods
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// nsWindow knows almost nothing about d&d except that it can cause
|
|
|
|
// video corruption if the screen is updated during a drag. It relies
|
|
|
|
// on nsIDragSessionOS2 to handle native d&d messages and to return
|
|
|
|
// the status flags it uses to control screen updates.
|
|
|
|
//
|
|
|
|
// OnDragDropMsg() handles all of the DM_* messages messages nsWindow
|
|
|
|
// should ever receive. CheckDragStatus() determines if a screen update
|
|
|
|
// is safe and may return a drag HPS if doing so will avoid corruption.
|
|
|
|
// As far as its author (R.Walsh) can tell, every use is required.
|
|
|
|
//
|
|
|
|
// For Moz drags, all while-you-drag features should be fully enabled &
|
|
|
|
// corruption free; for native drags, popups & scrolling are suppressed
|
|
|
|
// but some niceties, e.g. moving the cursor in text fields, are enabled.
|
|
|
|
//
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This method was designed to be totally ignorant of drag and drop.
|
|
|
|
// It gives nsIDragSessionOS2 (near) complete control over handling.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::OnDragDropMsg(ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT& mr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t eventType = 0;
|
|
|
|
uint32_t dragFlags = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mr = 0;
|
|
|
|
nsCOMPtr<nsIDragService> dragService =
|
|
|
|
do_GetService("@mozilla.org/widget/dragservice;1", &rv);
|
|
|
|
if (dragService) {
|
|
|
|
nsCOMPtr<nsIDragSessionOS2> dragSession(
|
|
|
|
do_QueryInterface(dragService, &rv));
|
|
|
|
if (dragSession) {
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// handle all possible input without regard to outcome
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (msg) {
|
|
|
|
|
|
|
|
case DM_DRAGOVER:
|
2007-04-11 21:37:39 -07:00
|
|
|
dragService->FireDragEventAtSource(NS_DRAGDROP_DRAG);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = dragSession->DragOverMsg((PDRAGINFO)mp1, mr, &dragFlags);
|
|
|
|
eventType = NS_DRAGDROP_OVER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DM_DRAGLEAVE:
|
|
|
|
rv = dragSession->DragLeaveMsg((PDRAGINFO)mp1, &dragFlags);
|
|
|
|
eventType = NS_DRAGDROP_EXIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DM_DROP:
|
|
|
|
rv = dragSession->DropMsg((PDRAGINFO)mp1, mWnd, &dragFlags);
|
|
|
|
eventType = NS_DRAGDROP_DROP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DM_DROPHELP:
|
|
|
|
rv = dragSession->DropHelpMsg((PDRAGINFO)mp1, &dragFlags);
|
|
|
|
eventType = NS_DRAGDROP_EXIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DM_RENDERCOMPLETE:
|
|
|
|
rv = dragSession->RenderCompleteMsg((PDRAGTRANSFER)mp1,
|
|
|
|
SHORT1FROMMP(mp2), &dragFlags);
|
|
|
|
eventType = NS_DRAGDROP_DROP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// handle all possible outcomes without regard to their source
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2010-03-04 10:19:41 -08:00
|
|
|
mDragStatus = sDragStatus = (dragFlags & DND_DragStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
if (dragFlags & DND_DispatchEnterEvent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
DispatchDragDropEvent(NS_DRAGDROP_ENTER);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
if (dragFlags & DND_DispatchEvent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
DispatchDragDropEvent(eventType);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
if (dragFlags & DND_GetDragoverResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
dragSession->GetDragoverResult(mr);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
if (dragFlags & DND_ExitSession) {
|
2007-03-22 10:30:00 -07:00
|
|
|
dragSession->ExitSession(&dragFlags);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
// save final drag status
|
|
|
|
sDragStatus = mDragStatus = (dragFlags & DND_DragStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
// CheckDragStatus() concentrates all the hacks needed to avoid video
|
|
|
|
// corruption during d&d into one place. The caller specifies an action
|
|
|
|
// that might be a problem; the method tells it whether to proceed and
|
|
|
|
// provides a Drg HPS if the situation calls for one.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::CheckDragStatus(uint32_t aAction, HPS* aHps)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool rtn = true;
|
|
|
|
bool getHps = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aAction) {
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// OnPaint() & Scroll..() - only Moz drags get a Drg hps
|
2007-03-22 10:30:00 -07:00
|
|
|
case ACTION_PAINT:
|
|
|
|
case ACTION_SCROLL:
|
2010-03-04 10:19:41 -08:00
|
|
|
if (sDragStatus & DND_MozDrag) {
|
2011-10-17 07:59:28 -07:00
|
|
|
getHps = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// GetNativeData() - Moz drags + native drags over this nsWindow
|
2007-03-22 10:30:00 -07:00
|
|
|
case ACTION_DRAW:
|
2010-03-04 10:19:41 -08:00
|
|
|
if ((sDragStatus & DND_MozDrag) ||
|
|
|
|
(mDragStatus & DND_NativeDrag)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
getHps = true;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Show() - don't show popups during a native dragover
|
2007-03-22 10:30:00 -07:00
|
|
|
case ACTION_SHOW:
|
2010-03-04 10:19:41 -08:00
|
|
|
if ((sDragStatus & (DND_NativeDrag | DND_InDrop)) == DND_NativeDrag) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rtn = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// InitEvent() - use PtrPos while in drag, MsgPos otherwise
|
2007-03-22 10:30:00 -07:00
|
|
|
case ACTION_PTRPOS:
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!sDragStatus) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rtn = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
rtn = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// If the caller wants an HPS, and the current drag status
|
|
|
|
// calls for one, *and* a drag hps hasn't already been requested
|
|
|
|
// for this window, get the hps; otherwise, return zero;
|
|
|
|
// (if we provide a 2nd hps for a window, the cursor in text
|
|
|
|
// fields won't be erased when it's moved to another position)
|
|
|
|
if (aHps) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (getHps && !mDragHps) {
|
|
|
|
mDragHps = DrgGetPS(mWnd);
|
2010-03-04 10:19:41 -08:00
|
|
|
*aHps = mDragHps;
|
2009-11-03 13:29:31 -08:00
|
|
|
} else {
|
2010-03-04 10:19:41 -08:00
|
|
|
*aHps = 0;
|
2009-11-03 13:29:31 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// If there's an outstanding drag hps & it matches the one passed in,
|
|
|
|
// release it.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::ReleaseIfDragHPS(HPS aHps)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
if (mDragHps && aHps == mDragHps) {
|
|
|
|
DrgReleasePS(mDragHps);
|
|
|
|
mDragHps = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// Keyboard Handlers
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
// Figure out which keyboard LEDs are on.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsWindow::GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t vkey;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aLEDState);
|
|
|
|
|
|
|
|
switch (aKeyCode) {
|
|
|
|
case NS_VK_CAPS_LOCK:
|
|
|
|
vkey = VK_CAPSLOCK;
|
|
|
|
break;
|
|
|
|
case NS_VK_NUM_LOCK:
|
|
|
|
vkey = VK_NUMLOCK;
|
|
|
|
break;
|
|
|
|
case NS_VK_SCROLL_LOCK:
|
|
|
|
vkey = VK_SCRLLOCK;
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
*aLEDState = false;
|
2010-03-04 10:19:41 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aLEDState = (WinGetKeyState(HWND_DESKTOP, vkey) & 1) != 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Prevent PM from translating some keys & key-combos into accelerators.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::OnTranslateAccelerator(PQMSG pQmsg)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
if (pQmsg->msg != WM_CHAR) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG mp1 = (LONG)pQmsg->mp1;
|
|
|
|
LONG mp2 = (LONG)pQmsg->mp2;
|
|
|
|
LONG sca = SHORT1FROMMP(mp1) & (KC_SHIFT | KC_CTRL | KC_ALT);
|
|
|
|
|
|
|
|
if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
|
|
|
|
|
|
|
|
// standalone F1 & F10
|
|
|
|
if (SHORT2FROMMP(mp2) == VK_F1 || SHORT2FROMMP(mp2) == VK_F10) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return (!sca ? true : false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shift+Enter
|
|
|
|
if (SHORT2FROMMP(mp2) == VK_ENTER) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return (sca == KC_SHIFT ? true : false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Alt+Enter
|
|
|
|
if (SHORT2FROMMP(mp2) == VK_NEWLINE) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return (sca == KC_ALT ? true : false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// standalone Alt & AltGraf
|
|
|
|
if ((SHORT2FROMMP(mp2) == VK_ALT || SHORT2FROMMP(mp2) == VK_ALTGRAF) &&
|
|
|
|
(SHORT1FROMMP(mp1) & (KC_KEYUP | KC_LONEKEY))
|
|
|
|
== (KC_KEYUP | KC_LONEKEY)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2012-06-19 00:33:42 -07:00
|
|
|
bool nsWindow::OnQueryConvertPos(MPARAM mp1, MRESULT& mresult)
|
|
|
|
{
|
|
|
|
PRECTL pCursorPos = (PRECTL)mp1;
|
|
|
|
|
|
|
|
nsIntPoint point(0, 0);
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent selection(true, NS_QUERY_SELECTED_TEXT, this);
|
2012-06-19 00:33:42 -07:00
|
|
|
InitEvent(selection, &point);
|
|
|
|
DispatchWindowEvent(&selection);
|
|
|
|
if (!selection.mSucceeded)
|
|
|
|
return false;
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent caret(true, NS_QUERY_CARET_RECT, this);
|
2012-06-19 00:33:42 -07:00
|
|
|
caret.InitForQueryCaretRect(selection.mReply.mOffset);
|
|
|
|
InitEvent(caret, &point);
|
|
|
|
DispatchWindowEvent(&caret);
|
|
|
|
if (!caret.mSucceeded)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pCursorPos->xLeft = caret.mReply.mRect.x;
|
|
|
|
pCursorPos->yBottom = caret.mReply.mRect.y;
|
|
|
|
pCursorPos->xRight = pCursorPos->xLeft + caret.mReply.mRect.width;
|
|
|
|
pCursorPos->yTop = pCursorPos->yBottom + caret.mReply.mRect.height;
|
|
|
|
NS2PM(*pCursorPos);
|
|
|
|
mresult = (MRESULT)QCP_CONVERT;
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-20 03:09:05 -07:00
|
|
|
bool nsWindow::ImeResultString(HIMI himi)
|
|
|
|
{
|
|
|
|
ULONG ulBufLen;
|
|
|
|
// Get a buffer size
|
|
|
|
ulBufLen = 0;
|
2013-10-08 11:47:49 -07:00
|
|
|
if (spfnImGetResultString(himi, IMR_RESULT_RESULTSTRING, nullptr, &ulBufLen))
|
2012-06-20 03:09:05 -07:00
|
|
|
return false;
|
2013-06-11 05:12:07 -07:00
|
|
|
nsAutoTArray<CHAR, 64> compositionStringA;
|
|
|
|
compositionStringA.SetCapacity(ulBufLen / sizeof(CHAR));
|
2012-06-20 03:09:05 -07:00
|
|
|
|
2013-06-11 05:12:07 -07:00
|
|
|
if (spfnImGetResultString(himi, IMR_RESULT_RESULTSTRING,
|
|
|
|
compositionStringA.Elements(), &ulBufLen)) {
|
2012-06-20 03:09:05 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mIsComposing) {
|
2012-07-14 18:22:54 -07:00
|
|
|
mLastDispatchedCompositionString.Truncate();
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent start(true, NS_COMPOSITION_START, this);
|
2012-06-20 03:09:05 -07:00
|
|
|
InitEvent(start);
|
|
|
|
DispatchWindowEvent(&start);
|
|
|
|
mIsComposing = true;
|
|
|
|
}
|
|
|
|
nsAutoChar16Buffer outBuf;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t outBufLen;
|
2013-06-11 05:12:07 -07:00
|
|
|
MultiByteToWideChar(0, compositionStringA.Elements(), ulBufLen,
|
|
|
|
outBuf, outBufLen);
|
2012-07-14 18:22:54 -07:00
|
|
|
nsAutoString compositionString(outBuf.Elements());
|
|
|
|
if (mLastDispatchedCompositionString != compositionString) {
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent update(true, NS_COMPOSITION_UPDATE, this);
|
2012-07-14 18:22:54 -07:00
|
|
|
InitEvent(update);
|
|
|
|
update.data = compositionString;
|
|
|
|
mLastDispatchedCompositionString = compositionString;
|
|
|
|
DispatchWindowEvent(&update);
|
|
|
|
}
|
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent text(true, NS_TEXT_TEXT, this);
|
2012-06-20 03:09:05 -07:00
|
|
|
InitEvent(text);
|
2012-07-14 18:22:54 -07:00
|
|
|
text.theText = compositionString;
|
2012-06-20 03:09:05 -07:00
|
|
|
DispatchWindowEvent(&text);
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent end(true, NS_COMPOSITION_END, this);
|
2012-06-20 03:09:05 -07:00
|
|
|
InitEvent(end);
|
2012-07-14 18:22:54 -07:00
|
|
|
end.data = compositionString;
|
2012-06-20 03:09:05 -07:00
|
|
|
DispatchWindowEvent(&end);
|
|
|
|
mIsComposing = false;
|
2012-07-14 18:22:54 -07:00
|
|
|
mLastDispatchedCompositionString.Truncate();
|
2012-06-20 03:09:05 -07:00
|
|
|
return true;
|
|
|
|
}
|
2013-06-11 05:12:07 -07:00
|
|
|
static uint32_t
|
|
|
|
PlatformToNSAttr(uint8_t aAttr)
|
|
|
|
{
|
|
|
|
switch (aAttr)
|
|
|
|
{
|
|
|
|
case CP_ATTR_INPUT_ERROR:
|
|
|
|
case CP_ATTR_INPUT:
|
|
|
|
return NS_TEXTRANGE_RAWINPUT;
|
|
|
|
|
|
|
|
case CP_ATTR_CONVERTED:
|
|
|
|
return NS_TEXTRANGE_CONVERTEDTEXT;
|
|
|
|
|
|
|
|
case CP_ATTR_TARGET_NOTCONVERTED:
|
|
|
|
return NS_TEXTRANGE_SELECTEDRAWTEXT;
|
|
|
|
|
|
|
|
case CP_ATTR_TARGET_CONVERTED:
|
|
|
|
return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
|
|
|
|
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("unknown attribute");
|
2013-06-11 05:12:07 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-20 03:09:05 -07:00
|
|
|
|
|
|
|
bool nsWindow::ImeConversionString(HIMI himi)
|
|
|
|
{
|
|
|
|
ULONG ulBufLen;
|
|
|
|
// Get a buffer size
|
|
|
|
ulBufLen = 0;
|
2013-10-08 11:47:49 -07:00
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CONVERSIONSTRING, nullptr,
|
2012-06-20 03:09:05 -07:00
|
|
|
&ulBufLen))
|
|
|
|
return false;
|
2013-06-11 05:12:07 -07:00
|
|
|
nsAutoTArray<CHAR, 64> compositionStringA;
|
|
|
|
compositionStringA.SetCapacity(ulBufLen / sizeof(CHAR));
|
2012-06-20 03:09:05 -07:00
|
|
|
|
2013-06-11 05:12:07 -07:00
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CONVERSIONSTRING,
|
|
|
|
compositionStringA.Elements(), &ulBufLen)) {
|
2012-06-20 03:09:05 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mIsComposing) {
|
2012-07-14 18:22:54 -07:00
|
|
|
mLastDispatchedCompositionString.Truncate();
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent start(true, NS_COMPOSITION_START, this);
|
2012-06-20 03:09:05 -07:00
|
|
|
InitEvent(start);
|
|
|
|
DispatchWindowEvent(&start);
|
|
|
|
mIsComposing = true;
|
|
|
|
}
|
|
|
|
nsAutoChar16Buffer outBuf;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t outBufLen;
|
2013-06-11 05:12:07 -07:00
|
|
|
MultiByteToWideChar(0, compositionStringA.Elements(), ulBufLen,
|
|
|
|
outBuf, outBufLen);
|
2012-07-14 18:22:54 -07:00
|
|
|
nsAutoString compositionString(outBuf.Elements());
|
|
|
|
// Is a conversion string changed ?
|
|
|
|
if (mLastDispatchedCompositionString != compositionString) {
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent update(true, NS_COMPOSITION_UPDATE, this);
|
2012-07-14 18:22:54 -07:00
|
|
|
InitEvent(update);
|
|
|
|
update.data = compositionString;
|
|
|
|
mLastDispatchedCompositionString = compositionString;
|
|
|
|
DispatchWindowEvent(&update);
|
|
|
|
}
|
2013-10-01 00:22:59 -07:00
|
|
|
nsAutoTArray<TextRange, 4> textRanges;
|
2012-07-14 18:22:54 -07:00
|
|
|
if (!compositionString.IsEmpty()) {
|
2013-06-11 05:12:07 -07:00
|
|
|
bool oneClause = false;
|
|
|
|
|
|
|
|
ulBufLen = 0;
|
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CONVERSIONCLAUSE, 0,
|
|
|
|
&ulBufLen)) {
|
|
|
|
oneClause = true; // Assume that there is only one clause
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG ulClauseCount = std::max(2UL, ulBufLen / sizeof(ULONG));
|
|
|
|
nsAutoTArray<ULONG, 4> clauseOffsets;
|
|
|
|
nsAutoTArray<UCHAR, 4> clauseAttr;
|
|
|
|
ULONG ulCursorPos;
|
|
|
|
|
|
|
|
clauseOffsets.SetCapacity(ulClauseCount);
|
|
|
|
clauseAttr.SetCapacity(ulClauseCount);
|
|
|
|
|
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CONVERSIONCLAUSE,
|
|
|
|
clauseOffsets.Elements(), &ulBufLen)) {
|
|
|
|
oneClause = true; // Assume that there is only one clause
|
|
|
|
}
|
|
|
|
|
|
|
|
// Korean IME does not provide clause and cursor infomation
|
|
|
|
// Or if getting a clause inforamtion was failed
|
|
|
|
if (ulBufLen == 0 && !oneClause) {
|
|
|
|
ulCursorPos = compositionString.Length();
|
|
|
|
|
|
|
|
oneClause = true;
|
|
|
|
} else {
|
|
|
|
while (!oneClause) {
|
|
|
|
ulBufLen = 0;
|
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CONVERSIONATTR, 0,
|
|
|
|
&ulBufLen)) {
|
|
|
|
oneClause = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<UCHAR, 64> attr;
|
|
|
|
attr.SetCapacity(ulBufLen / sizeof(UCHAR));
|
|
|
|
|
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CONVERSIONATTR,
|
|
|
|
attr.Elements(), &ulBufLen)) {
|
|
|
|
oneClause = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assume that all the conversion attribute in a clause are same
|
|
|
|
for (ULONG i = 0; i < ulClauseCount - 1; ++i) {
|
|
|
|
clauseAttr[i] = attr[clauseOffsets[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert ANSI string offsets to Unicode string offsets
|
|
|
|
clauseOffsets[0] = 0;
|
|
|
|
for (ULONG i = 1; i < ulClauseCount - 1; ++i) {
|
|
|
|
MultiByteToWideChar(0,
|
|
|
|
compositionStringA.Elements(), clauseOffsets[i],
|
|
|
|
outBuf, outBufLen);
|
|
|
|
clauseOffsets[i] = outBufLen;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulBufLen = sizeof(ULONG);
|
|
|
|
if (spfnImGetConversionString(himi, IMR_CONV_CURSORPOS, &ulCursorPos,
|
|
|
|
&ulBufLen)) {
|
|
|
|
ulCursorPos = NO_IME_CARET;
|
|
|
|
} else {
|
|
|
|
// Convert ANSI string position to Unicode string position
|
|
|
|
MultiByteToWideChar(0, compositionStringA.Elements(), ulCursorPos,
|
|
|
|
outBuf, outBufLen);
|
|
|
|
ulCursorPos = outBufLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oneClause) {
|
|
|
|
ulClauseCount = 2;
|
|
|
|
clauseOffsets[0] = 0;
|
|
|
|
clauseOffsets[1] = compositionString.Length();
|
|
|
|
clauseAttr[0] = NS_TEXTRANGE_SELECTEDRAWTEXT;
|
|
|
|
}
|
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRange newRange;
|
2012-06-20 03:09:05 -07:00
|
|
|
|
2013-06-11 05:12:07 -07:00
|
|
|
for (ULONG i = 0; i < ulClauseCount - 1; ++i) {
|
|
|
|
newRange.mStartOffset = clauseOffsets[i];
|
|
|
|
newRange.mEndOffset = clauseOffsets[i + 1];
|
|
|
|
newRange.mRangeType = PlatformToNSAttr(clauseAttr[i]);
|
|
|
|
textRanges.AppendElement(newRange);
|
|
|
|
}
|
2012-06-20 03:09:05 -07:00
|
|
|
|
2013-06-11 05:12:07 -07:00
|
|
|
if (ulCursorPos != NO_IME_CARET) {
|
|
|
|
newRange.mStartOffset = newRange.mEndOffset = ulCursorPos;
|
|
|
|
newRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
|
|
|
textRanges.AppendElement(newRange);
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent text(true, NS_TEXT_TEXT, this);
|
2012-06-20 03:09:05 -07:00
|
|
|
InitEvent(text);
|
2012-07-14 18:22:54 -07:00
|
|
|
text.theText = compositionString;
|
2012-06-20 03:09:05 -07:00
|
|
|
text.rangeArray = textRanges.Elements();
|
|
|
|
text.rangeCount = textRanges.Length();
|
|
|
|
DispatchWindowEvent(&text);
|
|
|
|
|
2012-07-14 18:22:54 -07:00
|
|
|
if (compositionString.IsEmpty()) { // IME conversion was canceled ?
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent end(true, NS_COMPOSITION_END, this);
|
2012-06-20 03:09:05 -07:00
|
|
|
InitEvent(end);
|
2012-07-14 18:22:54 -07:00
|
|
|
end.data = compositionString;
|
2012-06-20 03:09:05 -07:00
|
|
|
DispatchWindowEvent(&end);
|
|
|
|
|
|
|
|
mIsComposing = false;
|
2012-07-14 18:22:54 -07:00
|
|
|
mLastDispatchedCompositionString.Truncate();
|
2012-06-20 03:09:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsWindow::OnImeRequest(MPARAM mp1, MPARAM mp2)
|
|
|
|
{
|
|
|
|
HIMI himi;
|
|
|
|
bool rc;
|
|
|
|
|
|
|
|
if (!sIm32Mod)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (SHORT1FROMMP(mp1) != IMR_CONVRESULT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (spfnImGetInstance(mWnd, &himi))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (LONGFROMMP(mp2) & IMR_RESULT_RESULTSTRING)
|
|
|
|
rc = ImeResultString(himi);
|
|
|
|
else if (LONGFROMMP(mp2) & IMR_CONV_CONVERSIONSTRING)
|
|
|
|
rc = ImeConversionString(himi);
|
|
|
|
else
|
|
|
|
rc = true;
|
|
|
|
|
|
|
|
spfnImReleaseInstance(mWnd, himi);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2012-10-26 16:35:21 -07:00
|
|
|
NS_IMETHODIMP_(InputContext) nsWindow::GetInputContext()
|
|
|
|
{
|
|
|
|
HIMI himi;
|
|
|
|
if (sIm32Mod && spfnImGetInstance(mWnd, &himi)) {
|
|
|
|
mInputContext.mNativeIMEContext = static_cast<void*>(himi);
|
|
|
|
}
|
|
|
|
if (!mInputContext.mNativeIMEContext) {
|
|
|
|
mInputContext.mNativeIMEContext = this;
|
|
|
|
}
|
|
|
|
return mInputContext;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Key handler. Specs for the various text messages are really confused;
|
|
|
|
// see other platforms for best results of how things are supposed to work.
|
|
|
|
//
|
|
|
|
// Perhaps more importantly, the main man listening to these events
|
|
|
|
// (besides random bits of javascript) is ender -- see
|
|
|
|
// mozilla/editor/base/nsEditorEventListeners.cpp.
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::DispatchKeyEvent(MPARAM mp1, MPARAM mp2)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent pressEvent(true, 0, nullptr);
|
2010-03-04 10:19:41 -08:00
|
|
|
USHORT fsFlags = SHORT1FROMMP(mp1);
|
|
|
|
USHORT usVKey = SHORT2FROMMP(mp2);
|
|
|
|
USHORT usChar = SHORT1FROMMP(mp2);
|
|
|
|
UCHAR uchScan = CHAR4FROMMP(mp1);
|
|
|
|
|
|
|
|
// It appears we're not supposed to transmit shift,
|
|
|
|
// control, & alt events to gecko.
|
|
|
|
if (fsFlags & KC_VIRTUALKEY && !(fsFlags & KC_KEYUP) &&
|
|
|
|
(usVKey == VK_SHIFT || usVKey == VK_CTRL || usVKey == VK_ALTGRAF)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Workaround bug where using Alt+Esc let an Alt key creep through
|
|
|
|
// Only handle alt by itself if the LONEKEY bit is set
|
|
|
|
if ((fsFlags & KC_VIRTUALKEY) && (usVKey == VK_ALT) && !usChar &&
|
|
|
|
(!(fsFlags & KC_LONEKEY)) && (fsFlags & KC_KEYUP)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now check if it's a dead-key
|
|
|
|
if (fsFlags & KC_DEADKEY) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now dispatch a keyup/keydown event. This one is *not* meant to
|
|
|
|
// have the unicode charcode in.
|
|
|
|
nsIntPoint point(0,0);
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent event(true,
|
|
|
|
(fsFlags & KC_KEYUP) ? NS_KEY_UP : NS_KEY_DOWN,
|
|
|
|
this);
|
2010-03-04 10:19:41 -08:00
|
|
|
InitEvent(event, &point);
|
|
|
|
event.keyCode = WMChar2KeyCode(mp1, mp2);
|
2012-04-24 20:00:02 -07:00
|
|
|
event.InitBasicModifiers(fsFlags & KC_CTRL, fsFlags & KC_ALT,
|
|
|
|
fsFlags & KC_SHIFT, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
event.charCode = 0;
|
2013-11-07 03:17:33 -08:00
|
|
|
event.mIsRepeat = event.message == NS_KEY_DOWN && CHAR3FROMMP(mp1) != 0;
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
// Check for a scroll mouse event vs. a keyboard event. The way we know
|
|
|
|
// this is that the repeat count is 0 and the key is not physically down.
|
|
|
|
// Unfortunately, there is an exception here - if alt or ctrl are held
|
|
|
|
// down, repeat count is set so we have to add special checks for them.
|
|
|
|
if (((event.keyCode == NS_VK_UP) || (event.keyCode == NS_VK_DOWN)) &&
|
|
|
|
!(fsFlags & KC_KEYUP) &&
|
|
|
|
(!CHAR3FROMMP(mp1) || fsFlags & KC_CTRL || fsFlags & KC_ALT)) {
|
|
|
|
if (!(WinGetPhysKeyState(HWND_DESKTOP, uchScan) & 0x8000)) {
|
|
|
|
MPARAM mp2;
|
|
|
|
if (event.keyCode == NS_VK_UP) {
|
|
|
|
mp2 = MPFROM2SHORT(0, SB_LINEUP);
|
|
|
|
} else {
|
|
|
|
mp2 = MPFROM2SHORT(0, SB_LINEDOWN);
|
|
|
|
}
|
|
|
|
WinSendMsg(mWnd, WM_VSCROLL, 0, mp2);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pressEvent = event;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool rc = DispatchWindowEvent(&event);
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
// Break off now if this was a key-up.
|
|
|
|
if (fsFlags & KC_KEYUP) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:28 -07:00
|
|
|
// Don't dispatch keypress event if keydown event is consumed.
|
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Break off if we've got an "invalid composition" -- that is,
|
|
|
|
// the user typed a deadkey last time, but has now typed something
|
|
|
|
// that doesn't make sense in that context.
|
|
|
|
if (fsFlags & KC_INVALIDCOMP) {
|
|
|
|
// actually, not sure whether we're supposed to abort the keypress
|
|
|
|
// or process it as though the dead key has been pressed.
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we need to dispatch a keypress event which has the unicode char.
|
|
|
|
// If keydown default was prevented, do same for keypress
|
|
|
|
pressEvent.message = NS_KEY_PRESS;
|
|
|
|
|
|
|
|
if (usChar) {
|
|
|
|
USHORT inbuf[2];
|
|
|
|
inbuf[0] = usChar;
|
|
|
|
inbuf[1] = '\0';
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
nsAutoChar16Buffer outbuf;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bufLength;
|
2010-03-04 10:19:41 -08:00
|
|
|
MultiByteToWideChar(0, (const char*)inbuf, 2, outbuf, bufLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
pressEvent.charCode = outbuf[0];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-24 20:00:02 -07:00
|
|
|
if (pressEvent.IsControl() && !(fsFlags & (KC_VIRTUALKEY | KC_DEADKEY))) {
|
|
|
|
if (!pressEvent.IsShift() && (pressEvent.charCode >= 'A' && pressEvent.charCode <= 'Z')) {
|
2010-03-04 10:19:41 -08:00
|
|
|
pressEvent.charCode = tolower(pressEvent.charCode);
|
|
|
|
}
|
2012-04-24 20:00:02 -07:00
|
|
|
if (pressEvent.IsShift() && (pressEvent.charCode >= 'a' && pressEvent.charCode <= 'z')) {
|
2010-03-04 10:19:41 -08:00
|
|
|
pressEvent.charCode = toupper(pressEvent.charCode);
|
|
|
|
}
|
|
|
|
pressEvent.keyCode = 0;
|
2012-04-24 20:00:02 -07:00
|
|
|
} else if (!pressEvent.IsControl() && !pressEvent.IsAlt() && pressEvent.charCode != 0) {
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!(fsFlags & KC_VIRTUALKEY) || // not virtual key
|
|
|
|
((fsFlags & KC_CHAR) && !pressEvent.keyCode)) {
|
|
|
|
pressEvent.keyCode = 0;
|
|
|
|
} else if (usVKey == VK_SPACE) {
|
|
|
|
// space key, do nothing here
|
|
|
|
} else if ((fsFlags & KC_VIRTUALKEY) &&
|
|
|
|
isNumPadScanCode(uchScan) && pressEvent.keyCode != 0 && isNumlockOn) {
|
|
|
|
// this is NumLock+Numpad (no Alt), handle this like a normal number
|
|
|
|
pressEvent.keyCode = 0;
|
|
|
|
} else { // Real virtual key
|
|
|
|
pressEvent.charCode = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rc = DispatchWindowEvent(&pressEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return rc;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helper function to translate from a WM_CHAR to an NS_VK_ constant.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
static
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t WMChar2KeyCode(MPARAM mp1, MPARAM mp2)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t rc = SHORT1FROMMP(mp2); // character code
|
|
|
|
uint32_t rcmask = rc & 0x00FF; // masked character code for key up events
|
2007-03-22 10:30:00 -07:00
|
|
|
USHORT sc = CHAR4FROMMP(mp1); // scan code
|
|
|
|
USHORT flags = SHORT1FROMMP(mp1); // flag word
|
|
|
|
|
|
|
|
// First check for characters.
|
|
|
|
// This is complicated by keystrokes such as Ctrl+K not having the KC_CHAR
|
|
|
|
// bit set, but thankfully they do have the character actually there.
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Assume that `if not vkey or deadkey or valid number then char'
|
|
|
|
if (!(flags & (KC_VIRTUALKEY | KC_DEADKEY)) ||
|
|
|
|
(rcmask >= '0' && rcmask <= '9' && // handle keys on Numpad, too,
|
2010-03-04 10:19:41 -08:00
|
|
|
(isNumPadScanCode(sc) ? isNumlockOn : 1))) { // if NumLock is on
|
2007-03-22 10:30:00 -07:00
|
|
|
if (flags & KC_KEYUP) { // On OS/2 the scancode is in the upper byte of
|
|
|
|
// usChar when KC_KEYUP is set so mask it off
|
|
|
|
rc = rcmask;
|
|
|
|
} else { // not KC_KEYUP
|
2010-03-04 10:19:41 -08:00
|
|
|
if (!(flags & KC_CHAR)) {
|
|
|
|
if ((flags & KC_ALT) || (flags & KC_CTRL)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rc = rcmask;
|
2010-03-04 10:19:41 -08:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
rc = 0;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc < 0xFF) {
|
|
|
|
if (rc >= 'a' && rc <= 'z') { // The DOM_VK are for upper case only so
|
|
|
|
// if rc is lower case upper case it.
|
|
|
|
rc = rc - 'a' + NS_VK_A;
|
|
|
|
} else if (rc >= 'A' && rc <= 'Z') { // Upper case
|
|
|
|
rc = rc - 'A' + NS_VK_A;
|
|
|
|
} else if (rc >= '0' && rc <= '9') {
|
|
|
|
// Number keys, including Numpad if NumLock is not set
|
|
|
|
rc = rc - '0' + NS_VK_0;
|
|
|
|
} else {
|
2010-03-04 10:19:41 -08:00
|
|
|
// For some characters, map the scan code to the NS_VK value
|
|
|
|
// This only happens in the char case NOT the VK case!
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (sc) {
|
|
|
|
case 0x02: rc = NS_VK_1; break;
|
|
|
|
case 0x03: rc = NS_VK_2; break;
|
|
|
|
case 0x04: rc = NS_VK_3; break;
|
|
|
|
case 0x05: rc = NS_VK_4; break;
|
|
|
|
case 0x06: rc = NS_VK_5; break;
|
|
|
|
case 0x07: rc = NS_VK_6; break;
|
|
|
|
case 0x08: rc = NS_VK_7; break;
|
|
|
|
case 0x09: rc = NS_VK_8; break;
|
|
|
|
case 0x0A: rc = NS_VK_9; break;
|
|
|
|
case 0x0B: rc = NS_VK_0; break;
|
|
|
|
case 0x0D: rc = NS_VK_EQUALS; break;
|
|
|
|
case 0x1A: rc = NS_VK_OPEN_BRACKET; break;
|
|
|
|
case 0x1B: rc = NS_VK_CLOSE_BRACKET; break;
|
|
|
|
case 0x27: rc = NS_VK_SEMICOLON; break;
|
|
|
|
case 0x28: rc = NS_VK_QUOTE; break;
|
|
|
|
case 0x29: rc = NS_VK_BACK_QUOTE; break;
|
|
|
|
case 0x2B: rc = NS_VK_BACK_SLASH; break;
|
|
|
|
case 0x33: rc = NS_VK_COMMA; break;
|
|
|
|
case 0x34: rc = NS_VK_PERIOD; break;
|
|
|
|
case 0x35: rc = NS_VK_SLASH; break;
|
|
|
|
case 0x37: rc = NS_VK_MULTIPLY; break;
|
|
|
|
case 0x4A: rc = NS_VK_SUBTRACT; break;
|
|
|
|
case 0x4C: rc = NS_VK_CLEAR; break; // numeric case is handled above
|
|
|
|
case 0x4E: rc = NS_VK_ADD; break;
|
|
|
|
case 0x5C: rc = NS_VK_DIVIDE; break;
|
|
|
|
default: break;
|
|
|
|
} // switch
|
|
|
|
} // else
|
|
|
|
} // if (rc < 0xFF)
|
|
|
|
} else if (flags & KC_VIRTUALKEY) {
|
2010-03-04 10:19:41 -08:00
|
|
|
USHORT vk = SHORT2FROMMP(mp2);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (flags & KC_KEYUP) { // On OS/2 there are extraneous bits in the upper byte of
|
|
|
|
// usChar when KC_KEYUP is set so mask them off
|
|
|
|
rc = rcmask;
|
|
|
|
}
|
|
|
|
if (isNumPadScanCode(sc) &&
|
|
|
|
(((flags & KC_ALT) && (sc != PMSCAN_PADPERIOD)) ||
|
|
|
|
((flags & (KC_CHAR | KC_SHIFT)) == KC_CHAR) ||
|
2010-03-04 10:19:41 -08:00
|
|
|
((flags & KC_KEYUP) && rc != 0))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
CHAR numpadMap[] = {NS_VK_NUMPAD7, NS_VK_NUMPAD8, NS_VK_NUMPAD9, 0,
|
|
|
|
NS_VK_NUMPAD4, NS_VK_NUMPAD5, NS_VK_NUMPAD6, 0,
|
|
|
|
NS_VK_NUMPAD1, NS_VK_NUMPAD2, NS_VK_NUMPAD3,
|
|
|
|
NS_VK_NUMPAD0, NS_VK_DECIMAL};
|
|
|
|
// If this is the Numpad must not return VK for ALT+Numpad or ALT+NumLock+Numpad
|
|
|
|
// NumLock+Numpad is OK
|
|
|
|
if (numpadMap[sc - PMSCAN_PAD7] != 0) { // not plus or minus on Numpad
|
2010-03-04 10:19:41 -08:00
|
|
|
if (flags & KC_ALT) { // do not react on Alt plus ASCII-code sequences
|
2007-03-22 10:30:00 -07:00
|
|
|
rc = 0;
|
2010-03-04 10:19:41 -08:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
rc = numpadMap[sc - PMSCAN_PAD7];
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else { // plus or minus of Numpad
|
|
|
|
rc = 0; // No virtual key for Alt+Numpad or NumLock+Numpad
|
|
|
|
}
|
|
|
|
} else if (!(flags & KC_CHAR) || isNumPadScanCode(sc) ||
|
|
|
|
(vk == VK_BACKSPACE) || (vk == VK_TAB) || (vk == VK_BACKTAB) ||
|
|
|
|
(vk == VK_ENTER) || (vk == VK_NEWLINE) || (vk == VK_SPACE)) {
|
|
|
|
if (vk >= VK_F1 && vk <= VK_F24) {
|
|
|
|
rc = NS_VK_F1 + (vk - VK_F1);
|
|
|
|
}
|
|
|
|
else switch (vk) {
|
|
|
|
case VK_NUMLOCK: rc = NS_VK_NUM_LOCK; break;
|
|
|
|
case VK_SCRLLOCK: rc = NS_VK_SCROLL_LOCK; break;
|
|
|
|
case VK_ESC: rc = NS_VK_ESCAPE; break; // NS_VK_CANCEL
|
|
|
|
case VK_BACKSPACE: rc = NS_VK_BACK; break;
|
|
|
|
case VK_TAB: rc = NS_VK_TAB; break;
|
|
|
|
case VK_BACKTAB: rc = NS_VK_TAB; break; // layout tests for isShift
|
|
|
|
case VK_CLEAR: rc = NS_VK_CLEAR; break;
|
|
|
|
case VK_NEWLINE: rc = NS_VK_RETURN; break;
|
|
|
|
case VK_ENTER: rc = NS_VK_RETURN; break;
|
|
|
|
case VK_SHIFT: rc = NS_VK_SHIFT; break;
|
|
|
|
case VK_CTRL: rc = NS_VK_CONTROL; break;
|
|
|
|
case VK_ALT: rc = NS_VK_ALT; break;
|
|
|
|
case VK_PAUSE: rc = NS_VK_PAUSE; break;
|
|
|
|
case VK_CAPSLOCK: rc = NS_VK_CAPS_LOCK; break;
|
|
|
|
case VK_SPACE: rc = NS_VK_SPACE; break;
|
|
|
|
case VK_PAGEUP: rc = NS_VK_PAGE_UP; break;
|
|
|
|
case VK_PAGEDOWN: rc = NS_VK_PAGE_DOWN; break;
|
|
|
|
case VK_END: rc = NS_VK_END; break;
|
|
|
|
case VK_HOME: rc = NS_VK_HOME; break;
|
|
|
|
case VK_LEFT: rc = NS_VK_LEFT; break;
|
|
|
|
case VK_UP: rc = NS_VK_UP; break;
|
|
|
|
case VK_RIGHT: rc = NS_VK_RIGHT; break;
|
|
|
|
case VK_DOWN: rc = NS_VK_DOWN; break;
|
|
|
|
case VK_PRINTSCRN: rc = NS_VK_PRINTSCREEN; break;
|
|
|
|
case VK_INSERT: rc = NS_VK_INSERT; break;
|
|
|
|
case VK_DELETE: rc = NS_VK_DELETE; break;
|
|
|
|
} // switch
|
|
|
|
}
|
|
|
|
} // KC_VIRTUALKEY
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//=============================================================================
|
|
|
|
// Event Dispatch
|
|
|
|
//=============================================================================
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
// Initialize an event to dispatch.
|
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
void nsWindow::InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
// if no point was supplied, calculate it
|
|
|
|
if (!aPoint) {
|
|
|
|
// for most events, get the message position; for drag events,
|
|
|
|
// msg position may be incorrect, so get the current position instead
|
|
|
|
POINTL ptl;
|
|
|
|
if (CheckDragStatus(ACTION_PTRPOS, 0)) {
|
|
|
|
WinQueryPointerPos(HWND_DESKTOP, &ptl);
|
|
|
|
} else {
|
|
|
|
WinQueryMsgPos(0, &ptl);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
WinMapWindowPoints(HWND_DESKTOP, mWnd, &ptl, 1);
|
|
|
|
PM2NS(ptl);
|
|
|
|
event.refPoint.x = ptl.x;
|
|
|
|
event.refPoint.y = ptl.y;
|
|
|
|
} else {
|
|
|
|
// use the point override if provided
|
|
|
|
event.refPoint.x = aPoint->x;
|
|
|
|
event.refPoint.y = aPoint->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.time = WinQueryMsgTime(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Invoke the Event Listener object's callback.
|
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
NS_IMETHODIMP nsWindow::DispatchEvent(WidgetGUIEvent* event,
|
|
|
|
nsEventStatus& aStatus)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if (!mEventCallback) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if state is eDoingDelete, don't send out anything
|
2012-08-15 11:52:35 -07:00
|
|
|
if (mWindowState & nsWindowState_eLive) {
|
2010-03-04 10:19:41 -08:00
|
|
|
aStatus = (*mEventCallback)(event);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
NS_IMETHODIMP nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
bool nsWindow::DispatchWindowEvent(WidgetGUIEvent* event)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(event, status);
|
|
|
|
return (status == nsEventStatus_eConsumeNoDefault);
|
|
|
|
}
|
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
bool nsWindow::DispatchWindowEvent(WidgetGUIEvent*event,
|
|
|
|
nsEventStatus &aStatus)
|
|
|
|
{
|
2010-03-04 10:19:41 -08:00
|
|
|
DispatchEvent(event, aStatus);
|
|
|
|
return (aStatus == nsEventStatus_eConsumeNoDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::DispatchCommandEvent(uint32_t aEventCommand)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> command;
|
|
|
|
|
|
|
|
switch (aEventCommand) {
|
|
|
|
case APPCOMMAND_BROWSER_BACKWARD:
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Back;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
case APPCOMMAND_BROWSER_FORWARD:
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Forward;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
case APPCOMMAND_BROWSER_REFRESH:
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Reload;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
case APPCOMMAND_BROWSER_STOP:
|
2011-10-14 11:11:22 -07:00
|
|
|
command = nsGkAtoms::Stop;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
2013-09-26 23:20:54 -07:00
|
|
|
WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, command, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
InitEvent(event);
|
|
|
|
return DispatchWindowEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::DispatchDragDropEvent(uint32_t aMsg)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetDragEvent event(true, aMsg, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
InitEvent(event);
|
|
|
|
|
2012-04-24 20:00:02 -07:00
|
|
|
event.InitBasicModifiers(isKeyDown(VK_CTRL),
|
|
|
|
isKeyDown(VK_ALT) || isKeyDown(VK_ALTGRAF),
|
|
|
|
isKeyDown(VK_SHIFT), false);
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
return DispatchWindowEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::DispatchMoveEvent(int32_t aX, int32_t aY)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
|
|
|
// Params here are in XP-space for the desktop
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent event(true, NS_MOVE, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
nsIntPoint point(aX, aY);
|
|
|
|
InitEvent(event, &point);
|
|
|
|
return DispatchWindowEvent(&event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::DispatchResizeEvent(int32_t aX, int32_t aY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsSizeEvent event(true, NS_SIZE, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
nsIntRect rect(0, 0, aX, aY);
|
|
|
|
|
|
|
|
InitEvent(event);
|
|
|
|
event.windowSize = ▭ // this is the *client* rectangle
|
|
|
|
event.mWinWidth = mBounds.width;
|
|
|
|
event.mWinHeight = mBounds.height;
|
|
|
|
|
|
|
|
return DispatchWindowEvent(&event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Deal with all sorts of mouse events.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::DispatchMouseEvent(uint32_t aEventType, MPARAM mp1, MPARAM mp2,
|
|
|
|
bool aIsContextMenuKey, int16_t aButton)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(aEventType, false);
|
2010-08-19 02:35:09 -07:00
|
|
|
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent event(true, aEventType, this, WidgetMouseEvent::eReal,
|
|
|
|
aIsContextMenuKey ?
|
|
|
|
WidgetMouseEvent::eContextMenuKey :
|
|
|
|
WidgetMouseEvent::eNormal);
|
2010-03-04 10:19:41 -08:00
|
|
|
event.button = aButton;
|
2012-06-20 03:09:05 -07:00
|
|
|
if (aEventType == NS_MOUSE_BUTTON_DOWN && mIsComposing) {
|
|
|
|
// If IME is composing, let it complete.
|
|
|
|
HIMI himi;
|
|
|
|
|
|
|
|
spfnImGetInstance(mWnd, &himi);
|
|
|
|
spfnImRequestIME(himi, REQ_CONVERSIONSTRING, CNV_COMPLETE, 0);
|
|
|
|
spfnImReleaseInstance(mWnd, himi);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 02:35:09 -07:00
|
|
|
if (aEventType == NS_MOUSE_ENTER || aEventType == NS_MOUSE_EXIT) {
|
|
|
|
// Ignore enter/leave msgs forwarded from the frame to FID_CLIENT
|
|
|
|
// because we're only interested msgs involving the content area.
|
|
|
|
if (HWNDFROMMP(mp1) != mWnd) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the mouse has exited the content area and entered either an
|
|
|
|
// unrelated window or what Windows would call the nonclient area
|
|
|
|
// (i.e. frame, titlebar, etc.), mark this as a toplevel exit.
|
|
|
|
// Note: exits to and from menus will also be marked toplevel.
|
|
|
|
if (aEventType == NS_MOUSE_EXIT) {
|
2010-10-14 14:12:26 -07:00
|
|
|
HWND hTop = 0;
|
2010-08-19 02:35:09 -07:00
|
|
|
HWND hCur = mWnd;
|
|
|
|
HWND hDesk = WinQueryDesktopWindow(0, 0);
|
|
|
|
while (hCur && hCur != hDesk) {
|
|
|
|
hTop = hCur;
|
|
|
|
hCur = WinQueryWindow(hCur, QW_PARENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// event.exit was init'ed to eChild, so we don't need an 'else'
|
|
|
|
hTop = WinWindowFromID(hTop, FID_CLIENT);
|
|
|
|
if (!hTop || !WinIsChild(HWNDFROMMP(mp2), hTop)) {
|
2013-10-01 23:38:27 -07:00
|
|
|
event.exit = WidgetMouseEvent::eTopLevel;
|
2010-08-19 02:35:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
InitEvent(event, nullptr);
|
2012-04-24 20:00:02 -07:00
|
|
|
event.InitBasicModifiers(isKeyDown(VK_CTRL),
|
|
|
|
isKeyDown(VK_ALT) || isKeyDown(VK_ALTGRAF),
|
|
|
|
isKeyDown(VK_SHIFT), false);
|
2010-08-19 02:35:09 -07:00
|
|
|
} else {
|
2010-03-04 10:19:41 -08:00
|
|
|
POINTL ptl;
|
|
|
|
if (aEventType == NS_CONTEXTMENU && aIsContextMenuKey) {
|
|
|
|
WinQueryPointerPos(HWND_DESKTOP, &ptl);
|
|
|
|
WinMapWindowPoints(HWND_DESKTOP, mWnd, &ptl, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2010-03-04 10:19:41 -08:00
|
|
|
ptl.x = (SHORT)SHORT1FROMMP(mp1);
|
|
|
|
ptl.y = (SHORT)SHORT2FROMMP(mp1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
PM2NS(ptl);
|
|
|
|
nsIntPoint pt(ptl.x, ptl.y);
|
|
|
|
InitEvent(event, &pt);
|
|
|
|
|
|
|
|
USHORT usFlags = SHORT2FROMMP(mp2);
|
2012-04-24 20:00:02 -07:00
|
|
|
event.InitBasicModifiers(usFlags & KC_CTRL, usFlags & KC_ALT,
|
|
|
|
usFlags & KC_SHIFT, false);
|
2010-03-04 10:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dblclicks are used to set the click count, then changed to mousedowns
|
|
|
|
if (aEventType == NS_MOUSE_DOUBLECLICK &&
|
2013-10-01 23:38:27 -07:00
|
|
|
(aButton == WidgetMouseEvent::eLeftButton ||
|
|
|
|
aButton == WidgetMouseEvent::eRightButton)) {
|
2010-03-04 10:19:41 -08:00
|
|
|
event.message = NS_MOUSE_BUTTON_DOWN;
|
2013-10-01 23:38:27 -07:00
|
|
|
event.button =
|
|
|
|
(aButton == WidgetMouseEvent::eLeftButton) ?
|
|
|
|
WidgetMouseEvent::eLeftButton : WidgetMouseEvent::eRightButton;
|
2010-03-04 10:19:41 -08:00
|
|
|
event.clickCount = 2;
|
|
|
|
} else {
|
|
|
|
event.clickCount = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
NPEvent pluginEvent;
|
|
|
|
switch (aEventType) {
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
|
|
switch (aButton) {
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eLeftButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON1DOWN;
|
|
|
|
break;
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eMiddleButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON3DOWN;
|
|
|
|
break;
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eRightButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON2DOWN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
|
|
|
switch (aButton) {
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eLeftButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON1UP;
|
|
|
|
break;
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eMiddleButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON3UP;
|
|
|
|
break;
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eRightButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON2UP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_DOUBLECLICK:
|
|
|
|
switch (aButton) {
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eLeftButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON1DBLCLK;
|
|
|
|
break;
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eMiddleButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON3DBLCLK;
|
|
|
|
break;
|
2013-10-01 23:38:27 -07:00
|
|
|
case WidgetMouseEvent::eRightButton:
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.event = WM_BUTTON2DBLCLK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
pluginEvent.event = WM_MOUSEMOVE;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
pluginEvent.wParam = 0;
|
|
|
|
pluginEvent.lParam = MAKELONG(event.refPoint.x, event.refPoint.y);
|
|
|
|
|
|
|
|
event.pluginEvent = (void*)&pluginEvent;
|
|
|
|
|
|
|
|
return DispatchWindowEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Signal plugin & top-level window activation.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool nsWindow::DispatchActivationEvent(uint32_t aEventType)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent event(true, aEventType, this);
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
// These events should go to their base widget location,
|
|
|
|
// not current mouse position.
|
|
|
|
nsIntPoint point(0, 0);
|
|
|
|
InitEvent(event, &point);
|
|
|
|
|
|
|
|
NPEvent pluginEvent;
|
|
|
|
switch (aEventType) {
|
|
|
|
case NS_ACTIVATE:
|
|
|
|
pluginEvent.event = WM_SETFOCUS;
|
|
|
|
break;
|
|
|
|
case NS_DEACTIVATE:
|
|
|
|
pluginEvent.event = WM_FOCUSCHANGED;
|
|
|
|
break;
|
|
|
|
case NS_PLUGIN_ACTIVATE:
|
|
|
|
pluginEvent.event = WM_FOCUSCHANGED;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
event.pluginEvent = (void*)&pluginEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
return DispatchWindowEvent(&event);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-04 10:19:41 -08:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWindow::DispatchScrollEvent(ULONG msg, MPARAM mp1, MPARAM mp2)
|
2010-03-04 10:19:41 -08:00
|
|
|
{
|
2013-10-16 02:37:36 -07:00
|
|
|
WidgetWheelEvent wheelEvent(true, NS_WHEEL_WHEEL, this);
|
2012-08-11 18:42:37 -07:00
|
|
|
InitEvent(wheelEvent);
|
2010-03-04 10:19:41 -08:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.InitBasicModifiers(isKeyDown(VK_CTRL),
|
|
|
|
isKeyDown(VK_ALT) || isKeyDown(VK_ALTGRAF),
|
|
|
|
isKeyDown(VK_SHIFT), false);
|
2010-03-04 10:19:41 -08:00
|
|
|
// The SB_* constants for analogous vertical & horizontal ops have the
|
|
|
|
// the same values, so only use the verticals to avoid compiler errors.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta;
|
2010-03-04 10:19:41 -08:00
|
|
|
switch (SHORT2FROMMP(mp2)) {
|
|
|
|
case SB_LINEUP:
|
|
|
|
// SB_LINELEFT:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaMode = nsIDOMWheelEvent.DOM_DELTA_LINE;
|
|
|
|
delta = -1;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SB_LINEDOWN:
|
|
|
|
// SB_LINERIGHT:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaMode = nsIDOMWheelEvent.DOM_DELTA_LINE;
|
|
|
|
delta = 1;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SB_PAGEUP:
|
|
|
|
// SB_PAGELEFT:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaMode = nsIDOMWheelEvent.DOM_DELTA_PAGE;
|
|
|
|
delta = -1;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SB_PAGEDOWN:
|
|
|
|
// SB_PAGERIGHT:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaMode = nsIDOMWheelEvent.DOM_DELTA_PAGE;
|
|
|
|
delta = 1;
|
2010-03-04 10:19:41 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-08-11 18:42:37 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-11 18:42:37 -07:00
|
|
|
|
|
|
|
if (msg == WM_HSCROLL) {
|
|
|
|
wheelEvent.deltaX = wheelEvent.lineOrPageDeltaX = delta;
|
|
|
|
} else {
|
|
|
|
wheelEvent.deltaY = wheelEvent.lineOrPageDeltaY = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchWindowEvent(&wheelEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 10:19:41 -08:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|