Mozilla doesn't save its windows position when closed.

adds an implementation of GetScreemBounds, and registers frame movements, so they are saved and used when reopenning the window.

r=serget@fi.tartu.ee
This commit is contained in:
arougthopher%lizardland.net 2002-06-16 02:58:49 +00:00
Родитель 33317e6bea
Коммит 7ee6208a9b
2 изменённых файлов: 278 добавлений и 195 удалений

Просмотреть файл

@ -57,6 +57,7 @@
#include <Region.h>
#include <Debug.h>
#include <MenuBar.h>
#include <ScrollBar.h>
#include <app/Message.h>
#include <app/MessageRunner.h>
#include <support/String.h>
@ -1248,6 +1249,29 @@ NS_METHOD nsWindow::GetClientBounds(nsRect &aRect)
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this component size and position in screen coordinates
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsWindow::GetScreenBounds(nsRect &aRect)
{
if(mView && mView->LockLooper() && mView->Window())
{
BRect r = mView->Window()->Frame();
aRect.x = nscoord(r.left);
aRect.y = nscoord(r.top);
aRect.width = r.IntegerWidth()+1;
aRect.height = r.IntegerHeight()+1;
mView->UnlockLooper();
}
else
{
aRect = mBounds;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set the background color
@ -1832,6 +1856,14 @@ bool nsWindow::CallMethod(MethodInfo *info)
}
break;
case nsWindow::ONMOVE:
NS_ASSERTION(info->nArgs == 2, "Wrong number of arguments to CallMethod");
PRInt32 aX, aY;
aX=(nscoord)info->args[0];
aY=(nscoord)info->args[1];
OnMove(aX,aY);
break;
default:
bRet = FALSE;
break;
@ -2881,6 +2913,27 @@ void nsWindowBeOS::DispatchMessage(BMessage *msg, BHandler *handler)
BWindow::DispatchMessage(msg, handler);
}
void nsWindowBeOS::FrameMoved(BPoint origin)
{
//determine if the window position actually changed
if (origin.x == lastpoint.x && origin.x == lastpoint.x) {
//it didn't - don't bother
return;
}
lastpoint.x = origin.x;
lastpoint.y = origin.y;
nsWindow *w = (nsWindow *)GetMozillaWidget();
nsToolkit *t;
if(w && (t = w->GetToolkit()) != 0) {
uint32 args[2];
args[0] = (uint32)origin.x;
args[1] = (uint32)origin.y;
MethodInfo *info = new MethodInfo(w, w, nsWindow::ONMOVE, 2, args);
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
void nsWindowBeOS::FrameResized(float width, float height)
{
//determine if the window size actually changed

Просмотреть файл

@ -76,195 +76,213 @@ class nsWindow : public nsObject,
{
public:
nsWindow();
virtual ~nsWindow();
nsWindow();
virtual ~nsWindow();
// nsIWidget interface
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
// nsIWidget interface
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
// Utility method for implementing both Create(nsIWidget ...) and
// Create(nsNativeWidget...)
// 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);
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();
virtual nsIWidget* GetParent(void);
NS_IMETHOD Show(PRBool bState);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
NS_IMETHOD IsVisible(PRBool & aState);
NS_IMETHOD Destroy();
virtual nsIWidget* GetParent(void);
NS_IMETHOD Show(PRBool bState);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener,
PRBool aDoCapture,
PRBool aConsumeRollupEvent);
NS_IMETHOD IsVisible(PRBool & aState);
NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
PRInt32 *aX, PRInt32 *aY);
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 aState);
NS_IMETHOD IsEnabled(PRBool *aState);
NS_IMETHOD SetFocus(PRBool aRaise);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD GetClientBounds(nsRect &aRect);
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
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();
virtual void* GetNativeData(PRUint32 aDataType);
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar);
NS_IMETHOD ShowMenuBar(PRBool aShow);
NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
NS_IMETHOD RemoveTooltips();
NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]);
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 EnableFileDrop(PRBool aEnable);
NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
PRInt32 *aX, PRInt32 *aY);
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 aState);
NS_IMETHOD IsEnabled(PRBool *aState);
NS_IMETHOD SetFocus(PRBool aRaise);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD GetClientBounds(nsRect &aRect);
NS_IMETHOD GetScreenBounds(nsRect &aRect);
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
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();
virtual void* GetNativeData(PRUint32 aDataType);
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar);
NS_IMETHOD ShowMenuBar(PRBool aShow);
NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
NS_IMETHOD RemoveTooltips();
NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]);
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 EnableFileDrop(PRBool aEnable);
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
// nsSwitchToUIThread interface
virtual bool CallMethod(MethodInfo *info);
virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, PRUint32 mod);
virtual PRBool AutoErase();
// nsSwitchToUIThread interface
virtual bool CallMethod(MethodInfo *info);
virtual PRBool DispatchMouseEvent(PRUint32 aEventType,
nsPoint aPoint,
PRUint32 clicks,
PRUint32 mod);
virtual PRBool AutoErase();
// PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;}
// PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;}
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
protected:
static PRBool EventIsInsideWindow(nsWindow* aWindow, nsPoint pos) ;
static PRBool DealWithPopups(uint32 methodID, nsPoint pos);
// Allow Derived classes to modify the height that is passed
// when the window is created or resized.
virtual PRInt32 GetHeight(PRInt32 aProposedHeight);
virtual void OnDestroy();
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsRect &r);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnKeyDown(PRUint32 aEventType, const char *bytes, int32 numBytes, PRUint32 mod, PRUint32 bekeycode, int32 rawcode);
virtual PRBool OnKeyUp(PRUint32 aEventType, const char *bytes, int32 numBytes, PRUint32 mod, PRUint32 bekeycode, int32 rawcode);
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode, PRUint32 aKeyCode);
virtual PRBool DispatchFocus(PRUint32 aEventType);
virtual PRBool OnScroll();
static PRBool ConvertStatus(nsEventStatus aStatus);
PRBool DispatchStandardEvent(PRUint32 aMsg);
void AddTooltip(BView *hwndOwner, nsRect* aRect, int aId);
// Allow Derived classes to modify the height that is passed
// when the window is created or resized.
virtual PRInt32 GetHeight(PRInt32 aProposedHeight);
virtual void OnDestroy();
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsRect &r);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnKeyDown(PRUint32 aEventType,
const char *bytes,
int32 numBytes,
PRUint32 mod,
PRUint32 bekeycode,
int32 rawcode);
virtual PRBool OnKeyUp(PRUint32 aEventType,
const char *bytes,
int32 numBytes,
PRUint32 mod,
PRUint32 bekeycode,
int32 rawcode);
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode, PRUint32 aKeyCode);
virtual PRBool DispatchFocus(PRUint32 aEventType);
virtual PRBool OnScroll();
static PRBool ConvertStatus(nsEventStatus aStatus);
PRBool DispatchStandardEvent(PRUint32 aMsg);
void AddTooltip(BView *hwndOwner, nsRect* aRect, int aId);
virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
virtual BView *CreateBeOSView();
virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
virtual BView *CreateBeOSView();
#if 0
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
nsIMenuItem * FindMenuItem(nsIMenu * aMenu, PRUint32 aId);
nsIMenu * FindMenu(nsIMenu * aMenu, HMENU aNativeMenu, PRInt32 &aDepth);
nsresult MenuHasBeenSelected(HMENU aNativeMenu, UINT aItemNum, UINT aFlags, UINT aCommand);
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
nsIMenuItem *FindMenuItem(nsIMenu * aMenu, PRUint32 aId);
nsIMenu *FindMenu(nsIMenu * aMenu, HMENU aNativeMenu, PRInt32 &aDepth);
nsresult MenuHasBeenSelected(HMENU aNativeMenu, UINT aItemNum, UINT aFlags, UINT aCommand);
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle();
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle();
static LRESULT CALLBACK WindowProc(BWindow * hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
static LRESULT CALLBACK WindowProc(BWindow * hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
BWindow *mTooltip;
BWindow *mTooltip;
#endif
BView *mView;
BView *mView;
PRBool mIsTopWidgetWindow;
BView *mBorderlessParent;
PRBool mIsTopWidgetWindow;
BView *mBorderlessParent;
PRBool mIsDestroying;
PRBool mOnDestroyCalled;
PRBool mIsVisible;
// XXX Temporary, should not be caching the font
nsFont * mFont;
PRBool mIsDestroying;
PRBool mOnDestroyCalled;
PRBool mIsVisible;
// XXX Temporary, should not be caching the font
nsFont *mFont;
PRInt32 mPreferredWidth;
PRInt32 mPreferredHeight;
PRInt32 mPreferredWidth;
PRInt32 mPreferredHeight;
nsIMenuBar * mMenuBar;
PRInt32 mMenuCmdId;
nsIMenu * mHitMenu;
nsVoidArray * mHitSubMenus;
nsIMenuBar *mMenuBar;
PRInt32 mMenuCmdId;
nsIMenu *mHitMenu;
nsVoidArray *mHitSubMenus;
#if 0
// Drag & Drop
// Drag & Drop
#ifdef DRAG_DROP
//nsDropTarget * mDropTarget;
CfDropSource * mDropSource;
CfDropTarget * mDropTarget;
CfDragDrop * mDragDrop;
//nsDropTarget * mDropTarget;
CfDropSource * mDropSource;
CfDropTarget * mDropTarget;
CfDragDrop * mDragDrop;
#endif
#endif
public: // public on BeOS to allow BViews to access it
// 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,
GOT_FOCUS,
KILL_FOCUS,
SET_CURSOR,
CREATE_HACK,
ONMOUSE,
ONWHEEL,
ONPAINT,
ONSCROLL,
ONRESIZE,
CLOSEWINDOW,
MENU,
ONKEY,
BTNCLICK,
ONACTIVATE
};
// 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,
GOT_FOCUS,
KILL_FOCUS,
SET_CURSOR,
CREATE_HACK,
ONMOUSE,
ONWHEEL,
ONPAINT,
ONSCROLL,
ONRESIZE,
CLOSEWINDOW,
MENU,
ONKEY,
BTNCLICK,
ONACTIVATE,
ONMOVE
};
nsToolkit *GetToolkit() { return (nsToolkit *)nsBaseWidget::GetToolkit(); }
};
@ -272,70 +290,82 @@ public: // public on BeOS to allow BViews to access it
// Each class need to subclass this as part of the subclass
//
class nsIWidgetStore {
public:
nsIWidgetStore(nsIWidget *aWindow);
virtual ~nsIWidgetStore();
public:
nsIWidgetStore(nsIWidget *aWindow);
virtual ~nsIWidgetStore();
virtual nsIWidget *GetMozillaWidget(void);
virtual nsIWidget *GetMozillaWidget(void);
private:
nsIWidget *mWidget;
private:
nsIWidget *mWidget;
};
//
// A BWindow subclass
//
class nsWindowBeOS : public BWindow, public nsIWidgetStore {
public:
nsWindowBeOS(nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, window_look aLook,
window_feel aFeel, int32 aFlags, int32 aWorkspace = B_CURRENT_WORKSPACE);
virtual ~nsWindowBeOS();
public:
nsWindowBeOS(nsIWidget *aWidgetWindow,
BRect aFrame,
const char *aName,
window_look aLook,
window_feel aFeel,
int32 aFlags,
int32 aWorkspace = B_CURRENT_WORKSPACE);
virtual ~nsWindowBeOS();
virtual bool QuitRequested( void );
virtual void MessageReceived(BMessage *msg);
virtual void DispatchMessage(BMessage *msg, BHandler *handler);
virtual void WindowActivated(bool active);
virtual void FrameResized(float width, float height);
virtual bool QuitRequested( void );
virtual void MessageReceived(BMessage *msg);
virtual void DispatchMessage(BMessage *msg, BHandler *handler);
virtual void WindowActivated(bool active);
virtual void FrameResized(float width, float height);
virtual void FrameMoved(BPoint origin);
void ResizeToWithoutEvent(float width, float height);
void ResizeToWithoutEvent(float width, float height);
private:
void DoFrameResized();
void DoFrameResized();
float lastWidth, lastHeight;
BMessageRunner *resizeRunner;
float lastWidth, lastHeight;
BPoint lastpoint;
BMessageRunner *resizeRunner;
};
//
// A BView subclass
//
class nsViewBeOS : public BView, public nsIWidgetStore {
BRegion paintregion;
uint32 buttons;
BRegion paintregion;
uint32 buttons;
public:
nsViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
uint32 aResizingMode, uint32 aFlags );
nsViewBeOS(nsIWidget *aWidgetWindow,
BRect aFrame,
const char *aName,
uint32 aResizingMode,
uint32 aFlags);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
virtual void MouseUp(BPoint point);
bool GetPaintRect(nsRect &r);
void KeyDown(const char *bytes, int32 numBytes);
void KeyUp(const char *bytes, int32 numBytes);
virtual void MakeFocus(bool focused);
virtual void MessageReceived(BMessage *msg);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point);
virtual void MouseMoved(BPoint point,
uint32 transit,
const BMessage *message);
virtual void MouseUp(BPoint point);
bool GetPaintRect(nsRect &r);
void KeyDown(const char *bytes, int32 numBytes);
void KeyUp(const char *bytes, int32 numBytes);
virtual void MakeFocus(bool focused);
virtual void MessageReceived(BMessage *msg);
};
//
// A child window is a window with different style
//
class ChildWindow : public nsWindow {
public:
ChildWindow() {};
virtual PRBool IsChild() { return(PR_TRUE); };
public:
ChildWindow() {};
virtual PRBool IsChild() { return(PR_TRUE); };
};
#endif // Window_h__