1 /* 2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <ToolTip.h> 8 9 #include <new> 10 11 #include <Message.h> 12 #include <TextView.h> 13 14 15 BToolTip::BToolTip() 16 { 17 _InitData(); 18 } 19 20 21 BToolTip::BToolTip(BMessage* archive) 22 { 23 _InitData(); 24 25 bool sticky; 26 if (archive->FindBool("sticky", &sticky) == B_OK) 27 fIsSticky = sticky; 28 29 // TODO! 30 } 31 32 33 BToolTip::~BToolTip() 34 { 35 } 36 37 38 status_t 39 BToolTip::Archive(BMessage* archive, bool deep) const 40 { 41 status_t status = BArchivable::Archive(archive, deep); 42 43 if (fIsSticky) 44 status = archive->AddBool("sticky", fIsSticky); 45 46 // TODO! 47 return status; 48 } 49 50 51 void 52 BToolTip::SetSticky(bool enable) 53 { 54 fIsSticky = enable; 55 } 56 57 58 bool 59 BToolTip::IsSticky() const 60 { 61 return fIsSticky; 62 } 63 64 65 void 66 BToolTip::SetMouseRelativeLocation(BPoint location) 67 { 68 fRelativeLocation = location; 69 } 70 71 72 BPoint 73 BToolTip::MouseRelativeLocation() const 74 { 75 return fRelativeLocation; 76 } 77 78 79 void 80 BToolTip::SetAlignment(BAlignment alignment) 81 { 82 fAlignment = alignment; 83 } 84 85 86 BAlignment 87 BToolTip::Alignment() const 88 { 89 return fAlignment; 90 } 91 92 93 void 94 BToolTip::_InitData() 95 { 96 fIsSticky = false; 97 fRelativeLocation = BPoint(20, 20); 98 fAlignment = BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM); 99 } 100 101 102 // #pragma mark - 103 104 105 BTextToolTip::BTextToolTip(const char* text) 106 { 107 _InitData(text); 108 } 109 110 111 BTextToolTip::BTextToolTip(BMessage* archive) 112 { 113 // TODO! 114 } 115 116 117 BTextToolTip::~BTextToolTip() 118 { 119 delete fTextView; 120 } 121 122 123 /*static*/ BTextToolTip* 124 BTextToolTip::Instantiate(BMessage* archive) 125 { 126 if (!validate_instantiation(archive, "BTextToolTip")) 127 return NULL; 128 129 return new(std::nothrow) BTextToolTip(archive); 130 } 131 132 133 status_t 134 BTextToolTip::Archive(BMessage* archive, bool deep) const 135 { 136 status_t status = BToolTip::Archive(archive, deep); 137 // TODO! 138 139 return status; 140 } 141 142 143 BView* 144 BTextToolTip::View() const 145 { 146 return fTextView; 147 } 148 149 150 const char* 151 BTextToolTip::Text() const 152 { 153 return fTextView->Text(); 154 } 155 156 157 void 158 BTextToolTip::SetText(const char* text) 159 { 160 fTextView->SetText(text); 161 } 162 163 164 void 165 BTextToolTip::_InitData(const char* text) 166 { 167 fTextView = new BTextView("tool tip text"); 168 fTextView->SetText(text); 169 fTextView->MakeEditable(false); 170 fTextView->SetViewColor(ui_color(B_TOOL_TIP_BACKGROUND_COLOR)); 171 rgb_color color = ui_color(B_TOOL_TIP_TEXT_COLOR); 172 fTextView->SetFontAndColor(NULL, 0, &color); 173 fTextView->SetWordWrap(false); 174 } 175 176