Rework tooltip method in BView again.
Passing NULL or a blank string to SetToolTip(const char*) sets the tooltip to NULL by calling SetToolTip(BToolTip*) with a NULL argument. Calling SetToolTip(BToolTip*) with a NULL argument calls HideToolTip() because sometimes the tool tip can change without the mouse moving, for example because the user clicked. Thanks Axeld and Stippi.
This commit is contained in:
@@ -4817,6 +4817,11 @@ BView::DoLayout()
|
|||||||
void
|
void
|
||||||
BView::SetToolTip(const char* text)
|
BView::SetToolTip(const char* text)
|
||||||
{
|
{
|
||||||
|
if (text == NULL || text[0] == '\0') {
|
||||||
|
SetToolTip((BToolTip*)NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (BTextToolTip* tip = dynamic_cast<BTextToolTip*>(fToolTip))
|
if (BTextToolTip* tip = dynamic_cast<BTextToolTip*>(fToolTip))
|
||||||
tip->SetText(text);
|
tip->SetText(text);
|
||||||
else
|
else
|
||||||
@@ -4829,10 +4834,14 @@ BView::SetToolTip(BToolTip* tip)
|
|||||||
{
|
{
|
||||||
if (fToolTip == tip)
|
if (fToolTip == tip)
|
||||||
return;
|
return;
|
||||||
|
else if (tip == NULL)
|
||||||
|
HideToolTip();
|
||||||
|
|
||||||
if (fToolTip != NULL)
|
if (fToolTip != NULL)
|
||||||
fToolTip->ReleaseReference();
|
fToolTip->ReleaseReference();
|
||||||
|
|
||||||
fToolTip = tip;
|
fToolTip = tip;
|
||||||
|
|
||||||
if (fToolTip != NULL)
|
if (fToolTip != NULL)
|
||||||
fToolTip->AcquireReference();
|
fToolTip->AcquireReference();
|
||||||
}
|
}
|
||||||
@@ -4851,13 +4860,6 @@ BView::ShowToolTip(BToolTip* tip)
|
|||||||
if (tip == NULL)
|
if (tip == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (BTextToolTip* textTip = dynamic_cast<BTextToolTip*>(tip)) {
|
|
||||||
const char* text = textTip->Text();
|
|
||||||
// if text is NULL or blank don't show the tooltip
|
|
||||||
if (text == NULL || text[0] == '\0')
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BPoint where;
|
BPoint where;
|
||||||
GetMouse(&where, NULL, false);
|
GetMouse(&where, NULL, false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user