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

260 lines
9.2 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.
*/
#ifndef Window_h__
#define Window_h__
#include "nsdefs.h"
#include "nsObject.h"
#include "nsSwitchToUIThread.h"
#include "nsToolkit.h"
#include "nsIWidget.h"
#include "nsIEnumerator.h"
#include "nsIMouseListener.h"
#include "nsIEventListener.h"
#include "nsStringUtil.h"
#include "nsString.h"
1998-04-13 20:24:54 +00:00
#include "nsVoidArray.h"
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.
*/
1998-04-13 20:24:54 +00:00
class nsWindow : public nsObject,
public nsSwitchToUIThread,
public nsIWidget
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();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
1998-04-13 20:24:54 +00:00
1998-05-14 21:34:08 +00:00
virtual void PreCreateWidget(nsWidgetInitData *aWidgetInitData) {}
1998-04-13 20:24:54 +00:00
// nsIWidget interface
virtual void Create(nsIWidget *aParent,
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);
virtual void 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);
NS_IMETHOD GetClientData(void*& aClientData);
NS_IMETHOD SetClientData(void* aClientData);
1998-04-13 20:24:54 +00:00
virtual void Destroy();
virtual nsIWidget* GetParent(void);
virtual nsIEnumerator* GetChildren();
virtual void AddChild(nsIWidget* aChild);
virtual void RemoveChild(nsIWidget* aChild);
virtual void Show(PRBool bState);
virtual void Move(PRUint32 aX, PRUint32 aY);
virtual void Resize(PRUint32 aWidth,
PRUint32 aHeight,
PRBool aRepaint);
1998-04-13 20:24:54 +00:00
virtual void Resize(PRUint32 aX,
PRUint32 aY,
PRUint32 aWidth,
PRUint32 aHeight,
PRBool aRepaint);
1998-04-13 20:24:54 +00:00
virtual void Enable(PRBool bState);
virtual void SetFocus(void);
virtual void GetBounds(nsRect &aRect);
virtual nscolor GetForegroundColor(void);
virtual void SetForegroundColor(const nscolor &aColor);
virtual nscolor GetBackgroundColor(void);
virtual void SetBackgroundColor(const nscolor &aColor);
virtual nsIFontMetrics* GetFont(void);
virtual void SetFont(const nsFont &aFont);
virtual nsCursor GetCursor();
virtual void SetCursor(nsCursor aCursor);
virtual void Invalidate(PRBool aIsSynchronous);
virtual void* GetNativeData(PRUint32 aDataType);
virtual nsIRenderingContext* GetRenderingContext();
virtual void SetColorMap(nsColorMap *aColorMap);
virtual nsIDeviceContext* GetDeviceContext();
virtual nsIAppShell * GetAppShell();
1998-04-13 20:24:54 +00:00
virtual void Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
virtual nsIToolkit* GetToolkit();
virtual void SetBorderStyle(nsBorderStyle aBorderStyle);
1998-04-23 16:51:25 +00:00
virtual void SetTitle(const nsString& aTitle);
virtual void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
virtual void RemoveTooltips();
virtual void UpdateTooltips(nsRect* aNewTips[]);
virtual void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
virtual void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
1998-04-13 20:24:54 +00:00
virtual void AddMouseListener(nsIMouseListener * aListener);
virtual void AddEventListener(nsIEventListener * aListener);
virtual void BeginResizingChildren(void);
virtual void EndResizingChildren(void);
1998-04-13 20:24:54 +00:00
virtual void SetUpForPaint(HDC aHDC);
1998-09-16 17:18:56 +00:00
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
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
protected:
1998-05-29 22:44:13 +00:00
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
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);
virtual PRBool OnKey(PRUint32 aEventType, PRUint32 aKeyCode);
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);
static PRBool ConvertStatus(nsEventStatus aStatus);
DWORD GetBorderStyle(nsBorderStyle aBorderStyle);
1998-04-13 20:24:54 +00:00
1998-05-29 22:44:13 +00:00
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
PRBool DispatchEvent(nsGUIEvent* event);
PRBool DispatchStandardEvent(PRUint32 aMsg);
void AddTooltip(HWND hwndOwner, nsRect* aRect, int aId);
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
void GetNonClientBounds(nsRect &aRect);
1998-04-13 20:24:54 +00:00
protected:
1998-05-29 22:44:13 +00:00
static nsWindow* gCurrentWindow;
nsPoint mLastPoint;
1998-04-13 20:24:54 +00:00
HWND mWnd;
HWND mTooltip;
1998-04-13 20:24:54 +00:00
HPALETTE mPalette;
WNDPROC mPrevWndProc;
EVENT_CALLBACK mEventCallback;
nsIDeviceContext *mContext;
nsIAppShell *mAppShell;
1998-04-13 20:24:54 +00:00
nsToolkit *mToolkit;
nsIMouseListener * mMouseListener;
nsIEventListener * mEventListener;
nscolor mBackground;
HBRUSH mBrush;
nscolor mForeground;
nsCursor mCursor;
nsBorderStyle mBorderStyle;
1998-04-13 20:24:54 +00:00
PRBool mIsShiftDown;
PRBool mIsControlDown;
PRBool mIsAltDown;
PRBool mIsDestroying;
PRBool mOnDestroyCalled;
1998-04-13 20:24:54 +00:00
1998-06-19 02:46:25 +00:00
PRInt32 mWidth;
PRInt32 mHeight;
void* mClientData;
1998-04-13 20:24:54 +00:00
// keep the list of children
class Enumerator : public nsIEnumerator {
public:
NS_DECL_ISUPPORTS
1998-04-13 20:24:54 +00:00
Enumerator();
~Enumerator();
1998-04-13 20:24:54 +00:00
NS_IMETHOD_(nsISupports*) Next();
NS_IMETHOD_(void) Reset();
1998-04-13 20:24:54 +00:00
void Append(nsIWidget* aWidget);
void Remove(nsIWidget* aWidget);
1998-04-13 20:24:54 +00:00
private:
nsVoidArray mChildren;
PRInt32 mCurrentPosition;
1998-04-13 20:24:54 +00:00
} *mChildren;
// 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;
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__