18318af01SAxel Dörfler /*
28318af01SAxel Dörfler * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
38318af01SAxel Dörfler * Distributed under the terms of the MIT License.
48318af01SAxel Dörfler */
58318af01SAxel Dörfler
68318af01SAxel Dörfler
78318af01SAxel Dörfler #include <ToolTip.h>
88318af01SAxel Dörfler
98318af01SAxel Dörfler #include <new>
108318af01SAxel Dörfler
118318af01SAxel Dörfler #include <Message.h>
128318af01SAxel Dörfler #include <TextView.h>
13fcd50212SAxel Dörfler #include <ToolTipManager.h>
148318af01SAxel Dörfler
158318af01SAxel Dörfler
BToolTip()168318af01SAxel Dörfler BToolTip::BToolTip()
178318af01SAxel Dörfler {
188318af01SAxel Dörfler _InitData();
198318af01SAxel Dörfler }
208318af01SAxel Dörfler
218318af01SAxel Dörfler
BToolTip(BMessage * archive)228318af01SAxel Dörfler BToolTip::BToolTip(BMessage* archive)
238318af01SAxel Dörfler {
248318af01SAxel Dörfler _InitData();
258318af01SAxel Dörfler
268318af01SAxel Dörfler bool sticky;
278318af01SAxel Dörfler if (archive->FindBool("sticky", &sticky) == B_OK)
288318af01SAxel Dörfler fIsSticky = sticky;
298318af01SAxel Dörfler
308318af01SAxel Dörfler // TODO!
318318af01SAxel Dörfler }
328318af01SAxel Dörfler
338318af01SAxel Dörfler
~BToolTip()348318af01SAxel Dörfler BToolTip::~BToolTip()
358318af01SAxel Dörfler {
368318af01SAxel Dörfler }
378318af01SAxel Dörfler
388318af01SAxel Dörfler
398318af01SAxel Dörfler status_t
Archive(BMessage * archive,bool deep) const408318af01SAxel Dörfler BToolTip::Archive(BMessage* archive, bool deep) const
418318af01SAxel Dörfler {
428318af01SAxel Dörfler status_t status = BArchivable::Archive(archive, deep);
438318af01SAxel Dörfler
448318af01SAxel Dörfler if (fIsSticky)
458318af01SAxel Dörfler status = archive->AddBool("sticky", fIsSticky);
468318af01SAxel Dörfler
478318af01SAxel Dörfler // TODO!
488318af01SAxel Dörfler return status;
498318af01SAxel Dörfler }
508318af01SAxel Dörfler
518318af01SAxel Dörfler
528318af01SAxel Dörfler void
SetSticky(bool enable)538318af01SAxel Dörfler BToolTip::SetSticky(bool enable)
548318af01SAxel Dörfler {
558318af01SAxel Dörfler fIsSticky = enable;
568318af01SAxel Dörfler }
578318af01SAxel Dörfler
588318af01SAxel Dörfler
598318af01SAxel Dörfler bool
IsSticky() const608318af01SAxel Dörfler BToolTip::IsSticky() const
618318af01SAxel Dörfler {
628318af01SAxel Dörfler return fIsSticky;
638318af01SAxel Dörfler }
648318af01SAxel Dörfler
658318af01SAxel Dörfler
668318af01SAxel Dörfler void
SetMouseRelativeLocation(BPoint location)678318af01SAxel Dörfler BToolTip::SetMouseRelativeLocation(BPoint location)
688318af01SAxel Dörfler {
698318af01SAxel Dörfler fRelativeLocation = location;
708318af01SAxel Dörfler }
718318af01SAxel Dörfler
728318af01SAxel Dörfler
738318af01SAxel Dörfler BPoint
MouseRelativeLocation() const748318af01SAxel Dörfler BToolTip::MouseRelativeLocation() const
758318af01SAxel Dörfler {
768318af01SAxel Dörfler return fRelativeLocation;
778318af01SAxel Dörfler }
788318af01SAxel Dörfler
798318af01SAxel Dörfler
808318af01SAxel Dörfler void
SetAlignment(BAlignment alignment)818318af01SAxel Dörfler BToolTip::SetAlignment(BAlignment alignment)
828318af01SAxel Dörfler {
838318af01SAxel Dörfler fAlignment = alignment;
848318af01SAxel Dörfler }
858318af01SAxel Dörfler
868318af01SAxel Dörfler
878318af01SAxel Dörfler BAlignment
Alignment() const888318af01SAxel Dörfler BToolTip::Alignment() const
898318af01SAxel Dörfler {
908318af01SAxel Dörfler return fAlignment;
918318af01SAxel Dörfler }
928318af01SAxel Dörfler
938318af01SAxel Dörfler
948318af01SAxel Dörfler void
AttachedToWindow()955ffbab2aSAxel Dörfler BToolTip::AttachedToWindow()
965ffbab2aSAxel Dörfler {
975ffbab2aSAxel Dörfler }
985ffbab2aSAxel Dörfler
995ffbab2aSAxel Dörfler
1005ffbab2aSAxel Dörfler void
DetachedFromWindow()1015ffbab2aSAxel Dörfler BToolTip::DetachedFromWindow()
1025ffbab2aSAxel Dörfler {
1035ffbab2aSAxel Dörfler }
1045ffbab2aSAxel Dörfler
1055ffbab2aSAxel Dörfler
1065ffbab2aSAxel Dörfler bool
Lock()1075ffbab2aSAxel Dörfler BToolTip::Lock()
1085ffbab2aSAxel Dörfler {
1095ffbab2aSAxel Dörfler bool lockedLooper;
1105ffbab2aSAxel Dörfler while (true) {
1115ffbab2aSAxel Dörfler lockedLooper = View()->LockLooper();
1125ffbab2aSAxel Dörfler if (!lockedLooper) {
1134ac097c5SIngo Weinhold BToolTipManager* manager = BToolTipManager::Manager();
1144ac097c5SIngo Weinhold manager->Lock();
1155ffbab2aSAxel Dörfler
1165ffbab2aSAxel Dörfler if (View()->Window() != NULL) {
1174ac097c5SIngo Weinhold manager->Unlock();
1185ffbab2aSAxel Dörfler continue;
1195ffbab2aSAxel Dörfler }
1205ffbab2aSAxel Dörfler }
1215ffbab2aSAxel Dörfler break;
1225ffbab2aSAxel Dörfler }
1235ffbab2aSAxel Dörfler
1245ffbab2aSAxel Dörfler fLockedLooper = lockedLooper;
1255ffbab2aSAxel Dörfler return true;
1265ffbab2aSAxel Dörfler }
1275ffbab2aSAxel Dörfler
1285ffbab2aSAxel Dörfler
1295ffbab2aSAxel Dörfler void
Unlock()1305ffbab2aSAxel Dörfler BToolTip::Unlock()
1315ffbab2aSAxel Dörfler {
1325ffbab2aSAxel Dörfler if (fLockedLooper)
1335ffbab2aSAxel Dörfler View()->UnlockLooper();
1345ffbab2aSAxel Dörfler else
1354ac097c5SIngo Weinhold BToolTipManager::Manager()->Unlock();
1365ffbab2aSAxel Dörfler }
1375ffbab2aSAxel Dörfler
1385ffbab2aSAxel Dörfler
1395ffbab2aSAxel Dörfler void
_InitData()1408318af01SAxel Dörfler BToolTip::_InitData()
1418318af01SAxel Dörfler {
1428318af01SAxel Dörfler fIsSticky = false;
1438318af01SAxel Dörfler fRelativeLocation = BPoint(20, 20);
1448318af01SAxel Dörfler fAlignment = BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM);
1458318af01SAxel Dörfler }
1468318af01SAxel Dörfler
1478318af01SAxel Dörfler
1488318af01SAxel Dörfler // #pragma mark -
1498318af01SAxel Dörfler
1508318af01SAxel Dörfler
BTextToolTip(const char * text)1518318af01SAxel Dörfler BTextToolTip::BTextToolTip(const char* text)
1528318af01SAxel Dörfler {
1538318af01SAxel Dörfler _InitData(text);
1548318af01SAxel Dörfler }
1558318af01SAxel Dörfler
1568318af01SAxel Dörfler
BTextToolTip(BMessage * archive)1578318af01SAxel Dörfler BTextToolTip::BTextToolTip(BMessage* archive)
1588318af01SAxel Dörfler {
1598318af01SAxel Dörfler // TODO!
1608318af01SAxel Dörfler }
1618318af01SAxel Dörfler
1628318af01SAxel Dörfler
~BTextToolTip()1638318af01SAxel Dörfler BTextToolTip::~BTextToolTip()
1648318af01SAxel Dörfler {
1658318af01SAxel Dörfler delete fTextView;
1668318af01SAxel Dörfler }
1678318af01SAxel Dörfler
1688318af01SAxel Dörfler
1698318af01SAxel Dörfler /*static*/ BTextToolTip*
Instantiate(BMessage * archive)1708318af01SAxel Dörfler BTextToolTip::Instantiate(BMessage* archive)
1718318af01SAxel Dörfler {
1728318af01SAxel Dörfler if (!validate_instantiation(archive, "BTextToolTip"))
1738318af01SAxel Dörfler return NULL;
1748318af01SAxel Dörfler
1758318af01SAxel Dörfler return new(std::nothrow) BTextToolTip(archive);
1768318af01SAxel Dörfler }
1778318af01SAxel Dörfler
1788318af01SAxel Dörfler
1798318af01SAxel Dörfler status_t
Archive(BMessage * archive,bool deep) const1808318af01SAxel Dörfler BTextToolTip::Archive(BMessage* archive, bool deep) const
1818318af01SAxel Dörfler {
1828318af01SAxel Dörfler status_t status = BToolTip::Archive(archive, deep);
1838318af01SAxel Dörfler // TODO!
1848318af01SAxel Dörfler
1858318af01SAxel Dörfler return status;
1868318af01SAxel Dörfler }
1878318af01SAxel Dörfler
1888318af01SAxel Dörfler
1898318af01SAxel Dörfler BView*
View() const1908318af01SAxel Dörfler BTextToolTip::View() const
1918318af01SAxel Dörfler {
1928318af01SAxel Dörfler return fTextView;
1938318af01SAxel Dörfler }
1948318af01SAxel Dörfler
1958318af01SAxel Dörfler
1968318af01SAxel Dörfler const char*
Text() const1978318af01SAxel Dörfler BTextToolTip::Text() const
1988318af01SAxel Dörfler {
1998318af01SAxel Dörfler return fTextView->Text();
2008318af01SAxel Dörfler }
2018318af01SAxel Dörfler
2028318af01SAxel Dörfler
2038318af01SAxel Dörfler void
SetText(const char * text)2048318af01SAxel Dörfler BTextToolTip::SetText(const char* text)
2058318af01SAxel Dörfler {
2065ffbab2aSAxel Dörfler if (!Lock())
2075ffbab2aSAxel Dörfler return;
208fcd50212SAxel Dörfler
2098318af01SAxel Dörfler fTextView->SetText(text);
2104daa7647SJohn Scipione fTextView->InvalidateLayout();
211fcd50212SAxel Dörfler
2125ffbab2aSAxel Dörfler Unlock();
2138318af01SAxel Dörfler }
2148318af01SAxel Dörfler
2158318af01SAxel Dörfler
2168318af01SAxel Dörfler void
_InitData(const char * text)2178318af01SAxel Dörfler BTextToolTip::_InitData(const char* text)
2188318af01SAxel Dörfler {
2198318af01SAxel Dörfler fTextView = new BTextView("tool tip text");
2208318af01SAxel Dörfler fTextView->SetText(text);
2218318af01SAxel Dörfler fTextView->MakeEditable(false);
222*7a96554cSlooncraz fTextView->SetViewUIColor(B_TOOL_TIP_BACKGROUND_COLOR);
2238318af01SAxel Dörfler rgb_color color = ui_color(B_TOOL_TIP_TEXT_COLOR);
2248318af01SAxel Dörfler fTextView->SetFontAndColor(NULL, 0, &color);
2258318af01SAxel Dörfler fTextView->SetWordWrap(false);
2268318af01SAxel Dörfler }
2278318af01SAxel Dörfler
228