Added nsTooltipEvent to indicate the index of the tooltip rectangle that is being shown.

Now correctly initializes TOOLINFO structures before using them.
This commit is contained in:
kmcclusk 1998-05-18 17:55:34 +00:00
Родитель f51cf58f63
Коммит 1c2df781c1
5 изменённых файлов: 93 добавлений и 37 удалений

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

@ -115,6 +115,15 @@ struct nsKeyEvent : public nsGUIEvent {
PRBool isAlt;
};
/**
* Tooltip event
*/
struct nsTooltipEvent : public nsGUIEvent {
/// Index of tooltip area which generated the event. @see SetTooltips in nsIWidget
PRUint32 tipIndex;
};
/**
* GUI MESSAGES
*/

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

@ -404,7 +404,7 @@ class nsIWidget : public nsISupports {
*
*/
virtual void SetTooltips(PRUint32 aNumberOfTips,const nsRect* aTooltipAreas) = 0;
virtual void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]) = 0;
/**
* Update the collection of tooltip rectangles. The number of tooltips must
@ -415,7 +415,7 @@ class nsIWidget : public nsISupports {
*
*/
virtual void UpdateTooltips(const nsRect* aNewTips) = 0;
virtual void UpdateTooltips(nsRect* aNewTips[]) = 0;
/**
* Remove the collection of tooltip rectangles.

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

@ -79,10 +79,10 @@ void nsWindow::EndResizingChildren(void)
// hwndOwner - handle of the owner window
//
void nsWindow::AddTooltip(HWND hwndOwner,nsRect& aRect)
void nsWindow::AddTooltip(HWND hwndOwner,nsRect* aRect, int aId)
{
// HWND hwndTT; // handle of tooltip
TOOLINFO ti; // tool information
TOOLINFO ti; // tool information
memset(&ti, 0, sizeof(TOOLINFO));
// Make sure the common control DLL is loaded
InitCommonControls();
@ -103,18 +103,17 @@ void nsWindow::AddTooltip(HWND hwndOwner,nsRect& aRect)
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwndOwner;
ti.hinst = nsToolkit::mDllInstance;
ti.uId = 0;
ti.uId = aId;
ti.lpszText = (LPSTR)" "; // must set text to
// something for tooltip to give events;
ti.rect.left = aRect.x;
ti.rect.top = aRect.y;
ti.rect.right = aRect.x + aRect.width;
ti.rect.bottom = aRect.y + aRect.height;
ti.rect.left = aRect->x;
ti.rect.top = aRect->y;
ti.rect.right = aRect->x + aRect->width;
ti.rect.bottom = aRect->y + aRect->height;
if (!SendMessage(mTooltip, TTM_ADDTOOL, 0,
(LPARAM) (LPTOOLINFO) &ti))
return;
}
void nsWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect)
@ -147,11 +146,11 @@ void nsWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect)
//
//-------------------------------------------------------------------------
void nsWindow::SetTooltips(PRUint32 aNumberOfTips,const nsRect* aTooltipAreas)
void nsWindow::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[])
{
RemoveTooltips();
for (int i = 0; i < (int)aNumberOfTips; i++) {
AddTooltip(mWnd, (nsRect)(aTooltipAreas[i]));
AddTooltip(mWnd, aTooltipAreas[i], i);
}
}
@ -161,22 +160,29 @@ void nsWindow::SetTooltips(PRUint32 aNumberOfTips,const nsRect* aTooltipAreas)
//
//-------------------------------------------------------------------------
void nsWindow::UpdateTooltips(const nsRect* aNewTips)
void nsWindow::UpdateTooltips(nsRect* aNewTips[])
{
TOOLINFO ti;
memset(&ti, 0, sizeof(TOOLINFO));
ti.cbSize = sizeof(TOOLINFO);
ti.hwnd = mWnd;
// Get the number of tooltips
UINT count = ::SendMessage(mTooltip, TTM_GETTOOLCOUNT, 0, 0);
NS_ASSERTION(count > 0, "Called UpdateTooltips before calling SetTooltips");
for (UINT i = 0; i < count; i++) {
::SendMessage(mTooltip, TTM_ENUMTOOLS, i, (LPARAM) (LPTOOLINFO)&ti);
ti.rect.left = aNewTips[i].x;
ti.rect.top = aNewTips[i].y;
ti.rect.right = aNewTips[i].x + aNewTips[i].width;
ti.rect.bottom = aNewTips[i].y + aNewTips[i].height;
ti.uId = i;
int result =::SendMessage(mTooltip, TTM_ENUMTOOLS, i, (LPARAM) (LPTOOLINFO)&ti);
nsRect* newTip = aNewTips[i];
ti.rect.left = newTip->x;
ti.rect.top = newTip->y;
ti.rect.right = newTip->x + newTip->width;
ti.rect.bottom = newTip->y + newTip->height;
::SendMessage(mTooltip, TTM_NEWTOOLRECT, 0, (LPARAM) (LPTOOLINFO)&ti);
}
}
//-------------------------------------------------------------------------
@ -188,15 +194,23 @@ void nsWindow::UpdateTooltips(const nsRect* aNewTips)
void nsWindow::RemoveTooltips()
{
TOOLINFO ti;
memset(&ti, 0, sizeof(TOOLINFO));
ti.cbSize = sizeof(TOOLINFO);
long val;
if (mTooltip == NULL)
return;
// Get the number of tooltips
UINT count = ::SendMessage(mTooltip, TTM_GETTOOLCOUNT, 0, (LPARAM)&val);
for (UINT i = 0; i < count; i++) {
::SendMessage(mTooltip, TTM_ENUMTOOLS, i,(LPARAM) (LPTOOLINFO)&ti);
ti.uId = i;
ti.hwnd = mWnd;
::SendMessage(mTooltip, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO)&ti);
}
}
//-------------------------------------------------------------------------
//
// Convert nsEventStatus value to a windows boolean
@ -1250,9 +1264,13 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
}
break;
case TTN_SHOW:
result = DispatchStandardEvent(NS_SHOW_TOOLTIP);
break;
case TTN_SHOW: {
nsTooltipEvent event;
InitEvent(event, NS_SHOW_TOOLTIP);
event.tipIndex = (PRUint32)wParam;
result = DispatchEvent(&event);
}
break;
case TTN_POP:
result = DispatchStandardEvent(NS_HIDE_TOOLTIP);

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

@ -100,9 +100,9 @@ public:
virtual nsIToolkit* GetToolkit();
virtual void SetBorderStyle(nsBorderStyle aBorderStyle);
virtual void SetTitle(const nsString& aTitle);
virtual void SetTooltips(PRUint32 aNumberOfTips,const nsRect* aTooltipAreas);
virtual void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
virtual void RemoveTooltips();
virtual void UpdateTooltips(const nsRect* aNewTips);
virtual void UpdateTooltips(nsRect* aNewTips[]);
virtual void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
virtual void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
virtual void AddMouseListener(nsIMouseListener * aListener);
@ -152,7 +152,7 @@ protected:
void InitEvent(nsGUIEvent& event, PRUint32 aEventType);
PRBool DispatchEvent(nsGUIEvent* event);
PRBool DispatchStandardEvent(PRUint32 aMsg);
void AddTooltip(HWND hwndOwner, nsRect& aRect);
void AddTooltip(HWND hwndOwner, nsRect* aRect, int aId);
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
protected:
@ -388,11 +388,11 @@ protected:
{ \
nsWindow::SetTitle(aTitle); \
} \
void SetTooltips(PRUint32 aNumberOfTips,const nsRect* aTooltipAreas) \
void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]) \
{ \
nsWindow::SetTooltips(aNumberOfTips, aTooltipAreas); \
} \
void UpdateTooltips(const nsRect* aNewTips) \
void UpdateTooltips(nsRect* aNewTips[]) \
{ \
nsWindow::UpdateTooltips(aNewTips); \
} \

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

@ -761,7 +761,10 @@ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
case NS_SHOW_TOOLTIP:
{
statusText->SetText("Show tooltip");
char buf[256];
nsTooltipEvent* tEvent = (nsTooltipEvent*)aEvent;
sprintf(buf,"Show tooltip %d", tEvent->tipIndex);
statusText->SetText(buf);
nsRect oldPos;
oldPos.x = aEvent->point.x;
oldPos.y = aEvent->point.y;
@ -892,7 +895,7 @@ nsEventStatus PR_CALLBACK HandleFileButtonEvent(nsGUIEvent *aEvent)
nsString titles[] = {"all files","html","executables" };
nsString filters[] = {"*.*", "*.html", "*.exe" };
fileWidget->SetFilterList(3, titles, filters);
fileWidget->Create(nsnull,
fileWidget->Create(window,
title,
eMode_save,
nsnull,
@ -941,21 +944,47 @@ void SetTooltipPos(int pos, nsIWidget *aWidget, nsIButton *aButton1, nsIButton *
{
switch(pos) {
case 1: {
nsRect* tips1 = {&nsRect(kTooltip1_x,kTooltip1_y,
kTooltip1_width,kTooltip1_height)};
aWidget->SetTooltips(1, tips1);
nsRect* tips1[2];
tips1[0] = new nsRect(
kTooltip1_x,
kTooltip1_y,
kTooltip1_width / 2,
kTooltip1_height);
tips1[1] = new nsRect(
kTooltip1_x + (kTooltip1_width / 2),
kTooltip1_y,
kTooltip1_width / 2,
kTooltip1_height);
aWidget->SetTooltips(2, tips1);
aButton1->Move(kTooltip1_x, kTooltip1_y);
aButton2->Move(kTooltip1_x + kTooltip1_width,
kTooltip1_y + kTooltip1_height);
delete tips1[0];
delete tips1[1];
}
break;
case 2: {
nsRect* tips2 = {&nsRect(kTooltip2_x,kTooltip2_y,
kTooltip2_width,kTooltip2_height)};
aWidget->SetTooltips(1, tips2);
nsRect* tipsDummy[1];
// Test updating the tooltips by initialy giving a tooltip
// location that is 100 pixels to the left, then changing
// it to the correct position.
tipsDummy[0] = new nsRect(kTooltip2_x - 100,kTooltip2_y,
kTooltip2_width,kTooltip2_height);
aWidget->SetTooltips(1, tipsDummy);
nsRect* tips2[1];
tips2[0] = new nsRect(kTooltip2_x,kTooltip2_y,
kTooltip2_width,kTooltip2_height);
aWidget->UpdateTooltips(tips2); // Put it in the correct position
aButton1->Move(kTooltip2_x, kTooltip2_y);
aButton2->Move(kTooltip2_x + kTooltip2_width,
kTooltip2_y + kTooltip2_height);
delete tips2[0];
delete tipsDummy[0];
}
break;
}