diff --git a/mozilla/widget/public/nsIWidget.h b/mozilla/widget/public/nsIWidget.h index 2a7b5b097d0..3186d711b02 100644 --- a/mozilla/widget/public/nsIWidget.h +++ b/mozilla/widget/public/nsIWidget.h @@ -416,6 +416,24 @@ class nsIWidget : public nsISupports { virtual void RemoveTooltips() = 0; + /** + * Convert from this widget coordinates to screen coordinates. + * + * @param aOldRect widget coordinates stored in the x,y members + * @param aNewRect screen coordinates stored in the x,y members + */ + + virtual void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) = 0; + + /** + * Convert from screen coordinates to this widget's coordinates. + * + * @param aOldRect screen coordinates stored in the x,y members + * @param aNewRect widget's coordinates stored in the x,y members + */ + + virtual void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) = 0; + }; #endif // nsIWidget_h__ diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index df1b0f373a5..bf8740f2e7c 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -35,19 +35,21 @@ BOOL nsWindow::sIsRegistered = FALSE; nsWindow * mCurrentWindow = NULL; +// Global variable +// g_hinst - handle of the application instance +extern HINSTANCE g_hinst; static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); + + // 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 // -// Global variable -// g_hinst - handle of the application instance -extern HINSTANCE g_hinst; void nsWindow::AddTooltip(HWND hwndOwner,nsRect& aRect) { @@ -85,6 +87,30 @@ void nsWindow::AddTooltip(HWND hwndOwner,nsRect& aRect) (LPARAM) (LPTOOLINFO) &ti)) return; +} + +void 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; +} + +void 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; } //------------------------------------------------------------------------- diff --git a/mozilla/widget/src/windows/nsWindow.h b/mozilla/widget/src/windows/nsWindow.h index 6fdb5c8a950..cacd3080b93 100644 --- a/mozilla/widget/src/windows/nsWindow.h +++ b/mozilla/widget/src/windows/nsWindow.h @@ -112,6 +112,8 @@ public: virtual void SetTooltips(PRUint32 aNumberOfTips,const nsRect* aTooltipAreas); virtual void RemoveTooltips(); virtual void UpdateTooltips(const nsRect* aNewTips); + virtual void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect); + virtual void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect); virtual void AddMouseListener(nsIMouseListener * aListener); virtual void AddEventListener(nsIEventListener * aListener); @@ -399,7 +401,15 @@ protected: void RemoveTooltips() \ { \ nsWindow::RemoveTooltips(); \ - } + } \ + void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) \ + { \ + nsWindow::WidgetToScreen(aOldRect, aNewRect); \ + } \ + void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) \ + { \ + nsWindow::ScreenToWidget(aOldRect, aNewRect); \ + } diff --git a/mozilla/widget/tests/windows/winmain.cpp b/mozilla/widget/tests/windows/winmain.cpp index 4181fd38be4..ef8ce25c44e 100644 --- a/mozilla/widget/tests/windows/winmain.cpp +++ b/mozilla/widget/tests/windows/winmain.cpp @@ -760,9 +760,16 @@ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent) switch(aEvent->message) { case NS_SHOW_TOOLTIP: - statusText->SetText("Show tooltip"); - tooltipWindow->Move(aEvent->point.x + 5, aEvent->point.y + 5); - tooltipWindow->Show(PR_TRUE); + { + statusText->SetText("Show tooltip"); + nsRect oldPos; + oldPos.x = aEvent->point.x; + oldPos.y = aEvent->point.y; + nsRect newPos; + window->WidgetToScreen(oldPos, newPos); + tooltipWindow->Move(newPos.x + 5, newPos.y + 5); + tooltipWindow->Show(PR_TRUE); + } break; case NS_HIDE_TOOLTIP: