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

330 lines
12 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1998-04-13 20:24:54 +00:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1998-04-13 20:24:54 +00:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-04-13 20:24:54 +00:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-04-13 20:24:54 +00:00
*/
#ifndef Window_h__
#define Window_h__
#include "nsBaseWidget.h"
1998-04-13 20:24:54 +00:00
#include "nsdefs.h"
#include "nsSwitchToUIThread.h"
#include "nsToolkit.h"
#include "nsIWidget.h"
#include "nsIKBStateControl.h"
1998-04-13 20:24:54 +00:00
#include "nsIMouseListener.h"
#include "nsIEventListener.h"
#include "nsStringUtil.h"
#include "nsString.h"
1998-04-13 20:24:54 +00:00
#include "nsVoidArray.h"
class nsNativeDragTarget;
class nsIRollupListener;
1998-04-13 20:24:54 +00:00
class nsIMenuBar;
1998-04-13 20:24:54 +00:00
#define NSRGB_2_COLOREF(color) \
RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
/**
* Native WIN32 window wrapper.
*/
1999-04-19 19:04:12 +00:00
class nsWindow : public nsSwitchToUIThread,
public nsBaseWidget,
public nsIKBStateControl
1998-04-13 20:24:54 +00:00
{
public:
nsWindow();
virtual ~nsWindow();
1998-04-13 20:24:54 +00:00
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
1998-04-13 20:24:54 +00:00
// nsIWidget interface
NS_IMETHOD Create(nsIWidget *aParent,
1998-04-13 20:24:54 +00:00
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
1998-05-14 21:34:08 +00:00
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Create(nsNativeWidget aParent,
1998-04-13 20:24:54 +00:00
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
1998-05-14 21:34:08 +00:00
nsWidgetInitData *aInitData = nsnull);
// Utility method for implementing both Create(nsIWidget ...) and
// Create(nsNativeWidget...)
virtual nsresult StandardWindowCreate(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData,
nsNativeWidget aNativeParent = nsnull);
NS_IMETHOD Destroy();
1998-04-13 20:24:54 +00:00
virtual nsIWidget* GetParent(void);
NS_IMETHOD Show(PRBool bState);
NS_IMETHOD IsVisible(PRBool & aState);
NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent,
PRBool *aForWindow);
NS_IMETHOD CaptureMouse(PRBool aCapture);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth,
PRInt32 aHeight,
PRBool aRepaint);
NS_IMETHOD Resize(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight,
PRBool aRepaint);
NS_IMETHOD Enable(PRBool bState);
NS_IMETHOD SetFocus(void);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD GetClientBounds(nsRect &aRect);
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
1998-04-13 20:24:54 +00:00
virtual nsIFontMetrics* GetFont(void);
NS_IMETHOD SetFont(const nsFont &aFont);
NS_IMETHOD SetCursor(nsCursor aCursor);
NS_IMETHOD Invalidate(PRBool aIsSynchronous);
NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous);
NS_IMETHOD InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
NS_IMETHOD Update();
1998-04-13 20:24:54 +00:00
virtual void* GetNativeData(PRUint32 aDataType);
1999-05-27 23:20:09 +00:00
virtual void FreeNativeData(void * data, PRUint32 aDataType);//~~~
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
//XXX-Scroll is obsolete it is going away soon
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
NS_IMETHOD ScrollRect(nsRect &aRect, PRInt32 aDx, PRInt32 aDy);
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar) { return NS_ERROR_FAILURE; }
NS_IMETHOD ShowMenuBar(PRBool aShow) { return NS_ERROR_FAILURE; }
NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
NS_IMETHOD BeginResizingChildren(void);
NS_IMETHOD EndResizingChildren(void);
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
NS_IMETHOD EnableDragDrop(PRBool aEnable);
1998-04-13 20:24:54 +00:00
virtual void SetUpForPaint(HDC aHDC);
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
1998-09-16 17:18:56 +00:00
NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
NS_IMETHOD GetAttention();
// nsIKBStateControl interface
NS_IMETHOD ResetInputState();
NS_IMETHOD PasswordFieldInit();
HWND mBorderlessParent;
1998-04-13 20:24:54 +00:00
// nsSwitchToUIThread interface
virtual BOOL CallMethod(MethodInfo *info);
HWND GetWindowHandle() { return mWnd; }
WNDPROC GetPrevWindowProc() { return mPrevWndProc; }
1998-05-29 22:44:13 +00:00
virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint = nsnull);
virtual PRBool AutoErase();
1998-05-29 22:44:13 +00:00
nsPoint* GetLastPoint() { return &mLastPoint; }
1998-04-13 20:24:54 +00:00
1999-02-17 14:30:47 +00:00
PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;}
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
1998-04-13 20:24:54 +00:00
protected:
static PRBool IsScrollbar(HWND aWnd);
static PRBool EventIsInsideWindow(nsWindow* aWindow);
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
virtual PRBool DispatchWindowEvent(nsGUIEvent*event, nsEventStatus &aStatus);
1998-04-13 20:24:54 +00:00
1998-05-14 21:34:08 +00:00
// Allow Derived classes to modify the height that is passed
// when the window is created or resized.
virtual PRInt32 GetHeight(PRInt32 aProposedHeight);
1998-04-13 20:24:54 +00:00
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle();
virtual void SubclassWindow(BOOL bState);
1998-04-13 20:24:54 +00:00
virtual void OnDestroy();
1998-05-29 22:44:13 +00:00
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
1998-04-13 20:24:54 +00:00
virtual PRBool OnPaint();
virtual PRBool OnResize(nsRect &aWindowRect);
1999-04-23 14:30:51 +00:00
1999-06-11 20:32:09 +00:00
BOOL OnChar(UINT mbcsCharCode, UINT virtualKeyCode, bool isMultibyte);
1999-04-23 14:30:51 +00:00
BOOL OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode);
BOOL OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode);
UINT MapFromNativeToDOM(UINT aNativeKeyCode);
BOOL OnInputLangChange(HKL aHKL, LRESULT *oResult);
BOOL OnIMEChar(BYTE aByte1, BYTE aByte2, LPARAM aKeyState);
BOOL OnIMEComposition(LPARAM aGCS);
BOOL OnIMECompositionFull();
BOOL OnIMEEndComposition();
BOOL OnIMENotify(WPARAM aIMN, LPARAM aData, LRESULT *oResult);
BOOL OnIMERequest(WPARAM aIMR, LPARAM aData, LRESULT *oResult);
BOOL OnIMESelect(BOOL aSelected, WORD aLangID);
BOOL OnIMESetContext(BOOL aActive, LPARAM& aISC);
BOOL OnIMEStartComposition();
1999-04-23 14:30:51 +00:00
ULONG IsSpecialChar(UINT aVirtualKeyCode, WORD *aAsciiKey);
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode);
1998-04-13 20:24:54 +00:00
virtual PRBool DispatchFocus(PRUint32 aEventType);
virtual PRBool OnScroll(UINT scrollCode, int cPos);
virtual HBRUSH OnControlColor();
static LRESULT CALLBACK WindowProc(HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
#ifdef MOZ_AIMM
static LRESULT CALLBACK DefaultWindowProc(HWND hWns, UINT msg, WPARAM wParam, LPARAM lParam);
#endif
1998-04-13 20:24:54 +00:00
static PRBool ConvertStatus(nsEventStatus aStatus);
1999-07-27 04:27:17 +00:00
DWORD GetWindowType(nsWindowType aWindowType);
DWORD GetBorderStyle(nsBorderStyle aBorderStyle);
1998-04-13 20:24:54 +00:00
PRBool DispatchStandardEvent(PRUint32 aMsg);
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
void GetNonClientBounds(nsRect &aRect);
void HandleTextEvent(HIMC hIMEContext, PRBool aCheckAttr=PR_TRUE);
void HandleStartComposition(HIMC hIMEContext);
void HandleEndComposition(void);
void MapDBCSAtrributeArrayToUnicodeOffsets(PRUint32* textRangeListLengthResult, nsTextRangeArray* textRangeListResult);
NS_IMETHOD PasswordFieldEnter(PRUint32& oSavedState);
NS_IMETHOD PasswordFieldExit(PRUint32 aRestoredState);
private:
#ifdef DEBUG
void DebugPrintEvent(nsGUIEvent & aEvent,
1999-07-09 13:11:13 +00:00
HWND aWnd);
#endif
1998-04-13 20:24:54 +00:00
protected:
1998-05-29 22:44:13 +00:00
static nsWindow* gCurrentWindow;
PRBool mIsTopWidgetWindow;
1998-05-29 22:44:13 +00:00
nsPoint mLastPoint;
1998-04-13 20:24:54 +00:00
HWND mWnd;
HPALETTE mPalette;
WNDPROC mPrevWndProc;
1999-06-08 06:07:51 +00:00
PRBool mHas3DBorder;
1998-04-13 20:24:54 +00:00
HBRUSH mBrush;
PRBool mIsShiftDown;
PRBool mIsControlDown;
PRBool mIsAltDown;
PRBool mIsDestroying;
PRBool mOnDestroyCalled;
PRBool mIsVisible;
// XXX Temporary, should not be caching the font
nsFont * mFont;
PRInt32 mPreferredWidth;
PRInt32 mPreferredHeight;
PRInt32 mMenuCmdId;
1999-02-17 14:30:47 +00:00
// For Input Method Support
DWORD mIMEProperty;
PRBool mIMEIsComposing;
nsCString* mIMECompString;
nsString* mIMECompUnicode;
PRUint8* mIMEAttributeString;
PRInt32 mIMEAttributeStringLength;
PRInt32 mIMEAttributeStringSize;
PRUint32* mIMECompClauseString;
PRInt32 mIMECompClauseStringLength;
PRInt32 mIMECompClauseStringSize;
long mIMECursorPosition;
static UINT gCurrentKeyboardCP;
static HKL gKeyboardLayout;
PRBool mIsInMouseCapture;
// Drag & Drop
nsNativeDragTarget * mNativeDragTarget;
1998-04-13 20:24:54 +00:00
// Enumeration of the methods which are accessable on the "main GUI thread"
// via the CallMethod(...) mechanism...
// see nsSwitchToUIThread
enum {
CREATE = 0x0101,
CREATE_NATIVE,
DESTROY,
SET_FOCUS,
SET_CURSOR,
CREATE_HACK
};
static BOOL sIsRegistered;
HDWP mDeferredPositioner;
static UINT uMSH_MOUSEWHEEL;
1998-04-13 20:24:54 +00:00
};
//
// A child window is a window with different style
//
class ChildWindow : public nsWindow {
public:
ChildWindow(){}
PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint = nsnull);
1998-04-13 20:24:54 +00:00
protected:
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle() { return 0; }
};
1998-04-13 20:24:54 +00:00
#endif // Window_h__