From c645f9bcbeab32cfb3c631a1340d38ebf5fd2d6f Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 4 May 2012 19:49:41 -0400 Subject: [PATCH] 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. --- src/kits/interface/View.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 80ec21d191..5078f2fc3c 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -4817,6 +4817,11 @@ BView::DoLayout() void BView::SetToolTip(const char* text) { + if (text == NULL || text[0] == '\0') { + SetToolTip((BToolTip*)NULL); + return; + } + if (BTextToolTip* tip = dynamic_cast(fToolTip)) tip->SetText(text); else @@ -4829,10 +4834,14 @@ BView::SetToolTip(BToolTip* tip) { if (fToolTip == tip) return; + else if (tip == NULL) + HideToolTip(); if (fToolTip != NULL) fToolTip->ReleaseReference(); + fToolTip = tip; + if (fToolTip != NULL) fToolTip->AcquireReference(); } @@ -4851,13 +4860,6 @@ BView::ShowToolTip(BToolTip* tip) if (tip == NULL) return; - if (BTextToolTip* textTip = dynamic_cast(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; GetMouse(&where, NULL, false);