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"
|
1998-04-17 23:45:07 +00:00
|
|
|
#include "nsStringUtil.h"
|
|
|
|
#include "nsString.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-13 23:01:01 +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))
|
|
|
|
|
1998-04-14 23:20:49 +00:00
|
|
|
/**
|
|
|
|
* Native WIN32 window wrapper.
|
|
|
|
*/
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
class nsWindow : public nsObject,
|
1998-09-14 20:40:49 +00:00
|
|
|
public nsSwitchToUIThread,
|
|
|
|
public nsIWidget
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
1998-09-14 20:40:49 +00:00
|
|
|
nsWindow();
|
|
|
|
virtual ~nsWindow();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-09-14 20:40:49 +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,
|
1998-07-29 18:51:45 +00:00
|
|
|
nsIAppShell *aAppShell = nsnull,
|
1998-04-24 21:37:30 +00:00
|
|
|
nsIToolkit *aToolkit = nsnull,
|
1998-05-14 21:34:08 +00:00
|
|
|
nsWidgetInitData *aInitData = nsnull);
|
1998-06-25 04:24:45 +00:00
|
|
|
virtual void Create(nsNativeWidget aParent,
|
1998-04-13 20:24:54 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
1998-07-29 18:51:45 +00:00
|
|
|
nsIAppShell *aAppShell = nsnull,
|
1998-04-24 21:37:30 +00:00
|
|
|
nsIToolkit *aToolkit = nsnull,
|
1998-05-14 21:34:08 +00:00
|
|
|
nsWidgetInitData *aInitData = nsnull);
|
1998-08-07 05:19:40 +00:00
|
|
|
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,
|
1998-06-01 20:26:50 +00:00
|
|
|
PRUint32 aHeight,
|
|
|
|
PRBool aRepaint);
|
1998-04-13 20:24:54 +00:00
|
|
|
virtual void Resize(PRUint32 aX,
|
|
|
|
PRUint32 aY,
|
|
|
|
PRUint32 aWidth,
|
1998-06-01 20:26:50 +00:00
|
|
|
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();
|
1998-07-29 18:51:45 +00:00
|
|
|
virtual nsIAppShell * GetAppShell();
|
1998-04-13 20:24:54 +00:00
|
|
|
virtual void Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
|
1998-04-17 23:45:07 +00:00
|
|
|
virtual nsIToolkit* GetToolkit();
|
|
|
|
virtual void SetBorderStyle(nsBorderStyle aBorderStyle);
|
1998-04-23 16:51:25 +00:00
|
|
|
virtual void SetTitle(const nsString& aTitle);
|
1998-05-18 17:55:34 +00:00
|
|
|
virtual void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
|
1998-05-04 19:25:25 +00:00
|
|
|
virtual void RemoveTooltips();
|
1998-05-18 17:55:34 +00:00
|
|
|
virtual void UpdateTooltips(nsRect* aNewTips[]);
|
1998-05-05 23:41:16 +00:00
|
|
|
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);
|
1998-05-13 03:39:08 +00:00
|
|
|
virtual void BeginResizingChildren(void);
|
|
|
|
virtual void EndResizingChildren(void);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-03 22:28:00 +00:00
|
|
|
virtual void SetUpForPaint(HDC aHDC);
|
1998-09-16 17:18:56 +00:00
|
|
|
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
|
|
|
|
1998-08-03 22:28:00 +00:00
|
|
|
|
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);
|
1998-04-28 19:24:52 +00:00
|
|
|
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();
|
|
|
|
|
1998-08-03 22:28:00 +00:00
|
|
|
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);
|
1998-04-17 23:45:07 +00:00
|
|
|
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);
|
1998-04-24 23:09:11 +00:00
|
|
|
PRBool DispatchEvent(nsGUIEvent* event);
|
1998-05-04 19:25:25 +00:00
|
|
|
PRBool DispatchStandardEvent(PRUint32 aMsg);
|
1998-05-18 17:55:34 +00:00
|
|
|
void AddTooltip(HWND hwndOwner, nsRect* aRect, int aId);
|
1998-05-04 19:25:25 +00:00
|
|
|
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
|
1998-04-24 23:09:11 +00:00
|
|
|
|
1998-06-16 17:16:59 +00:00
|
|
|
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;
|
1998-05-04 19:25:25 +00:00
|
|
|
HWND mTooltip;
|
1998-04-13 20:24:54 +00:00
|
|
|
HPALETTE mPalette;
|
|
|
|
WNDPROC mPrevWndProc;
|
|
|
|
EVENT_CALLBACK mEventCallback;
|
|
|
|
nsIDeviceContext *mContext;
|
1998-07-29 18:51:45 +00:00
|
|
|
nsIAppShell *mAppShell;
|
1998-04-13 20:24:54 +00:00
|
|
|
nsToolkit *mToolkit;
|
|
|
|
|
|
|
|
nsIMouseListener * mMouseListener;
|
|
|
|
nsIEventListener * mEventListener;
|
|
|
|
|
|
|
|
nscolor mBackground;
|
|
|
|
HBRUSH mBrush;
|
|
|
|
nscolor mForeground;
|
|
|
|
nsCursor mCursor;
|
1998-04-17 23:45:07 +00:00
|
|
|
nsBorderStyle mBorderStyle;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
PRBool mIsShiftDown;
|
|
|
|
PRBool mIsControlDown;
|
|
|
|
PRBool mIsAltDown;
|
1998-04-28 18:59:38 +00:00
|
|
|
PRBool mIsDestroying;
|
1998-09-15 03:45:06 +00:00
|
|
|
PRBool mOnDestroyCalled;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-19 02:46:25 +00:00
|
|
|
PRInt32 mWidth;
|
|
|
|
PRInt32 mHeight;
|
|
|
|
|
1998-08-07 05:19:40 +00:00
|
|
|
void* mClientData;
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// keep the list of children
|
|
|
|
class Enumerator : public nsIEnumerator {
|
|
|
|
public:
|
1998-08-13 23:01:01 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-13 23:01:01 +00:00
|
|
|
Enumerator();
|
|
|
|
~Enumerator();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-13 23:01:01 +00:00
|
|
|
NS_IMETHOD_(nsISupports*) Next();
|
|
|
|
NS_IMETHOD_(void) Reset();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-13 23:01:01 +00:00
|
|
|
void Append(nsIWidget* aWidget);
|
|
|
|
void Remove(nsIWidget* aWidget);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
private:
|
1998-08-13 23:01:01 +00:00
|
|
|
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;
|
1998-05-13 03:39:08 +00:00
|
|
|
|
|
|
|
HDWP mDeferredPositioner;
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// A child window is a window with different style
|
|
|
|
//
|
|
|
|
class ChildWindow : public nsWindow {
|
|
|
|
|
|
|
|
public:
|
1998-09-14 20:40:49 +00:00
|
|
|
ChildWindow(){}
|
1998-07-21 18:04:18 +00:00
|
|
|
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-17 23:45:07 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#endif // Window_h__
|