Added tooltip widget and ScreenToWidget and WidgetToScreen conversion member functions

git-svn-id: svn://10.0.0.236/trunk@1168 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kmcclusk
1998-05-05 23:41:16 +00:00
parent c76e69b986
commit a85f449dd0
4 changed files with 68 additions and 7 deletions

View File

@@ -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__

View File

@@ -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;
}
//-------------------------------------------------------------------------

View File

@@ -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); \
}

View File

@@ -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: