gecko-dev/widget/src/windows/nsWindow.cpp

3160 lines
91 KiB
C++
Raw Normal View History

1998-04-13 20:24:54 +00:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsWindow.h"
#include "nsIAppShell.h"
1998-04-13 20:24:54 +00:00
#include "nsIFontMetrics.h"
#include "nsFont.h"
1998-04-13 20:24:54 +00:00
#include "nsGUIEvent.h"
#include "nsIRenderingContext.h"
#include "nsIDeviceContext.h"
#include "nsRect.h"
#include "nsTransform2D.h"
#include "nsStringUtil.h"
1998-04-13 20:24:54 +00:00
#include <windows.h>
//#include <winuser.h>
#include <zmouse.h>
//#include "sysmets.h"
1998-04-13 20:24:54 +00:00
#include "nsGfxCIID.h"
#include "resource.h"
1998-04-17 00:16:11 +00:00
#include <commctrl.h>
1998-04-13 20:24:54 +00:00
#include "prtime.h"
#include "nsIRenderingContextWin.h"
1998-04-13 20:24:54 +00:00
1999-02-17 14:30:47 +00:00
#include "nsIMenu.h"
1999-03-01 16:22:40 +00:00
#include "nsMenu.h"
1999-02-17 14:30:47 +00:00
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
#include "nsMenuItem.h"
#include <imm.h>
1999-02-17 14:30:47 +00:00
//#define NEW_DRAG_AND_DROP
#ifdef NEW_DRAG_AND_DROP
#include "nsNativeDragTarget.h"
//#include "nsDropTarget.h"
//#include "DragDrop.h"
//#include "DropTar.h"
//#include "DropSrc.h"
#endif
1999-03-23 21:26:20 +00:00
// For clipboard support
#include "nsIServiceManager.h"
#include "nsIClipboard.h"
#include "nsWidgetsCID.h"
static NS_DEFINE_IID(kIClipboardIID, NS_ICLIPBOARD_IID);
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
1998-04-13 20:24:54 +00:00
BOOL nsWindow::sIsRegistered = FALSE;
1998-05-29 22:44:13 +00:00
nsWindow* nsWindow::gCurrentWindow = nsnull;
#define IS_VK_DOWN(a) (PRBool)(((GetKeyState(a) & 0x80)) ? (PR_TRUE) : (PR_FALSE))
// Global variable
// g_hinst - handle of the application instance
extern HINSTANCE g_hinst;
1998-04-13 20:24:54 +00:00
1999-02-17 14:30:47 +00:00
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
//static NS_DEFINE_IID(kIMenuListenerIID, NS_IMENULISTENER_IID);
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// nsWindow constructor
//
//-------------------------------------------------------------------------
nsWindow::nsWindow() : nsBaseWidget()
{
NS_INIT_REFCNT();
mWnd = 0;
mPrevWndProc = NULL;
mBackground = ::GetSysColor(COLOR_BTNFACE);
mBrush = ::CreateSolidBrush(NSRGB_2_COLOREF(mBackground));
mForeground = ::GetSysColor(COLOR_WINDOWTEXT);
mPalette = NULL;
mIsShiftDown = PR_FALSE;
mIsControlDown = PR_FALSE;
mIsAltDown = PR_FALSE;
mIsDestroying = PR_FALSE;
mOnDestroyCalled = PR_FALSE;
mTooltip = NULL;
mDeferredPositioner = NULL;
mLastPoint.x = 0;
mLastPoint.y = 0;
mPreferredWidth = 0;
mPreferredHeight = 0;
mFont = nsnull;
mIsVisible = PR_FALSE;
mHas3DBorder = PR_FALSE;
1999-02-17 14:30:47 +00:00
mMenuBar = nsnull;
mMenuCmdId = 0;
mHitMenu = nsnull;
mHitSubMenus = new nsVoidArray();
mVScrollbar = nsnull;
mIMEProperty = 0;
mIMEIsComposing = PR_FALSE;
mIMECompositionString = NULL;
mIMECompositionStringSize = 0;
mIMECompositionStringSize = 0;
mIMECompositionUniString = NULL;
#ifdef NEW_DRAG_AND_DROP
mNativeDragTarget = nsnull;
#endif
}
//-------------------------------------------------------------------------
//
// nsWindow destructor
//
//-------------------------------------------------------------------------
nsWindow::~nsWindow()
{
mIsDestroying = PR_TRUE;
if (gCurrentWindow == this) {
gCurrentWindow = nsnull;
}
MouseTrailer * mouseTrailer = MouseTrailer::GetMouseTrailer(0);
if (mouseTrailer->GetMouseTrailerWindow() == this) {
mouseTrailer->DestroyTimer();
}
// If the widget was released without calling Destroy() then the native
// window still exists, and we need to destroy it
if (NULL != mWnd) {
Destroy();
}
NS_IF_RELEASE(mHitMenu); // this should always have already been freed by the deselect
1999-05-06 01:43:12 +00:00
delete mHitSubMenus;
//XXX Temporary: Should not be caching the font
delete mFont;
}
1998-05-14 21:34:08 +00:00
//-------------------------------------------------------------------------
//
// Default for height modification is to do nothing
//
//-------------------------------------------------------------------------
PRInt32 nsWindow::GetHeight(PRInt32 aProposedHeight)
{
return(aProposedHeight);
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Deferred Window positioning
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::BeginResizingChildren(void)
{
if (NULL == mDeferredPositioner)
mDeferredPositioner = ::BeginDeferWindowPos(1);
return NS_OK;
}
NS_METHOD nsWindow::EndResizingChildren(void)
{
if (NULL != mDeferredPositioner) {
::EndDeferWindowPos(mDeferredPositioner);
mDeferredPositioner = NULL;
}
return NS_OK;
}
// DoCreateTooltip - creates a tooltip control and adds some tools
// to it.
// Returns the handle of the tooltip control if successful or NULL
// otherwise.
// hwndOwner - handle of the owner window
//
void nsWindow::AddTooltip(HWND hwndOwner,nsRect* aRect, int aId)
{
TOOLINFO ti; // tool information
memset(&ti, 0, sizeof(TOOLINFO));
// Make sure the common control DLL is loaded
InitCommonControls();
// Create a tooltip control for the window if needed
if (mTooltip == (HWND) NULL) {
mTooltip = CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU) NULL,
nsToolkit::mDllInstance,
NULL);
}
if (mTooltip == (HWND) NULL)
return;
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwndOwner;
ti.hinst = nsToolkit::mDllInstance;
ti.uId = aId;
ti.lpszText = (LPSTR)" "; // must set text to
// something for tooltip to give events;
ti.rect.left = aRect->x;
ti.rect.top = aRect->y;
ti.rect.right = aRect->x + aRect->width;
ti.rect.bottom = aRect->y + aRect->height;
if (!SendMessage(mTooltip, TTM_ADDTOOL, 0,
(LPARAM) (LPTOOLINFO) &ti))
return;
}
NS_METHOD nsWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect)
{
POINT point;
point.x = aOldRect.x;
point.y = aOldRect.y;
::ClientToScreen((HWND)GetNativeData(NS_NATIVE_WINDOW), &point);
aNewRect.x = point.x;
aNewRect.y = point.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_METHOD nsWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect)
{
POINT point;
point.x = aOldRect.x;
point.y = aOldRect.y;
::ScreenToClient((HWND)GetNativeData(NS_NATIVE_WINDOW), &point);
aNewRect.x = point.x;
aNewRect.y = point.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Setup initial tooltip rectangles
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[])
{
RemoveTooltips();
for (int i = 0; i < (int)aNumberOfTips; i++) {
AddTooltip(mWnd, aTooltipAreas[i], i);
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Update all tooltip rectangles
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::UpdateTooltips(nsRect* aNewTips[])
{
TOOLINFO ti;
memset(&ti, 0, sizeof(TOOLINFO));
ti.cbSize = sizeof(TOOLINFO);
ti.hwnd = mWnd;
// Get the number of tooltips
UINT count = ::SendMessage(mTooltip, TTM_GETTOOLCOUNT, 0, 0);
NS_ASSERTION(count > 0, "Called UpdateTooltips before calling SetTooltips");
for (UINT i = 0; i < count; i++) {
ti.uId = i;
int result =::SendMessage(mTooltip, TTM_ENUMTOOLS, i, (LPARAM) (LPTOOLINFO)&ti);
nsRect* newTip = aNewTips[i];
ti.rect.left = newTip->x;
ti.rect.top = newTip->y;
ti.rect.right = newTip->x + newTip->width;
ti.rect.bottom = newTip->y + newTip->height;
::SendMessage(mTooltip, TTM_NEWTOOLRECT, 0, (LPARAM) (LPTOOLINFO)&ti);
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Remove all tooltip rectangles
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::RemoveTooltips()
{
TOOLINFO ti;
memset(&ti, 0, sizeof(TOOLINFO));
ti.cbSize = sizeof(TOOLINFO);
long val;
if (mTooltip == NULL)
return NS_ERROR_FAILURE;
// Get the number of tooltips
UINT count = ::SendMessage(mTooltip, TTM_GETTOOLCOUNT, 0, (LPARAM)&val);
for (UINT i = 0; i < count; i++) {
ti.uId = i;
ti.hwnd = mWnd;
::SendMessage(mTooltip, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO)&ti);
}
return NS_OK;
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Convert nsEventStatus value to a windows boolean
//
//-------------------------------------------------------------------------
PRBool nsWindow::ConvertStatus(nsEventStatus aStatus)
{
switch(aStatus) {
1998-09-15 00:14:11 +00:00
case nsEventStatus_eIgnore:
return PR_FALSE;
case nsEventStatus_eConsumeNoDefault:
return PR_TRUE;
case nsEventStatus_eConsumeDoDefault:
return PR_FALSE;
default:
NS_ASSERTION(0, "Illegal nsEventStatus enumeration value");
1998-04-13 20:24:54 +00:00
break;
}
1998-09-15 00:14:11 +00:00
return PR_FALSE;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Initialize an event to dispatch
//
//-------------------------------------------------------------------------
1998-05-29 22:44:13 +00:00
void nsWindow::InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint)
{
event.widget = this;
NS_ADDREF(event.widget);
1998-05-29 22:44:13 +00:00
if (nsnull == aPoint) { // use the point from the event
// get the message position in client coordinates and in twips
DWORD pos = ::GetMessagePos();
POINT cpos;
1998-05-29 22:44:13 +00:00
cpos.x = LOWORD(pos);
cpos.y = HIWORD(pos);
if (mWnd != NULL) {
::ScreenToClient(mWnd, &cpos);
event.point.x = cpos.x;
event.point.y = cpos.y;
1998-08-04 21:06:35 +00:00
} else {
event.point.x = 0;
event.point.y = 0;
}
1998-05-29 22:44:13 +00:00
}
else { // use the point override if provided
event.point.x = aPoint->x;
event.point.y = aPoint->y;
}
event.time = ::GetMessageTime();
event.message = aEventType;
1998-05-29 22:44:13 +00:00
mLastPoint.x = event.point.x;
mLastPoint.y = event.point.y;
}
//-------------------------------------------------------------------------
//
// Invokes callback and ProcessEvent method on Event Listener object
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus)
{
aStatus = nsEventStatus_eIgnore;
1999-02-04 03:01:05 +00:00
//if (nsnull != mMenuListener)
// aStatus = mMenuListener->MenuSelected(*event);
if (nsnull != mEventCallback) {
aStatus = (*mEventCallback)(event);
}
// Dispatch to event listener if event was not consumed
if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) {
aStatus = mEventListener->ProcessEvent(*event);
}
// the window can be destroyed during processing of seemingly innocuous events like, say,
// mousedowns due to the magic of scripting. mousedowns will return nsEventStatus_eIgnore,
// which causes problems with the deleted window. therefore:
if (mOnDestroyCalled)
aStatus = nsEventStatus_eConsumeNoDefault;
return NS_OK;
}
//-------------------------------------------------------------------------
PRBool nsWindow::DispatchWindowEvent(nsGUIEvent* event)
{
nsEventStatus status;
DispatchEvent(event, status);
return ConvertStatus(status);
}
//-------------------------------------------------------------------------
//
// Dispatch standard event
//
//-------------------------------------------------------------------------
PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg)
{
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
InitEvent(event, aMsg);
PRBool result = DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
return result;
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// the nsWindow procedure for all nsWindows in this toolkit
//
//-------------------------------------------------------------------------
LRESULT CALLBACK nsWindow::WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
1998-04-17 00:16:11 +00:00
// Get the window which caused the event and ask it to process the message
nsWindow *someWindow = (nsWindow*)::GetWindowLong(hWnd, GWL_USERDATA);
1998-04-17 00:16:11 +00:00
// Re-direct a tab change message destined for its parent window to the
// the actual window which generated the event.
1998-04-17 00:16:11 +00:00
if (msg == WM_NOTIFY) {
LPNMHDR pnmh = (LPNMHDR) lParam;
if (pnmh->code == TCN_SELCHANGE) {
someWindow = (nsWindow*)::GetWindowLong(pnmh->hwndFrom, GWL_USERDATA);
}
}
1998-04-13 20:24:54 +00:00
if (nsnull != someWindow) {
LRESULT retValue;
if (PR_TRUE == someWindow->ProcessMessage(msg, wParam, lParam, &retValue)) {
return retValue;
}
}
#if defined(STRICT)
return ::CallWindowProc((WNDPROC)someWindow->GetPrevWindowProc(), hWnd,
msg, wParam, lParam);
#else
return ::CallWindowProc((FARPROC)someWindow->GetPrevWindowProc(), hWnd,
msg, wParam, lParam);
#endif
1998-04-13 20:24:54 +00:00
}
//WINOLEAPI oleStatus;
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Utility method for implementing both Create(nsIWidget ...) and
// Create(nsNativeWidget...)
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
1999-03-23 21:26:20 +00:00
// This is needed for drag & drop & Clipboard support
BOOL gOLEInited = FALSE;
nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent,
1998-04-13 20:24:54 +00:00
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData,
nsNativeWidget aNativeParent)
1998-04-13 20:24:54 +00:00
{
BaseCreate(aParent, aRect, aHandleEventFunction, aContext,
aAppShell, aToolkit, aInitData);
// See if the caller wants to explictly set clip children and clip siblings
DWORD style = WindowStyle();
if (nsnull != aInitData) {
if (aInitData->clipChildren) {
style |= WS_CLIPCHILDREN;
} else {
style &= ~WS_CLIPCHILDREN;
}
if (aInitData->clipSiblings) {
style |= WS_CLIPSIBLINGS;
}
}
1998-04-13 20:24:54 +00:00
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
//
nsToolkit* toolkit = (nsToolkit *)mToolkit;
if (toolkit) {
if (!toolkit->IsGuiThread()) {
DWORD args[7];
1998-04-13 20:24:54 +00:00
args[0] = (DWORD)aParent;
args[1] = (DWORD)&aRect;
args[2] = (DWORD)aHandleEventFunction;
args[3] = (DWORD)aContext;
args[4] = (DWORD)aAppShell;
args[5] = (DWORD)aToolkit;
args[6] = (DWORD)aInitData;
1998-04-13 20:24:54 +00:00
if (nsnull != aParent) {
// nsIWidget parent dispatch
MethodInfo info(this, nsWindow::CREATE, 7, args);
toolkit->CallMethod(&info);
return NS_OK;
}
else {
// Native parent dispatch
MethodInfo info(this, nsWindow::CREATE_NATIVE, 5, args);
toolkit->CallMethod(&info);
return NS_OK;
}
}
}
HWND parent;
if (nsnull != aParent) { // has a nsIWidget parent
parent = ((aParent) ? (HWND)aParent->GetNativeData(NS_NATIVE_WINDOW) : nsnull);
} else { // has a nsNative parent
parent = (HWND)aNativeParent;
}
DWORD extendedStyle = WindowExStyle();
1998-11-02 19:13:05 +00:00
if (nsnull != aInitData) {
if (aInitData->mBorderStyle == eBorderStyle_dialog ||
aInitData->mBorderStyle == eBorderStyle_none) {
extendedStyle &= ~WS_EX_CLIENTEDGE;
1998-11-02 19:13:05 +00:00
} else if (aInitData->mBorderStyle == eBorderStyle_3DChildWindow) {
extendedStyle |= WS_EX_CLIENTEDGE;
}
}
mHas3DBorder = (extendedStyle & WS_EX_CLIENTEDGE) > 0;
mWnd = ::CreateWindowEx(extendedStyle,
1998-04-13 20:24:54 +00:00
WindowClass(),
"",
style,
1998-04-13 20:24:54 +00:00
aRect.x,
aRect.y,
aRect.width,
1998-05-14 21:34:08 +00:00
GetHeight(aRect.height),
parent,
1998-04-13 20:24:54 +00:00
NULL,
nsToolkit::mDllInstance,
NULL);
VERIFY(mWnd);
1998-04-13 20:24:54 +00:00
// Initial Drag & Drop Work
if (!gOLEInited) {
DWORD dwVer = ::OleBuildVersion();
if (FAILED(::OleInitialize(NULL))){
1999-03-23 21:26:20 +00:00
printf("***** OLE has not been initialized!\n");
} else {
1999-03-24 18:42:34 +00:00
//if defined(DEBUG) printf("***** OLE has been initialized!\n");
}
gOLEInited = TRUE;
}
#ifdef NEW_DRAG_AND_DROP
mNativeDragTarget = new nsNativeDragTarget(this);
if (NULL != mNativeDragTarget) {
mNativeDragTarget->AddRef();
if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget,TRUE,FALSE)) {
if (S_OK == ::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget)) {
}
}
}
#endif
1998-04-13 20:24:54 +00:00
// call the event callback to notify about creation
DispatchStandardEvent(NS_CREATE);
1998-04-13 20:24:54 +00:00
SubclassWindow(TRUE);
return(NS_OK);
}
//-------------------------------------------------------------------------
//
// Create the proper widget
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
return(StandardWindowCreate(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData,
nsnull));
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// create with a native parent
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Create(nsNativeWidget aParent,
1998-04-13 20:24:54 +00:00
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
1998-05-14 21:34:08 +00:00
nsWidgetInitData *aInitData)
1998-04-13 20:24:54 +00:00
{
return(StandardWindowCreate(nsnull, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData,
aParent));
1998-04-13 20:24:54 +00:00
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Close this nsWindow
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Destroy()
1998-04-13 20:24:54 +00:00
{
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
nsToolkit* toolkit = (nsToolkit *)mToolkit;
if (toolkit != nsnull && !toolkit->IsGuiThread()) {
MethodInfo info(this, nsWindow::DESTROY);
toolkit->CallMethod(&info);
return NS_ERROR_FAILURE;
}
1998-04-13 20:24:54 +00:00
// disconnect from the parent
if (!mIsDestroying) {
nsBaseWidget::Destroy();
}
#ifdef NEW_DRAG_AND_DROP
if (NULL != mNativeDragTarget) {
if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget, FALSE, TRUE)) {
}
NS_RELEASE(mNativeDragTarget);
}
#endif
// destroy the HWND
if (mWnd) {
// prevent the widget from causing additional events
mEventCallback = nsnull;
VERIFY(::DestroyWindow(mWnd));
mWnd = NULL;
//our windows can be subclassed by
//others and these namless, faceless others
//may not let us know about WM_DESTROY. so,
//if OnDestroy() didn't get called, just call
//it now. MMP
if (PR_FALSE == mOnDestroyCalled)
OnDestroy();
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Get this nsWindow parent
//
//-------------------------------------------------------------------------
nsIWidget* nsWindow::GetParent(void)
{
nsWindow* widget = NULL;
1998-04-13 20:24:54 +00:00
if (mWnd) {
HWND parent = ::GetParent(mWnd);
if (parent) {
widget = (nsWindow *)::GetWindowLong(parent, GWL_USERDATA);
if (widget) {
// If the widget is in the process of being destroyed then
// do NOT return it
if (widget->mIsDestroying) {
widget = NULL;
} else {
NS_ADDREF(widget);
}
}
1998-04-13 20:24:54 +00:00
}
}
return (nsIWidget*)widget;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Hide or show this component
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Show(PRBool bState)
1998-04-13 20:24:54 +00:00
{
if (mWnd) {
if (bState) {
::SetWindowPos(mWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
}
else
::ShowWindow(mWnd, SW_HIDE);
}
mIsVisible = bState;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Return PR_TRUE if the whether the component is visible, PR_FALSE otherwise
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::IsVisible(PRBool & bState)
{
bState = mIsVisible;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Move this component
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Move(PRUint32 aX, PRUint32 aY)
1998-04-13 20:24:54 +00:00
{
mBounds.x = aX;
mBounds.y = aY;
1998-04-13 20:24:54 +00:00
if (mWnd) {
nsIWidget *par = GetParent();
HDWP deferrer = NULL;
if (nsnull != par) {
deferrer = ((nsWindow *)par)->mDeferredPositioner;
}
if (NULL != deferrer) {
VERIFY(((nsWindow *)par)->mDeferredPositioner = ::DeferWindowPos(deferrer,
mWnd, NULL, aX, aY, 0, 0,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE));
}
else {
VERIFY(::SetWindowPos(mWnd, NULL, aX, aY, 0, 0,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE));
}
NS_IF_RELEASE(par);
1998-04-13 20:24:54 +00:00
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Resize this component
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint)
1998-04-13 20:24:54 +00:00
{
// Set cached value for lightweight and printing
mBounds.width = aWidth;
mBounds.height = aHeight;
1998-04-13 20:24:54 +00:00
if (mWnd) {
nsIWidget *par = GetParent();
HDWP deferrer = NULL;
if (nsnull != par) {
deferrer = ((nsWindow *)par)->mDeferredPositioner;
}
UINT flags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE;
if (!aRepaint) {
flags |= SWP_NOREDRAW;
}
if (NULL != deferrer) {
VERIFY(((nsWindow *)par)->mDeferredPositioner = ::DeferWindowPos(deferrer,
mWnd, NULL, 0, 0, aWidth, GetHeight(aHeight), flags));
}
else {
1998-05-14 21:34:08 +00:00
VERIFY(::SetWindowPos(mWnd, NULL, 0, 0, aWidth, GetHeight(aHeight),
flags));
}
NS_IF_RELEASE(par);
1998-04-13 20:24:54 +00:00
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Resize this component
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Resize(PRUint32 aX,
PRUint32 aY,
PRUint32 aWidth,
PRUint32 aHeight,
PRBool aRepaint)
1998-04-13 20:24:54 +00:00
{
// Set cached value for lightweight and printing
mBounds.x = aX;
mBounds.y = aY;
mBounds.width = aWidth;
mBounds.height = aHeight;
1998-04-13 20:24:54 +00:00
if (mWnd) {
nsIWidget *par = GetParent();
HDWP deferrer = NULL;
if (nsnull != par) {
deferrer = ((nsWindow *)par)->mDeferredPositioner;
}
UINT flags = SWP_NOZORDER | SWP_NOACTIVATE;
if (!aRepaint) {
flags |= SWP_NOREDRAW;
}
if (NULL != deferrer) {
VERIFY(((nsWindow *)par)->mDeferredPositioner = ::DeferWindowPos(deferrer,
mWnd, NULL, aX, aY, aWidth, GetHeight(aHeight),
flags));
}
else {
1998-05-14 21:34:08 +00:00
VERIFY(::SetWindowPos(mWnd, NULL, aX, aY, aWidth, GetHeight(aHeight),
flags));
}
NS_IF_RELEASE(par);
1998-04-13 20:24:54 +00:00
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Enable/disable this component
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Enable(PRBool bState)
1998-04-13 20:24:54 +00:00
{
if (mWnd) {
::EnableWindow(mWnd, bState);
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Give the focus to this component
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetFocus(void)
1998-04-13 20:24:54 +00:00
{
//
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
//
nsToolkit* toolkit = (nsToolkit *)mToolkit;
if (!toolkit->IsGuiThread()) {
1998-04-13 20:24:54 +00:00
MethodInfo info(this, nsWindow::SET_FOCUS);
toolkit->CallMethod(&info);
return NS_ERROR_FAILURE;
1998-04-13 20:24:54 +00:00
}
if (mWnd) {
::SetFocus(mWnd);
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Get this component dimension
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::GetBounds(nsRect &aRect)
1998-04-13 20:24:54 +00:00
{
if (mWnd) {
RECT r;
VERIFY(::GetWindowRect(mWnd, &r));
// assign size
aRect.width = r.right - r.left;
aRect.height = r.bottom - r.top;
// convert coordinates if parent exists
HWND parent = ::GetParent(mWnd);
if (parent) {
RECT pr;
VERIFY(::GetWindowRect(parent, &pr));
r.left -= pr.left;
r.top -= pr.top;
}
aRect.x = r.left;
aRect.y = r.top;
} else {
aRect = mBounds;
}
1998-04-13 20:24:54 +00:00
return NS_OK;
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Get this component dimension
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::GetClientBounds(nsRect &aRect)
{
if (mWnd) {
RECT r;
VERIFY(::GetClientRect(mWnd, &r));
// assign size
aRect.x = 0;
aRect.y = 0;
aRect.width = r.right - r.left;
aRect.height = r.bottom - r.top;
} else {
aRect.SetRect(0,0,0,0);
}
return NS_OK;
}
//get the bounds, but don't take into account the client size
void nsWindow::GetNonClientBounds(nsRect &aRect)
{
if (mWnd) {
RECT r;
VERIFY(::GetWindowRect(mWnd, &r));
// assign size
aRect.width = r.right - r.left;
aRect.height = r.bottom - r.top;
// convert coordinates if parent exists
HWND parent = ::GetParent(mWnd);
if (parent) {
RECT pr;
VERIFY(::GetWindowRect(parent, &pr));
r.left -= pr.left;
r.top -= pr.top;
}
aRect.x = r.left;
aRect.y = r.top;
} else {
aRect.SetRect(0,0,0,0);
}
1998-04-13 20:24:54 +00:00
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Set the background color
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetBackgroundColor(const nscolor &aColor)
1998-04-13 20:24:54 +00:00
{
nsBaseWidget::SetBackgroundColor(aColor);
if (mBrush)
::DeleteObject(mBrush);
1998-04-13 20:24:54 +00:00
mBrush = ::CreateSolidBrush(NSRGB_2_COLOREF(mBackground));
if (mWnd != NULL) {
SetClassLong(mWnd, GCL_HBRBACKGROUND, (LONG)mBrush);
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Get this component font
//
//-------------------------------------------------------------------------
nsIFontMetrics* nsWindow::GetFont(void)
{
NS_NOTYETIMPLEMENTED("GetFont not yet implemented"); // to be implemented
return NULL;
}
//-------------------------------------------------------------------------
//
// Set this component font
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetFont(const nsFont &aFont)
1998-04-13 20:24:54 +00:00
{
// Cache Font for owner draw
if (mFont == nsnull) {
mFont = new nsFont(aFont);
} else {
*mFont = aFont;
}
// Bail out if there is no context
if (nsnull == mContext) {
return NS_ERROR_FAILURE;
}
nsIFontMetrics* metrics;
mContext->GetMetricsFor(aFont, metrics);
nsFontHandle fontHandle;
metrics->GetFontHandle(fontHandle);
HFONT hfont = (HFONT)fontHandle;
// Draw in the new font
::SendMessage(mWnd, WM_SETFONT, (WPARAM)hfont, (LPARAM)0);
NS_RELEASE(metrics);
return NS_OK;
1998-04-13 20:24:54 +00:00
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Set this component cursor
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
1998-04-13 20:24:54 +00:00
{
1998-04-13 20:24:54 +00:00
// Only change cursor if it's changing
//XXX mCursor isn't always right. Scrollbars and others change it, too.
//XXX If we want this optimization we need a better way to do it.
//if (aCursor != mCursor) {
1998-04-13 20:24:54 +00:00
HCURSOR newCursor = NULL;
switch(aCursor) {
case eCursor_select:
newCursor = ::LoadCursor(NULL, IDC_IBEAM);
break;
case eCursor_wait:
newCursor = ::LoadCursor(NULL, IDC_WAIT);
break;
case eCursor_hyperlink: {
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_SELECTANCHOR));
1998-04-13 20:24:54 +00:00
break;
}
case eCursor_standard:
newCursor = ::LoadCursor(NULL, IDC_ARROW);
break;
case eCursor_sizeWE:
newCursor = ::LoadCursor(NULL, IDC_SIZEWE);
break;
case eCursor_sizeNS:
newCursor = ::LoadCursor(NULL, IDC_SIZENS);
break;
1998-08-07 14:45:46 +00:00
case eCursor_arrow_north:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWNORTH));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_north_plus:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWNORTHPLUS));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_south:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWSOUTH));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_south_plus:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWSOUTHPLUS));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_east:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWEAST));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_east_plus:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWEASTPLUS));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_west:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWWEST));
1998-08-07 14:45:46 +00:00
break;
case eCursor_arrow_west_plus:
newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWWESTPLUS));
1998-08-07 14:45:46 +00:00
break;
1998-04-13 20:24:54 +00:00
default:
NS_ASSERTION(0, "Invalid cursor type");
break;
}
if (NULL != newCursor) {
mCursor = aCursor;
HCURSOR oldCursor = ::SetCursor(newCursor);
}
//}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Invalidate this component visible area
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Invalidate(PRBool aIsSynchronous)
1998-04-13 20:24:54 +00:00
{
if (mWnd) {
VERIFY(::InvalidateRect(mWnd, NULL, TRUE));
if (aIsSynchronous) {
VERIFY(::UpdateWindow(mWnd));
}
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Invalidate this component visible area
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous)
{
RECT rect;
if (mWnd) {
rect.left = aRect.x;
rect.top = aRect.y;
rect.right = aRect.x + aRect.width;
rect.bottom = aRect.y + aRect.height;
VERIFY(::InvalidateRect(mWnd, &rect, TRUE));
if (aIsSynchronous) {
VERIFY(::UpdateWindow(mWnd));
}
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Force a synchronous repaint of the window
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsWindow::Update()
{
// updates can come through for windows no longer holding an mWnd during
// deletes triggered by JavaScript in buttons with mouse feedback
if (mWnd)
VERIFY(::UpdateWindow(mWnd));
return NS_OK;
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Return some native data according to aDataType
//
//-------------------------------------------------------------------------
void* nsWindow::GetNativeData(PRUint32 aDataType)
{
switch(aDataType) {
case NS_NATIVE_WIDGET:
1998-04-13 20:24:54 +00:00
case NS_NATIVE_WINDOW:
case NS_NATIVE_PLUGIN_PORT:
1998-04-13 20:24:54 +00:00
return (void*)mWnd;
case NS_NATIVE_GRAPHIC:
// XXX: This is sleezy!! Remember to Release the DC after using it!
1998-04-13 20:24:54 +00:00
return (void*)::GetDC(mWnd);
case NS_NATIVE_COLORMAP:
default:
break;
}
return NULL;
}
//-------------------------------------------------------------------------
//
// Set the colormap of the window
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::SetColorMap(nsColorMap *aColorMap)
1998-04-13 20:24:54 +00:00
{
if (mPalette != NULL) {
::DeleteObject(mPalette);
}
PRUint8 *map = aColorMap->Index;
LPLOGPALETTE pLogPal = (LPLOGPALETTE) new char[2 * sizeof(WORD) +
aColorMap->NumColors * sizeof(PALETTEENTRY)];
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = aColorMap->NumColors;
for(int i = 0; i < aColorMap->NumColors; i++)
{
pLogPal->palPalEntry[i].peRed = *map++;
pLogPal->palPalEntry[i].peGreen = *map++;
pLogPal->palPalEntry[i].peBlue = *map++;
pLogPal->palPalEntry[i].peFlags = 0;
}
mPalette = ::CreatePalette(pLogPal);
delete pLogPal;
NS_ASSERTION(mPalette != NULL, "Null palette");
if (mPalette != NULL) {
HDC hDC = ::GetDC(mWnd);
HPALETTE hOldPalette = ::SelectPalette(hDC, mPalette, TRUE);
::RealizePalette(hDC);
::SelectPalette(hDC, hOldPalette, TRUE);
::ReleaseDC(mWnd, hDC);
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Scroll the bits of a window
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect)
1998-04-13 20:24:54 +00:00
{
RECT trect;
if (nsnull != aClipRect)
{
trect.left = aClipRect->x;
trect.top = aClipRect->y;
trect.right = aClipRect->XMost();
trect.bottom = aClipRect->YMost();
}
::ScrollWindowEx(mWnd, aDx, aDy, (nsnull != aClipRect) ? &trect : NULL, NULL,
NULL, NULL, SW_INVALIDATE | SW_SCROLLCHILDREN);
1998-04-13 20:24:54 +00:00
::UpdateWindow(mWnd);
return NS_OK;
1998-04-13 20:24:54 +00:00
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Every function that needs a thread switch goes through this function
// by calling SendMessage (..WM_CALLMETHOD..) in nsToolkit::CallMethod.
//
//-------------------------------------------------------------------------
BOOL nsWindow::CallMethod(MethodInfo *info)
{
BOOL bRet = TRUE;
switch (info->methodId) {
case nsWindow::CREATE:
NS_ASSERTION(info->nArgs == 7, "Wrong number of arguments to CallMethod");
1998-04-13 20:24:54 +00:00
Create((nsIWidget*)(info->args[0]),
(nsRect&)*(nsRect*)(info->args[1]),
(EVENT_CALLBACK)(info->args[2]),
(nsIDeviceContext*)(info->args[3]),
(nsIAppShell *)(info->args[4]),
(nsIToolkit*)(info->args[5]),
(nsWidgetInitData*)(info->args[6]));
1998-04-13 20:24:54 +00:00
break;
case nsWindow::CREATE_NATIVE:
NS_ASSERTION(info->nArgs == 7, "Wrong number of arguments to CallMethod");
Create((nsNativeWidget)(info->args[0]),
1998-04-13 20:24:54 +00:00
(nsRect&)*(nsRect*)(info->args[1]),
(EVENT_CALLBACK)(info->args[2]),
(nsIDeviceContext*)(info->args[3]),
(nsIAppShell *)(info->args[4]),
(nsIToolkit*)(info->args[5]),
(nsWidgetInitData*)(info->args[6]));
1998-04-13 20:24:54 +00:00
return TRUE;
case nsWindow::DESTROY:
NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod");
Destroy();
break;
case nsWindow::SET_FOCUS:
NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod");
SetFocus();
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
//-------------------------------------------------------------------------
void nsWindow::SetUpForPaint(HDC aHDC)
{
::SetBkColor (aHDC, NSRGB_2_COLOREF(mBackground));
::SetTextColor(aHDC, NSRGB_2_COLOREF(mForeground));
::SetBkMode (aHDC, TRANSPARENT);
}
1998-04-13 20:24:54 +00:00
1999-02-17 14:30:47 +00:00
//-------------------------------------------------------------------------
nsIMenuItem * nsWindow::FindMenuItem(nsIMenu * aMenu, PRUint32 aId)
1999-02-17 14:30:47 +00:00
{
PRUint32 i, count;
aMenu->GetItemCount(count);
for (i=0;i<count;i++) {
nsISupports * item;
nsIMenuItem * menuItem;
nsIMenu * menu;
aMenu->GetItemAt(i, item);
1999-02-17 14:30:47 +00:00
if (NS_OK == item->QueryInterface(kIMenuItemIID, (void **)&menuItem)) {
if (((nsMenuItem *)menuItem)->GetCmdId() == (PRInt32)aId) {
NS_RELEASE(item);
1999-02-17 14:30:47 +00:00
return menuItem;
}
} else if (NS_OK == item->QueryInterface(kIMenuIID, (void **)&menu)) {
nsIMenuItem * fndItem = FindMenuItem(menu, aId);
NS_RELEASE(menu);
if (nsnull != fndItem) {
NS_RELEASE(item);
return fndItem;
}
}
NS_RELEASE(item);
}
return nsnull;
}
//-------------------------------------------------------------------------
static nsIMenuItem * FindMenuChild(nsIMenu * aMenu, PRInt32 aId)
{
PRUint32 i, count;
aMenu->GetItemCount(count);
for (i=0;i<count;i++) {
nsISupports * item;
aMenu->GetItemAt(i, item);
nsIMenuItem * menuItem;
if (NS_OK == item->QueryInterface(kIMenuItemIID, (void **)&menuItem)) {
if (((nsMenuItem *)menuItem)->GetCmdId() == (PRInt32)aId) {
NS_RELEASE(item);
return menuItem;
}
1999-02-17 14:30:47 +00:00
}
NS_RELEASE(item);
1999-02-17 14:30:47 +00:00
}
return nsnull;
}
1999-03-01 16:22:40 +00:00
//-------------------------------------------------------------------------
nsIMenu * nsWindow::FindMenu(nsIMenu * aMenu, HMENU aNativeMenu, PRInt32 &aDepth)
1999-03-01 16:22:40 +00:00
{
if (aNativeMenu == ((nsMenu *)aMenu)->GetNativeMenu()) {
NS_ADDREF(aMenu);
return aMenu;
}
1999-04-30 21:13:42 +00:00
//aDepth++;
1999-03-01 16:22:40 +00:00
PRUint32 i, count;
aMenu->GetItemCount(count);
for (i=0;i<count;i++) {
nsISupports * item;
aMenu->GetItemAt(i, item);
nsIMenu * menu;
if (NS_OK == item->QueryInterface(kIMenuIID, (void **)&menu)) {
HMENU nativeMenu = ((nsMenu *)menu)->GetNativeMenu();
if (nativeMenu == aNativeMenu) {
1999-04-30 21:13:42 +00:00
aDepth++;
1999-03-01 16:22:40 +00:00
return menu;
} else {
nsIMenu * fndMenu = FindMenu(menu, aNativeMenu, aDepth);
if (fndMenu) {
NS_RELEASE(item);
NS_RELEASE(menu);
1999-04-30 21:13:42 +00:00
aDepth++;
return fndMenu;
}
1999-03-01 16:22:40 +00:00
}
NS_RELEASE(menu);
1999-03-01 16:22:40 +00:00
}
NS_RELEASE(item);
1999-03-01 16:22:40 +00:00
}
return nsnull;
}
//-------------------------------------------------------------------------
static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent)
{
if (nsnull != aCurrentMenu) {
nsIMenuListener * listener;
if (NS_OK == aCurrentMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
1999-04-19 08:23:18 +00:00
//listener->MenuDeselected(aEvent);
NS_RELEASE(listener);
}
}
if (nsnull != aNewMenu) {
nsIMenuListener * listener;
if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
1999-04-20 01:18:55 +00:00
NS_ASSERTION(false, "get debugger");
1999-04-19 08:23:18 +00:00
//listener->MenuSelected(aEvent);
NS_RELEASE(listener);
}
}
}
1999-04-19 08:23:18 +00:00
//-------------------------------------------------------------------------
1999-04-19 08:23:18 +00:00
nsresult nsWindow::MenuHasBeenSelected(
HMENU aNativeMenu,
UINT aItemNum,
UINT aFlags,
UINT aCommand)
{
1999-04-19 08:23:18 +00:00
// Build nsMenuEvent
nsMenuEvent event;
event.mCommand = aCommand;
event.eventStructType = NS_MENU_EVENT;
InitEvent(event, NS_MENU_SELECTED);
// The MF_POPUP flag tells us if we are a menu item or a menu
1999-03-05 21:04:57 +00:00
// the aItemNum is either the command ID of the menu item or
1999-04-19 08:23:18 +00:00
// the position of the menu as a child of its parent
PRBool isMenuItem = !(aFlags & MF_POPUP);
if(isMenuItem) {
//printf("WM_MENUSELECT for menu item\n");
//return NS_OK;
}
else
{
//printf("WM_MENUSELECT for menu\n");
}
// uItem is the position of the item that was clicked
1999-03-05 21:04:57 +00:00
// aNativeMenu is a handle to the menu that was clicked
1999-03-05 21:04:57 +00:00
// if aNativeMenu is NULL then the menu is being deselected
if (!aNativeMenu) {
//printf("... for deselect\n");
//printf("///////////// Menu is NULL!\n");
// check to make sure something had been selected
1999-04-20 01:18:55 +00:00
//AdjustMenus(mHitMenu, nsnull, event);
nsIMenu * aNewMenu = nsnull;
nsMenuEvent aEvent = event;
//static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent)
{
if (nsnull != mHitMenu) {
nsIMenuListener * listener;
if (NS_OK == mHitMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuDeselected(aEvent);
NS_RELEASE(listener);
}
}
if (nsnull != aNewMenu) {
nsIMenuListener * listener;
if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuSelected(aEvent);
NS_RELEASE(listener);
}
}
}
1999-04-20 01:18:55 +00:00
NS_IF_RELEASE(mHitMenu);
// Clear All SubMenu items
while (mHitSubMenus->Count() > 0) {
PRUint32 inx = mHitSubMenus->Count()-1;
nsIMenu * menu = (nsIMenu *)mHitSubMenus->ElementAt(inx);
1999-04-20 01:18:55 +00:00
//AdjustMenus(menu, nsnull, event);
nsIMenu * aCurrentMenu = menu;
nsIMenu * aNewMenu = nsnull;
//static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent)
{
if (nsnull != aCurrentMenu) {
nsIMenuListener * listener;
if (NS_OK == aCurrentMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuDeselected(event);
NS_RELEASE(listener);
}
}
if (nsnull != aNewMenu) {
nsIMenuListener * listener;
if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuSelected(event);
NS_RELEASE(listener);
}
}
}
1999-04-20 01:18:55 +00:00
NS_RELEASE(menu);
mHitSubMenus->RemoveElementAt(inx);
}
return NS_OK;
} else { // The menu is being selected
//printf("... for selection\n");
void * voidData;
mMenuBar->GetNativeData(voidData);
HMENU nativeMenuBar = (HMENU)voidData;
// first check to see if it is a member of the menubar
nsIMenu * hitMenu = nsnull;
1999-03-05 21:04:57 +00:00
if (aNativeMenu == nativeMenuBar) {
mMenuBar->GetMenuAt(aItemNum, hitMenu);
if (mHitMenu != hitMenu) {
//mHitMenu, hitMenu, event
nsMenuEvent aEvent = event;
//AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent)
{
if (nsnull != mHitMenu) {
nsIMenuListener * listener;
if (NS_OK == mHitMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuDeselected(aEvent);
NS_RELEASE(listener);
}
}
if (nsnull != hitMenu) {
nsIMenuListener * listener;
if (NS_OK == hitMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuSelected(aEvent);
NS_RELEASE(listener);
}
}
}
NS_IF_RELEASE(mHitMenu);
mHitMenu = hitMenu;
} else {
NS_IF_RELEASE(hitMenu);
}
} else {
// At this point we know we are inside a menu
// Find the menu we are in (the parent menu)
nsIMenu * parentMenu = nsnull;
PRInt32 fndDepth = 0;
PRUint32 i, count;
mMenuBar->GetMenuCount(count);
for (i=0;i<count;i++) {
nsIMenu * menu;
mMenuBar->GetMenuAt(i, menu);
PRInt32 depth = 0;
1999-03-05 21:04:57 +00:00
parentMenu = FindMenu(menu, aNativeMenu, depth);
if (parentMenu) {
fndDepth = depth;
break;
}
NS_RELEASE(menu);
}
if (nsnull != parentMenu) {
// Sometimes an event comes through for a menu that is being popup down
// So it its depth is great then the current hit list count it already gone.
if (fndDepth > mHitSubMenus->Count()) {
NS_RELEASE(parentMenu);
return NS_OK;
}
nsIMenu * newMenu = nsnull;
// Skip if it is a menu item, otherwise, we get the menu by position
if (!isMenuItem) {
//printf("Getting submenu by position %d from parentMenu\n", aItemNum);
nsISupports * item;
1999-03-05 21:04:57 +00:00
parentMenu->GetItemAt((PRUint32)aItemNum, item);
if (NS_OK != item->QueryInterface(kIMenuIID, (void **)&newMenu)) {
//printf("Item was not a menu! What are we doing here? Return early....\n");
return NS_ERROR_FAILURE;
}
}
// Figure out if this new menu is in the list of popup'ed menus
PRBool newFound = PR_FALSE;
PRInt32 newLevel = 0;
for (newLevel=0;newLevel<mHitSubMenus->Count();newLevel++) {
if (newMenu == (nsIMenu *)mHitSubMenus->ElementAt(newLevel)) {
newFound = PR_TRUE;
break;
}
}
// Figure out if the parent menu is in the list of popup'ed menus
PRBool found = PR_FALSE;
PRInt32 level = 0;
for (level=0;level<mHitSubMenus->Count();level++) {
if (parentMenu == (nsIMenu *)mHitSubMenus->ElementAt(level)) {
found = PR_TRUE;
break;
}
}
// So now figure out were we are compared to the hit list depth
// we figure out how many items are open below
//
// If the parent was found then we use it
// if the parent was NOT found this means we are at the very first level (menu from the menubar)
// Windows will send an event for a parent AND child that is already in the hit list
// and we think we should be popping it down. So we check to see if the
// new menu is already in the tree so it doesn't get removed and then added.
PRInt32 numToRemove = 0;
if (found) {
numToRemove = mHitSubMenus->Count() - level - 1;
} else {
// This means we got a menu event for a menubar menu
if (newFound) { // newFound checks to see if the new menu to be added is already in the hit list
numToRemove = mHitSubMenus->Count() - newLevel - 1;
} else {
numToRemove = mHitSubMenus->Count();
}
}
// If we are to remove 1 item && the new menu to be added is the
// same as the one we would be removing, then don't remove it.
if (numToRemove == 1 && newMenu == (nsIMenu *)mHitSubMenus->ElementAt(mHitSubMenus->Count()-1)) {
numToRemove = 0;
}
// Now loop thru and removing the menu from thre list
PRInt32 ii;
for (ii=0;ii<numToRemove;ii++) {
nsIMenu * m = (nsIMenu *)mHitSubMenus->ElementAt(mHitSubMenus->Count()-1 );
1999-04-20 01:18:55 +00:00
//AdjustMenus(m, nsnull, event);
nsIMenu * aCurrentMenu = m;
nsIMenu * aNewMenu = nsnull;
nsMenuEvent aEvent = event;
//static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent)
{
if (nsnull != aCurrentMenu) {
nsIMenuListener * listener;
if (NS_OK == aCurrentMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuDeselected(aEvent);
NS_RELEASE(listener);
}
}
if (nsnull != aNewMenu) {
nsIMenuListener * listener;
if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
NS_ASSERTION(false, "get debugger");
listener->MenuSelected(aEvent);
NS_RELEASE(listener);
}
}
}
nsString name;
m->GetLabel(name);
NS_RELEASE(m);
mHitSubMenus->RemoveElementAt(mHitSubMenus->Count()-1);
}
// At this point we bail if we are a menu item
if (isMenuItem) {
return NS_OK;
}
// Here we know we have a menu, check one last time to see
// if the new one is the last one in the list
// Add it if it isn't or skip adding it
nsString name;
newMenu->GetLabel(name);
if (newMenu != (nsIMenu *)mHitSubMenus->ElementAt(mHitSubMenus->Count()-1)) {
mHitSubMenus->AppendElement(newMenu);
NS_ADDREF(newMenu);
1999-04-20 01:18:55 +00:00
//AdjustMenus(nsnull, newMenu, event);
nsIMenu * aCurrentMenu = nsnull;
nsIMenu * aNewMenu = newMenu;
nsMenuEvent aEvent = event;
//static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent)
{
if (nsnull != aCurrentMenu) {
nsIMenuListener * listener;
if (NS_OK == aCurrentMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuDeselected(aEvent);
NS_RELEASE(listener);
}
}
if (nsnull != aNewMenu) {
nsIMenuListener * listener;
if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuSelected(aEvent);
NS_RELEASE(listener);
}
}
}
}
NS_RELEASE(parentMenu);
} else {
//printf("no menu was found. This is bad.\n");
1999-03-05 21:04:57 +00:00
// XXX need to assert here!
}
}
}
return NS_OK;
}
//---------------------------------------------------------
NS_METHOD nsWindow::EnableFileDrop(PRBool aEnable)
{
//::DragAcceptFiles(mWnd, (aEnable?TRUE:FALSE));
#ifdef NEW_DRAG_AND_DROP
mNativeDragTarget = new nsNativeDragTarget(this);
if (NULL != mNativeDragTarget) {
mNativeDragTarget->AddRef();
if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget,TRUE,FALSE)) {
if (S_OK == ::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget)) {
}
}
}
#endif
return NS_OK;
}
1999-03-01 16:22:40 +00:00
1999-04-23 14:30:51 +00:00
//-------------------------------------------------------------------------
//
// OnKey
//
//-------------------------------------------------------------------------
PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode)
{
nsKeyEvent event;
nsPoint point;
point.x = 0;
point.y = 0;
InitEvent(event, aEventType, &point); // this add ref's event.widget
event.charCode = aCharCode;
event.keyCode = aVirtualCharCode;
//printf("Type: %s charCode %d keyCode %d ", (aEventType == NS_KEY_UP?"Up":"Down"), event.charCode, event.keyCode);
//printf("Shift: %s Control %s Alt: %s \n", (mIsShiftDown?"D":"U"), (mIsControlDown?"D":"U"), (mIsAltDown?"D":"U"));
event.isShift = mIsShiftDown;
event.isControl = mIsControlDown;
event.isAlt = mIsAltDown;
event.eventStructType = NS_KEY_EVENT;
PRBool result = DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
return result;
}
//-----------------------------------------------------
static BOOL IsKeypadKey(UINT vCode, long isExtended)
{
switch (vCode) {
case VK_HOME:
case VK_END:
case VK_PRIOR:
case VK_NEXT:
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
case VK_CLEAR:
case VK_INSERT:
// extended are not keypad keys
if (isExtended)
break;
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
return TRUE;
}
return FALSE;
}
//-------------------------------------------------------------------------
//
// return
// EXTENDED_KEY for extended keys supported by java
// SPECIAL_KEY for extended keys
// DONT_PROCESS_KEY for extended keys of no interest (never exposed to java)
// STANDARD_KEY for standard keys
//
//-------------------------------------------------------------------------
#define STANDARD_KEY 1
#define EXTENDED_KEY 2
#define SPECIAL_KEY 3
#define DONT_PROCESS_KEY 4
//-------------------------------------------------------------------------
ULONG nsWindow::IsSpecialChar(UINT aVirtualKeyCode, WORD *aAsciiKey)
{
ULONG keyType = EXTENDED_KEY;
*aAsciiKey = 0;
// Process non-standard Control Keys
if (mIsControlDown && !mIsShiftDown && !mIsAltDown &&
((aVirtualKeyCode >= 0x30 && aVirtualKeyCode <= 0x39) || // 0-9
(aVirtualKeyCode >= 0xBA && aVirtualKeyCode <= 0xC0) || // ;=,-./` (semi-colon,equals,comma,dash,period,slash,back tick)
(aVirtualKeyCode == 0xDE))) { // ' (tick)
*aAsciiKey = aVirtualKeyCode;
return SPECIAL_KEY;
}
//printf("*********************** 0x%x\n", aVirtualKeyCode);
switch (aVirtualKeyCode) {
case VK_TAB:
case VK_HOME:
case VK_END:
case VK_PRIOR:
case VK_NEXT:
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
case VK_F1:
case VK_F2:
case VK_F3:
case VK_F4:
case VK_F5:
case VK_F6:
case VK_F7:
case VK_F8:
case VK_F9:
case VK_F10:
case VK_F11:
case VK_F12:
*aAsciiKey = aVirtualKeyCode;
break;
case VK_DELETE:
*aAsciiKey = '\177';
keyType = SPECIAL_KEY;
break;
//case VK_RETURN:*aAsciiKey = '\n';
//keyType = SPECIAL_KEY;
//break;
1999-04-23 14:30:51 +00:00
case VK_MENU:
keyType = DONT_PROCESS_KEY;
break;
default:
keyType = STANDARD_KEY;
break;
}
return keyType;
}
//-------------------------------------------------------------------------
//
// change the virtual key coming from windows into an ascii code
//
//-------------------------------------------------------------------------
BOOL TranslateToAscii(BYTE *aKeyState,
UINT aVirtualKeyCode,
UINT aScanCode,
WORD *aAsciiKey)
{
WORD asciiBuf;
BOOL bIsExtended;
bIsExtended = TRUE;
*aAsciiKey = 0;
switch (aVirtualKeyCode) {
case VK_TAB:
case VK_HOME:
case VK_END:
case VK_PRIOR:
case VK_NEXT:
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
case VK_F1:
case VK_F2:
case VK_F3:
case VK_F4:
case VK_F5:
case VK_F6:
case VK_F7:
case VK_F8:
case VK_F9:
case VK_F10:
case VK_F11:
case VK_F12:
*aAsciiKey = aVirtualKeyCode;
break;
case VK_DELETE:
*aAsciiKey = '\177';
bIsExtended = FALSE;
break;
case VK_RETURN:
*aAsciiKey = '\n';
bIsExtended = FALSE;
break;
default:
bIsExtended = FALSE;
if (::ToAscii(aVirtualKeyCode, aScanCode, aKeyState, &asciiBuf, FALSE) == 1) {
*aAsciiKey = (char)asciiBuf;
}
break;
}
return bIsExtended;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
BOOL nsWindow::OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode)
{
WORD asciiKey;
asciiKey = 0;
switch (IsSpecialChar(aVirtualKeyCode, &asciiKey)) {
case EXTENDED_KEY:
break;
// special keys don't generate an action but don't even go
// through WM_CHAR
case SPECIAL_KEY:
break;
// standard keys are processed through WM_CHAR
case STANDARD_KEY:
asciiKey = 0; // just to be paranoid
break;
}
//printf("In OnKeyDown ascii %d virt: %d scan: %d\n", asciiKey, aVirtualKeyCode, aScanCode);
// if we enter this if statement we expect not to get a WM_CHAR
if (asciiKey) {
//printf("Dispatching Key Down [%d]\n", asciiKey);
return DispatchKeyEvent(NS_KEY_DOWN, asciiKey, aVirtualKeyCode);
1999-04-23 14:30:51 +00:00
}
// always let the def proc process a WM_KEYDOWN
return FALSE;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
BOOL nsWindow::OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode)
{
WORD asciiKey;
asciiKey = 0;
switch (IsSpecialChar(aVirtualKeyCode, &asciiKey)) {
case EXTENDED_KEY:
break;
case STANDARD_KEY: {
BYTE keyState[256];
::GetKeyboardState(keyState);
::ToAscii(aVirtualKeyCode, aScanCode, keyState, &asciiKey, FALSE);
} break;
case SPECIAL_KEY:
break;
} // switch
if (asciiKey) {
//printf("Dispatching Key Up [%d]\n", asciiKey);
return DispatchKeyEvent(NS_KEY_UP, asciiKey, aVirtualKeyCode);
1999-04-23 14:30:51 +00:00
}
// always let the def proc process a WM_KEYUP
return FALSE;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
BOOL nsWindow::OnChar( UINT aVirtualKeyCode )
{
// if we get a '\n', ignore it because we already processed it in OnKeyDown.
// This is the safest assumption since not always pressing enter produce a WM_CHAR
//if (IsDBCSLeadByte(aVirtualKeyCode) || aVirtualKeyCode == 0xD /*'\n'*/ ) {
// return FALSE;
//}
//printf("OnChar (KeyDown) %d\n", aVirtualKeyCode);
DispatchKeyEvent(NS_KEY_DOWN, aVirtualKeyCode, aVirtualKeyCode);
return FALSE;
1999-04-23 14:30:51 +00:00
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Process all nsWindows messages
//
//-------------------------------------------------------------------------
PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue)
{
static UINT vkKeyCached = 0; // caches VK code fon WM_KEYDOWN
static BOOL firstTime = TRUE; // for mouse wheel logic
static int iDeltaPerLine, iAccumDelta ; // for mouse wheel logic
ULONG ulScrollLines ; // for mouse wheel logic
PRBool result = PR_FALSE; // call the default nsWindow proc
nsPaletteInfo palInfo;
1999-03-01 16:22:40 +00:00
*aRetValue = 0;
1998-04-13 20:24:54 +00:00
switch (msg) {
1999-03-01 16:22:40 +00:00
case WM_COMMAND: {
WORD wNotifyCode = HIWORD(wParam); // notification code
if (wNotifyCode == 0) { // Menu selection
nsMenuEvent event;
event.mCommand = LOWORD(wParam);
event.eventStructType = NS_MENU_EVENT;
InitEvent(event, NS_MENU_SELECTED);
result = DispatchWindowEvent(&event);
1999-04-20 01:18:55 +00:00
1999-02-17 14:30:47 +00:00
if (mMenuBar) {
PRUint32 i, count;
mMenuBar->GetMenuCount(count);
for (i=0;i<count;i++) {
nsIMenu * menu;
mMenuBar->GetMenuAt(i, menu);
nsIMenuItem * menuItem = FindMenuItem(menu, event.mCommand);
if (menuItem) {
nsIMenuListener * listener;
if (NS_OK == menuItem->QueryInterface(kIMenuListenerIID, (void **)&listener)) {
listener->MenuItemSelected(event);
1999-02-17 14:30:47 +00:00
NS_RELEASE(listener);
1999-04-20 01:18:55 +00:00
menu->QueryInterface(kIMenuListenerIID, (void **)&listener);
if(listener){
//listener->MenuDestruct(event);
1999-04-20 01:18:55 +00:00
NS_RELEASE(listener);
}
1999-02-17 14:30:47 +00:00
}
NS_RELEASE(menuItem);
}
NS_RELEASE(menu);
1999-02-17 14:30:47 +00:00
}
}
NS_RELEASE(event.widget);
}
}
break;
1998-04-17 00:16:11 +00:00
case WM_NOTIFY:
// TAB change
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch (pnmh->code) {
case TCN_SELCHANGE: {
DispatchStandardEvent(NS_TABCHANGE);
result = PR_TRUE;
}
break;
case TTN_SHOW: {
nsTooltipEvent event;
InitEvent(event, NS_SHOW_TOOLTIP);
event.tipIndex = (PRUint32)wParam;
event.eventStructType = NS_TOOLTIP_EVENT;
result = DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
}
break;
case TTN_POP:
result = DispatchStandardEvent(NS_HIDE_TOOLTIP);
break;
}
1998-04-17 00:16:11 +00:00
}
break;
case WM_MOVE: // Window moved
{
1998-05-29 22:44:13 +00:00
PRInt32 x = (PRInt32)LOWORD(lParam); // horizontal position in screen coordinates
PRInt32 y = (PRInt32)HIWORD(lParam); // vertical position in screen coordinates
result = OnMove(x, y);
}
break;
1998-04-17 00:16:11 +00:00
1998-04-13 20:24:54 +00:00
case WM_DESTROY:
// clean up.
OnDestroy();
result = PR_TRUE;
break;
case WM_PAINT:
result = OnPaint();
break;
1999-04-23 14:30:51 +00:00
case WM_SYSCHAR:
case WM_CHAR:
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
1999-04-23 14:30:51 +00:00
// Process non-standard Control Keys
// I am unclear whether I should process these like this (rods)
if (mIsControlDown && !mIsAltDown &&
(wParam >= 0x01 && wParam <= 0x1A)) { // a-z
wParam += 0x40; // 64 decimal
} else if (!mIsControlDown && mIsAltDown &&
(wParam >= 0x61 && wParam <= 0x7A)) { // a-z
wParam -= 0x20; // 32 decimal
}
if (!mIMEIsComposing)
1999-04-23 14:30:51 +00:00
result = OnChar(wParam);
else
result = PR_FALSE;
1999-04-23 14:30:51 +00:00
break;
1999-04-23 14:30:51 +00:00
// Let ths fall through if it isn't a key pad
case WM_SYSKEYUP:
// if it's a keypad key don't process a WM_CHAR will come or...oh well...
if (IsKeypadKey(wParam, lParam & 0x01000000)) {
result = PR_TRUE;
break;
}
case WM_KEYUP:
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
1999-04-23 14:30:51 +00:00
if (!mIMEIsComposing)
1999-04-23 14:30:51 +00:00
result = OnKeyUp(wParam, (HIWORD(lParam) & 0xFF));
else
result = PR_FALSE;
break;
1999-04-23 14:30:51 +00:00
case WM_KEYDOWN: {
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
if (!mIMEIsComposing)
result = OnKeyDown(wParam, (HIWORD(lParam) & 0xFF));
else
result = PR_FALSE;
}
1998-04-13 20:24:54 +00:00
break;
// say we've dealt with erase background if widget does
// not need auto-erasing
case WM_ERASEBKGND:
1998-05-05 19:58:27 +00:00
if (! AutoErase()) {
*aRetValue = 1;
result = PR_TRUE;
}
1998-04-13 20:24:54 +00:00
break;
case WM_MOUSEMOVE:
//RelayMouseEvent(msg,wParam, lParam);
1998-04-13 20:24:54 +00:00
result = DispatchMouseEvent(NS_MOUSE_MOVE);
break;
case WM_LBUTTONDOWN:
//SetFocus(); // this is bad
//RelayMouseEvent(msg,wParam, lParam);
1998-04-13 20:24:54 +00:00
result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_DOWN);
break;
case WM_LBUTTONUP:
//RelayMouseEvent(msg,wParam, lParam);
1998-04-13 20:24:54 +00:00
result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_UP);
break;
case WM_LBUTTONDBLCLK:
result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_DOWN);
if (result == PR_FALSE)
result = DispatchMouseEvent(NS_MOUSE_LEFT_DOUBLECLICK);
1998-04-13 20:24:54 +00:00
break;
case WM_MBUTTONDOWN:
result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_DOWN);
break;
case WM_MBUTTONUP:
result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_UP);
break;
case WM_MBUTTONDBLCLK:
result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_DOWN);
1998-04-13 20:24:54 +00:00
break;
case WM_RBUTTONDOWN:
result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_DOWN);
1998-04-13 20:24:54 +00:00
break;
case WM_RBUTTONUP:
result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_UP);
break;
case WM_RBUTTONDBLCLK:
result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_DOWN);
if (result == PR_FALSE)
result = DispatchMouseEvent(NS_MOUSE_RIGHT_DOUBLECLICK);
1998-04-13 20:24:54 +00:00
break;
case WM_HSCROLL:
case WM_VSCROLL:
1998-04-13 20:24:54 +00:00
// check for the incoming nsWindow handle to be null in which case
// we assume the message is coming from a horizontal scrollbar inside
// a listbox and we don't bother processing it (well, we don't have to)
if (lParam) {
nsWindow* scrollbar = (nsWindow*)::GetWindowLong((HWND)lParam, GWL_USERDATA);
if (scrollbar) {
result = scrollbar->OnScroll(LOWORD(wParam), (short)HIWORD(wParam));
}
}
break;
case WM_CTLCOLORLISTBOX:
1998-04-13 20:24:54 +00:00
case WM_CTLCOLOREDIT:
case WM_CTLCOLORBTN:
//case WM_CTLCOLORSCROLLBAR: //XXX causes a the scrollbar to be drawn incorrectly
1998-04-13 20:24:54 +00:00
case WM_CTLCOLORSTATIC:
if (lParam) {
nsWindow* control = (nsWindow*)::GetWindowLong((HWND)lParam, GWL_USERDATA);
if (control) {
control->SetUpForPaint((HDC)wParam);
1998-04-13 20:24:54 +00:00
*aRetValue = (LPARAM)control->OnControlColor();
}
1998-04-13 20:24:54 +00:00
}
result = PR_TRUE;
break;
case WM_SETFOCUS:
1998-04-13 20:24:54 +00:00
result = DispatchFocus(NS_GOTFOCUS);
break;
case WM_KILLFOCUS:
result = DispatchFocus(NS_LOSTFOCUS);
break;
1998-04-13 20:24:54 +00:00
case WM_WINDOWPOSCHANGED:
{
WINDOWPOS *wp = (LPWINDOWPOS)lParam;
// We only care about a resize, so filter out things like z-order
// changes. Note: there's a WM_MOVE handler above which is why we're
// not handling them here...
if (0 == (wp->flags & SWP_NOSIZE)) {
// XXX Why are we using the client size area? If the size notification
// is for the client area then the origin should be (0,0) and not
// the window origin in screen coordinates...
RECT r;
::GetWindowRect(mWnd, &r);
1998-06-19 02:46:25 +00:00
PRInt32 newWidth, newHeight;
newWidth = PRInt32(r.right - r.left);
newHeight = PRInt32(r.bottom - r.top);
nsRect rect(wp->x, wp->y, newWidth, newHeight);
//if (newWidth != mBounds.width)
1998-06-19 02:46:25 +00:00
{
RECT drect;
//getting wider
drect.left = wp->x + mBounds.width;
1998-06-19 02:46:25 +00:00
drect.top = wp->y;
drect.right = drect.left + (newWidth - mBounds.width);
1998-06-19 02:46:25 +00:00
drect.bottom = drect.top + newHeight;
// ::InvalidateRect(mWnd, NULL, FALSE);
1998-06-19 02:46:25 +00:00
// ::InvalidateRect(mWnd, &drect, FALSE);
::RedrawWindow(mWnd, &drect, NULL,
RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ERASENOW | RDW_ALLCHILDREN);
}
//if (newHeight != mBounds.height)
1998-06-19 02:46:25 +00:00
{
RECT drect;
//getting taller
drect.left = wp->x;
drect.top = wp->y + mBounds.height;
1998-06-19 02:46:25 +00:00
drect.right = drect.left + newWidth;
drect.bottom = drect.top + (newHeight - mBounds.height);
1998-06-19 02:46:25 +00:00
// ::InvalidateRect(mWnd, NULL, FALSE);
1998-06-19 02:46:25 +00:00
// ::InvalidateRect(mWnd, &drect, FALSE);
::RedrawWindow(mWnd, &drect, NULL,
RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ERASENOW | RDW_ALLCHILDREN);
}
mBounds.width = newWidth;
mBounds.height = newHeight;
///nsRect rect(wp->x, wp->y, wp->cx, wp->cy);
// recalculate the width and height
// this time based on the client area
if (::GetClientRect(mWnd, &r)) {
rect.width = PRInt32(r.right - r.left);
rect.height = PRInt32(r.bottom - r.top);
}
result = OnResize(rect);
}
1998-04-13 20:24:54 +00:00
break;
}
case WM_MENUSELECT:
if (mMenuBar) {
MenuHasBeenSelected((HMENU)lParam, (UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (UINT) LOWORD(wParam));
}
break;
case WM_SETTINGCHANGE:
firstTime = TRUE;
// Fall through
case WM_MOUSEWHEEL: {
if (firstTime) {
firstTime = FALSE;
//printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ WM_SETTINGCHANGE\n");
SystemParametersInfo (104, 0, &ulScrollLines, 0) ;
//SystemParametersInfo (SPI_GETWHEELSCROLLLINES, 0, &ulScrollLines, 0) ;
// ulScrollLines usually equals 3 or 0 (for no scrolling)
// WHEEL_DELTA equals 120, so iDeltaPerLine will be 40
if (ulScrollLines)
iDeltaPerLine = WHEEL_DELTA / ulScrollLines ;
else
iDeltaPerLine = 0 ;
//printf("ulScrollLines %d iDeltaPerLine %d\n", ulScrollLines, iDeltaPerLine);
if (msg == WM_SETTINGCHANGE) {
return 0;
}
}
HWND scrollbar = NULL;
if (nsnull != mVScrollbar) {
scrollbar = (HWND)mVScrollbar->GetNativeData(NS_NATIVE_WINDOW);
}
if (scrollbar) {
if (iDeltaPerLine == 0)
break ;
iAccumDelta += (short) HIWORD (wParam) ; // 120 or -120
while (iAccumDelta >= iDeltaPerLine) {
//printf("iAccumDelta %d\n", iAccumDelta);
SendMessage (mWnd, WM_VSCROLL, SB_LINEUP, (LONG)scrollbar) ;
iAccumDelta -= iDeltaPerLine ;
}
while (iAccumDelta <= -iDeltaPerLine) {
//printf("iAccumDelta %d\n", iAccumDelta);
SendMessage (mWnd, WM_VSCROLL, SB_LINEDOWN, (LONG)scrollbar) ;
iAccumDelta += iDeltaPerLine ;
}
}
return 0 ;
} break;
1998-04-13 20:24:54 +00:00
case WM_PALETTECHANGED:
if ((HWND)wParam == mWnd) {
// We caused the WM_PALETTECHANGED message so avoid realizing
// another foreground palette
result = PR_TRUE;
break;
1998-04-13 20:24:54 +00:00
}
// fall thru...
case WM_QUERYNEWPALETTE:
mContext->GetPaletteInfo(palInfo);
if (palInfo.isPaletteDevice && palInfo.palette) {
1998-04-13 20:24:54 +00:00
HDC hDC = ::GetDC(mWnd);
HPALETTE hOldPal = ::SelectPalette(hDC, (HPALETTE)palInfo.palette, FALSE);
1998-04-13 20:24:54 +00:00
// Realize the drawing palette
1998-04-13 20:24:54 +00:00
int i = ::RealizePalette(hDC);
1998-08-19 05:06:59 +00:00
// Did any of our colors change?
if (i > 0) {
// Yes, so repaint
::InvalidateRect(mWnd, (LPRECT)NULL, TRUE);
1998-04-13 20:24:54 +00:00
}
::SelectPalette(hDC, hOldPal, TRUE);
::RealizePalette(hDC);
1998-04-13 20:24:54 +00:00
::ReleaseDC(mWnd, hDC);
*aRetValue = TRUE;
}
result = PR_TRUE;
break;
case WM_IME_STARTCOMPOSITION: {
COMPOSITIONFORM compForm;
HIMC hIMEContext;
mIMEIsComposing = PR_TRUE;
#ifdef DEBUG_TAGUE
printf("IME: Recieved WM_IME_STARTCOMPOSITION\n");
#endif
if ((mIMEProperty & IME_PROP_SPECIAL_UI) || (mIMEProperty & IME_PROP_AT_CARET)) {
return PR_FALSE;
}
hIMEContext = ::ImmGetContext(mWnd);
if (hIMEContext==NULL) {
return PR_TRUE;
}
compForm.dwStyle = CFS_POINT;
compForm.ptCurrentPos.x = 100;
compForm.ptCurrentPos.y = 100;
::ImmSetCompositionWindow(hIMEContext,&compForm);
::ImmReleaseContext(mWnd,hIMEContext);
HandleStartComposition();
result = PR_TRUE;
}
break;
case WM_IME_COMPOSITION: {
//COMPOSITIONFORM compForm;
HIMC hIMEContext;
result = PR_FALSE; // will change this if an IME message we handle
hIMEContext = ::ImmGetContext(mWnd);
if (hIMEContext==NULL) {
return PR_TRUE;
}
if (lParam & GCS_COMPSTR) {
#ifdef DEBUG_TAGUE
fprintf(stderr,"nsWindow::WM_IME_COMPOSITION: handling GCS_COMPSTR\n");
#endif
long compStrLen = ::ImmGetCompositionString(hIMEContext,GCS_COMPSTR,NULL,0);
if (compStrLen+1>mIMECompositionStringSize) {
if (mIMECompositionString!=NULL) delete [] mIMECompositionString;
mIMECompositionString = new char[compStrLen+32];
mIMECompositionStringSize = compStrLen+32;
}
::ImmGetCompositionString(hIMEContext,GCS_COMPSTR,mIMECompositionString,mIMECompositionStringSize);
mIMECompositionStringLength = compStrLen;
mIMECompositionString[compStrLen]='\0';
HandleTextEvent(PR_FALSE);
result = PR_TRUE;
}
if (lParam & GCS_RESULTSTR) {
#ifdef DEBUG_TAGUE
fprintf(stderr,"nsWindow::WM_IME_COMPOSITION: handling GCS_RESULTSTR\n");
#endif
long compStrLen = ::ImmGetCompositionString(hIMEContext,GCS_RESULTSTR,NULL,0);
if (compStrLen+1>mIMECompositionStringSize) {
delete [] mIMECompositionString;
mIMECompositionString = new char[compStrLen+32];
mIMECompositionStringSize = compStrLen+32;
}
::ImmGetCompositionString(hIMEContext,GCS_RESULTSTR,mIMECompositionString,mIMECompositionStringSize);
mIMECompositionStringLength = compStrLen;
mIMECompositionString[compStrLen]='\0';
result = PR_TRUE;
HandleTextEvent(PR_TRUE);
HandleEndComposition();
HandleStartComposition();
}
::ImmReleaseContext(mWnd,hIMEContext);
}
break;
case WM_IME_ENDCOMPOSITION:
mIMEIsComposing = PR_FALSE;
#ifdef DEBUG_TAGUE
printf("IME: Received WM_IME_ENDCOMPOSITION\n");
#endif
HandleEndComposition();
result = PR_TRUE;
break;
case WM_DROPFILES: {
/*HDROP hDropInfo = (HDROP) wParam;
UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0);
for (UINT iFile = 0; iFile < nFiles; iFile++) {
TCHAR szFileName[_MAX_PATH];
::DragQueryFile(hDropInfo, iFile, szFileName, _MAX_PATH);
printf("szFileName [%s]\n", szFileName);
nsAutoString fileStr(szFileName);
nsEventStatus status;
nsDragDropEvent event;
InitEvent(event, NS_DRAGDROP_EVENT);
event.mType = nsDragDropEventStatus_eDrop;
event.mIsFileURL = PR_FALSE;
event.mURL = (PRUnichar *)fileStr.GetUnicode();
DispatchEvent(&event, status);
}*/
} break;
1999-03-23 21:26:20 +00:00
case WM_DESTROYCLIPBOARD: {
nsIClipboard* clipboard;
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
kIClipboardIID,
(nsISupports **)&clipboard);
clipboard->EmptyClipboard();
1999-04-23 14:30:51 +00:00
nsServiceManager::ReleaseService(kCClipboardCID, clipboard);
1999-03-23 21:26:20 +00:00
} break;
1998-04-13 20:24:54 +00:00
}
return result;
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsWindow::WindowClass()
{
1998-05-05 19:58:27 +00:00
const LPCTSTR className = "NetscapeWindowClass";
1998-04-13 20:24:54 +00:00
if (!nsWindow::sIsRegistered) {
WNDCLASS wc;
1998-06-19 02:46:25 +00:00
// wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
1998-06-02 05:27:08 +00:00
wc.style = CS_DBLCLKS;
1998-04-13 20:24:54 +00:00
wc.lpfnWndProc = ::DefWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = nsToolkit::mDllInstance;
wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = NULL;
wc.hbrBackground = mBrush;
1998-04-13 20:24:54 +00:00
wc.lpszMenuName = NULL;
1998-05-05 19:58:27 +00:00
wc.lpszClassName = className;
1998-04-13 20:24:54 +00:00
nsWindow::sIsRegistered = ::RegisterClass(&wc);
}
1998-05-05 19:58:27 +00:00
return className;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// return nsWindow styles
//
//-------------------------------------------------------------------------
DWORD nsWindow::WindowStyle()
{
return WS_OVERLAPPEDWINDOW;
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// return nsWindow extended styles
//
//-------------------------------------------------------------------------
DWORD nsWindow::WindowExStyle()
{
return WS_EX_CLIENTEDGE;
}
// -----------------------------------------------------------------------
//
// Subclass (or remove the subclass from) this component's nsWindow
//
// -----------------------------------------------------------------------
void nsWindow::SubclassWindow(BOOL bState)
{
if (NULL != mWnd) {
1998-04-13 20:24:54 +00:00
NS_PRECONDITION(::IsWindow(mWnd), "Invalid window handle");
if (bState) {
// change the nsWindow proc
mPrevWndProc = (WNDPROC)::SetWindowLong(mWnd, GWL_WNDPROC,
(LONG)nsWindow::WindowProc);
NS_ASSERTION(mPrevWndProc, "Null standard window procedure");
// connect the this pointer to the nsWindow handle
::SetWindowLong(mWnd, GWL_USERDATA, (LONG)this);
}
else {
::SetWindowLong(mWnd, GWL_WNDPROC, (LONG)mPrevWndProc);
::SetWindowLong(mWnd, GWL_USERDATA, (LONG)NULL);
1998-04-13 20:24:54 +00:00
mPrevWndProc = NULL;
}
}
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// WM_DESTROY has been called
//
//-------------------------------------------------------------------------
void nsWindow::OnDestroy()
{
mOnDestroyCalled = PR_TRUE;
1998-04-13 20:24:54 +00:00
SubclassWindow(FALSE);
mWnd = NULL;
1998-04-13 20:24:54 +00:00
1998-08-06 05:06:24 +00:00
// free GDI objects
if (mBrush) {
VERIFY(::DeleteObject(mBrush));
mBrush = NULL;
}
if (mPalette) {
VERIFY(::DeleteObject(mPalette));
mPalette = NULL;
}
// free tooltip window
if (mTooltip) {
VERIFY(::DestroyWindow(mTooltip));
mTooltip = NULL;
1998-04-13 20:24:54 +00:00
}
// if we were in the middle of deferred window positioning then
// free the memory for the multiple-window position structure
if (mDeferredPositioner) {
VERIFY(::EndDeferWindowPos(mDeferredPositioner));
mDeferredPositioner = NULL;
}
// release references to children, device context, toolkit, and app shell
nsBaseWidget::OnDestroy();
1998-08-06 05:06:24 +00:00
// dispatch the event
if (!mIsDestroying) {
1998-08-06 05:06:24 +00:00
// dispatching of the event may cause the reference count to drop to 0
// and result in this object being destroyed. To avoid that, add a reference
// and then release it after dispatching the event
AddRef();
DispatchStandardEvent(NS_DESTROY);
Release();
}
1998-04-13 20:24:54 +00:00
}
1998-05-29 22:44:13 +00:00
//-------------------------------------------------------------------------
//
// Move
//
//-------------------------------------------------------------------------
PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY)
{
nsGUIEvent event;
InitEvent(event, NS_MOVE);
event.point.x = aX;
event.point.y = aY;
event.eventStructType = NS_GUI_EVENT;
PRBool result = DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
return result;
1998-05-29 22:44:13 +00:00
}
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Paint
//
//-------------------------------------------------------------------------
PRBool nsWindow::OnPaint()
{
nsRect bounds;
PRBool result = PR_TRUE;
PAINTSTRUCT ps;
#ifdef PAINT_DEBUG
HRGN rgn = ::CreateRectRgn(0, 0, 0, 0);
::GetUpdateRgn(mWnd, rgn, TRUE);
HDC dc = ::GetDC(mWnd);
HBRUSH brsh = ::CreateSolidBrush(RGB(255, 0, 0));
::FillRgn(dc, rgn, brsh);
::ReleaseDC(mWnd, dc);
::DeleteObject(rgn);
int x;
for (x = 0; x < 10000000; x++);
#endif
1998-04-13 20:24:54 +00:00
HDC hDC = ::BeginPaint(mWnd, &ps);
1998-08-19 05:06:59 +00:00
// XXX What is this check doing? If it's trying to check for an empty
// paint rect then use the IsRectEmpty() function...
1998-04-13 20:24:54 +00:00
if (ps.rcPaint.left || ps.rcPaint.right || ps.rcPaint.top || ps.rcPaint.bottom) {
// call the event callback
if (mEventCallback) {
nsPaintEvent event;
InitEvent(event, NS_PAINT);
1998-04-13 20:24:54 +00:00
nsRect rect(ps.rcPaint.left,
ps.rcPaint.top,
ps.rcPaint.right - ps.rcPaint.left,
ps.rcPaint.bottom - ps.rcPaint.top);
event.rect = &rect;
event.eventStructType = NS_PAINT_EVENT;
1998-04-13 20:24:54 +00:00
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
static NS_DEFINE_IID(kRenderingContextWinIID, NS_IRENDERING_CONTEXT_WIN_IID);
if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID, nsnull, kRenderingContextIID, (void **)&event.renderingContext))
{
nsIRenderingContextWin *winrc;
if (NS_OK == event.renderingContext->QueryInterface(kRenderingContextWinIID, (void **)&winrc))
{
nsDrawingSurface surf;
//i know all of this seems a little backwards. i'll fix it, i swear. MMP
if (NS_OK == winrc->CreateDrawingSurface(hDC, surf))
{
event.renderingContext->Init(mContext, surf);
result = DispatchWindowEvent(&event);
event.renderingContext->DestroyDrawingSurface(surf);
}
NS_RELEASE(winrc);
}
1998-04-13 20:24:54 +00:00
NS_RELEASE(event.renderingContext);
}
else
result = PR_FALSE;
NS_RELEASE(event.widget);
1998-04-13 20:24:54 +00:00
}
}
::EndPaint(mWnd, &ps);
1998-04-13 20:24:54 +00:00
return result;
}
//-------------------------------------------------------------------------
//
// Send a resize message to the listener
//
//-------------------------------------------------------------------------
PRBool nsWindow::OnResize(nsRect &aWindowRect)
{
// call the event callback
if (mEventCallback) {
nsSizeEvent event;
InitEvent(event, NS_SIZE);
event.windowSize = &aWindowRect;
event.eventStructType = NS_SIZE_EVENT;
RECT r;
if (::GetWindowRect(mWnd, &r)) {
event.mWinWidth = PRInt32(r.right - r.left);
event.mWinHeight = PRInt32(r.bottom - r.top);
} else {
event.mWinWidth = 0;
event.mWinHeight = 0;
}
PRBool result = DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
return result;
}
1998-04-13 20:24:54 +00:00
return PR_FALSE;
1998-04-13 20:24:54 +00:00
}
1998-04-17 00:16:11 +00:00
1998-04-13 20:24:54 +00:00
//-------------------------------------------------------------------------
//
// Deal with all sort of mouse event
//
//-------------------------------------------------------------------------
1998-05-29 22:44:13 +00:00
PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint)
1998-04-13 20:24:54 +00:00
{
PRBool result = PR_FALSE;
if (nsnull == mEventCallback && nsnull == mMouseListener) {
return result;
}
1998-05-08 14:54:09 +00:00
nsMouseEvent event;
1998-05-29 22:44:13 +00:00
InitEvent(event, aEventType, aPoint);
1998-04-13 20:24:54 +00:00
event.isShift = IS_VK_DOWN(NS_VK_SHIFT);
event.isControl = IS_VK_DOWN(NS_VK_CONTROL);
event.isAlt = IS_VK_DOWN(NS_VK_ALT);
1998-05-08 14:54:09 +00:00
event.clickCount = (aEventType == NS_MOUSE_LEFT_DOUBLECLICK ||
aEventType == NS_MOUSE_LEFT_DOUBLECLICK)? 2:1;
event.eventStructType = NS_MOUSE_EVENT;
1998-05-08 14:54:09 +00:00
1998-04-13 20:24:54 +00:00
// call the event callback
if (nsnull != mEventCallback) {
result = DispatchWindowEvent(&event);
1998-04-13 20:24:54 +00:00
if (aEventType == NS_MOUSE_MOVE) {
MouseTrailer * mouseTrailer = MouseTrailer::GetMouseTrailer(0);
MouseTrailer::SetMouseTrailerWindow(this);
mouseTrailer->CreateTimer();
nsRect rect;
GetBounds(rect);
rect.x = 0;
rect.y = 0;
if (rect.Contains(event.point.x, event.point.y)) {
1998-05-29 22:44:13 +00:00
if (gCurrentWindow == NULL || gCurrentWindow != this) {
if ((nsnull != gCurrentWindow) && (!gCurrentWindow->mIsDestroying)) {
MouseTrailer::IgnoreNextCycle();
gCurrentWindow->DispatchMouseEvent(NS_MOUSE_EXIT, gCurrentWindow->GetLastPoint());
}
gCurrentWindow = this;
if (!mIsDestroying) {
gCurrentWindow->DispatchMouseEvent(NS_MOUSE_ENTER);
1998-04-13 20:24:54 +00:00
}
}
}
} else if (aEventType == NS_MOUSE_EXIT) {
1998-05-29 22:44:13 +00:00
if (gCurrentWindow == this) {
gCurrentWindow = nsnull;
1998-04-13 20:24:54 +00:00
}
}
NS_RELEASE(event.widget);
1998-04-13 20:24:54 +00:00
return result;
}
if (nsnull != mMouseListener) {
switch (aEventType) {
case NS_MOUSE_MOVE: {
result = ConvertStatus(mMouseListener->MouseMoved(event));
nsRect rect;
GetBounds(rect);
if (rect.Contains(event.point.x, event.point.y)) {
1998-05-29 22:44:13 +00:00
if (gCurrentWindow == NULL || gCurrentWindow != this) {
gCurrentWindow = this;
1998-04-13 20:24:54 +00:00
}
} else {
//printf("Mouse exit");
1998-04-13 20:24:54 +00:00
}
} break;
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
result = ConvertStatus(mMouseListener->MousePressed(event));
break;
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP:
result = ConvertStatus(mMouseListener->MouseReleased(event));
result = ConvertStatus(mMouseListener->MouseClicked(event));
break;
} // switch
}
NS_RELEASE(event.widget);
1998-04-13 20:24:54 +00:00
return result;
}
//-------------------------------------------------------------------------
//
// Deal with focus messages
//
//-------------------------------------------------------------------------
PRBool nsWindow::DispatchFocus(PRUint32 aEventType)
{
// call the event callback
if (mEventCallback) {
if ((nsnull != gCurrentWindow) && (!gCurrentWindow->mIsDestroying)) {
return(DispatchStandardEvent(aEventType));
}
1998-04-13 20:24:54 +00:00
}
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Deal with scrollbar messages (actually implemented only in nsScrollbar)
//
//-------------------------------------------------------------------------
PRBool nsWindow::OnScroll(UINT scrollCode, int cPos)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Return the brush used to paint the background of this control
//
//-------------------------------------------------------------------------
HBRUSH nsWindow::OnControlColor()
{
return mBrush;
}
//-------------------------------------------------------------------------
//
// return the style for a child nsWindow
//
//-------------------------------------------------------------------------
DWORD ChildWindow::WindowStyle()
{
return WS_CHILD | WS_CLIPCHILDREN | GetBorderStyle(mBorderStyle);
1998-04-13 20:24:54 +00:00
}
//-------------------------------------------------------------------------
//
// Deal with all sort of mouse event
//
//-------------------------------------------------------------------------
PRBool ChildWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint)
{
PRBool result = PR_FALSE;
if (nsnull == mEventCallback && nsnull == mMouseListener) {
return result;
}
switch (aEventType) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
SetCapture(mWnd);
break;
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP:
ReleaseCapture();
break;
default:
break;
} // switch
return nsWindow::DispatchMouseEvent(aEventType, aPoint);
}
1998-04-13 20:24:54 +00:00
DWORD nsWindow::GetBorderStyle(nsBorderStyle aBorderStyle)
{
switch(aBorderStyle)
{
case eBorderStyle_none:
return(0);
break;
case eBorderStyle_dialog:
return(WS_DLGFRAME | DS_3DLOOK);
break;
default:
NS_ASSERTION(0, "unknown border style");
return(WS_OVERLAPPEDWINDOW);
}
}
NS_METHOD nsWindow::SetTitle(const nsString& aTitle)
{
NS_ALLOC_STR_BUF(buf, aTitle, 256);
::SendMessage(mWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)(LPCTSTR)buf);
NS_FREE_STR_BUF(buf);
return NS_OK;
}
PRBool nsWindow::AutoErase()
{
return(PR_FALSE);
}
NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar)
{
1999-02-17 14:30:47 +00:00
mMenuBar = aMenuBar;
NS_ADDREF(mMenuBar);
HMENU nativeMenuHandle;
1998-09-29 18:32:37 +00:00
void * voidData;
aMenuBar->GetNativeData(voidData);
nativeMenuHandle = (HMENU)voidData;
if (nsnull != nativeMenuHandle) {
::SetMenu(mWnd, nativeMenuHandle);
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
}
NS_METHOD nsWindow::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
{
aWidth = mPreferredWidth;
aHeight = mPreferredHeight;
return NS_ERROR_FAILURE;
}
NS_METHOD nsWindow::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight)
{
mPreferredWidth = aWidth;
mPreferredHeight = aHeight;
return NS_OK;
}
void
nsWindow::HandleTextEvent(PRBool commit)
{
nsTextEvent event;
nsPoint point;
size_t unicharSize;
point.x = 0;
point.y = 0;
InitEvent(event, NS_TEXT_EVENT, &point);
if (mIMECompositionUniString!=NULL)
delete [] mIMECompositionUniString;
unicharSize = ::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,mIMECompositionString,mIMECompositionStringLength,
mIMECompositionUniString,0);
mIMECompositionUniString = new PRUnichar[unicharSize+1];
::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,mIMECompositionString,mIMECompositionStringLength,
mIMECompositionUniString,unicharSize);
mIMECompositionUniString[unicharSize] = (PRUnichar)0;
event.theText = mIMECompositionUniString;
event.commitText = commit;
event.isShift = mIsShiftDown;
event.isControl = mIsControlDown;
event.isAlt = mIsAltDown;
event.eventStructType = NS_TEXT_EVENT;
(void)DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
}
void
nsWindow::HandleStartComposition(void)
{
nsCompositionEvent event;
nsPoint point;
point.x = 0;
point.y = 0;
InitEvent(event,NS_COMPOSITION_START,&point);
event.eventStructType = NS_COMPOSITION_START;
event.compositionMessage = NS_COMPOSITION_START;
(void)DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
}
void
nsWindow::HandleEndComposition(void)
{
nsCompositionEvent event;
nsPoint point;
point.x = 0;
point.y = 0;
InitEvent(event,NS_COMPOSITION_END,&point);
event.eventStructType = NS_COMPOSITION_END;
event.compositionMessage = NS_COMPOSITION_END;
(void)DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
}