52 class TTipDelayTimer :
public TTimer {
56 TTipDelayTimer(TGToolTip *tip, Long_t ms) : TTimer(ms, kTRUE) { fTip = tip; }
63 Bool_t TTipDelayTimer::Notify()
77 TGToolTip::TGToolTip(
const TGWindow *p,
const TGFrame *f,
const char *text,
79 : TGCompositeFrame(p, 10, 10, kTempFrame | kHorizontalFrame | kRaisedFrame)
81 SetWindowAttributes_t attr;
82 attr.fMask = kWAOverrideRedirect | kWASaveUnder;
83 attr.fOverrideRedirect = kTRUE;
84 attr.fSaveUnder = kTRUE;
86 gVirtualX->ChangeWindowAttributes(fId, &attr);
87 SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
89 fLabel =
new TGLabel(
this, text);
90 fLabel->SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
91 fLabel->SetTextColor(fClient->GetResourcePool()->GetTipFgndColor());
93 AddFrame(fLabel, fL1 =
new TGLayoutHints(kLHintsLeft | kLHintsTop,
96 Resize(GetDefaultSize());
102 fDelay =
new TTipDelayTimer(
this, delayms);
112 TGToolTip::TGToolTip(
const TGWindow *p,
const TBox *box,
const char *text,
114 : TGCompositeFrame(p, 10, 10, kTempFrame | kHorizontalFrame | kRaisedFrame)
116 SetWindowAttributes_t attr;
117 attr.fMask = kWAOverrideRedirect | kWASaveUnder;
118 attr.fOverrideRedirect = kTRUE;
119 attr.fSaveUnder = kTRUE;
121 gVirtualX->ChangeWindowAttributes(fId, &attr);
122 SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
124 fLabel =
new TGLabel(
this, text);
125 fLabel->SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
126 fLabel->SetTextColor(fClient->GetResourcePool()->GetTipFgndColor());
128 AddFrame(fLabel, fL1 =
new TGLayoutHints(kLHintsLeft | kLHintsTop,
131 Resize(GetDefaultSize());
136 fDelay =
new TTipDelayTimer(
this, delayms);
146 TGToolTip::TGToolTip(
const TBox *box,
const char *text,Long_t delayms)
147 : TGCompositeFrame(gClient->GetRoot(), 10, 10, kTempFrame | kHorizontalFrame | kRaisedFrame)
149 SetWindowAttributes_t attr;
150 attr.fMask = kWAOverrideRedirect | kWASaveUnder;
151 attr.fOverrideRedirect = kTRUE;
152 attr.fSaveUnder = kTRUE;
154 gVirtualX->ChangeWindowAttributes(fId, &attr);
155 SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
157 fLabel =
new TGLabel(
this, text);
158 fLabel->SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
159 fLabel->SetTextColor(fClient->GetResourcePool()->GetTipFgndColor());
161 AddFrame(fLabel, fL1 =
new TGLayoutHints(kLHintsLeft | kLHintsTop,
164 Resize(GetDefaultSize());
169 fDelay =
new TTipDelayTimer(
this, delayms);
177 TGToolTip::TGToolTip(Int_t x, Int_t y,
const char *text, Long_t delayms)
178 : TGCompositeFrame(gClient->GetDefaultRoot(), 10, 10, kTempFrame | kHorizontalFrame | kRaisedFrame)
180 SetWindowAttributes_t attr;
181 attr.fMask = kWAOverrideRedirect | kWASaveUnder;
182 attr.fOverrideRedirect = kTRUE;
183 attr.fSaveUnder = kTRUE;
185 gVirtualX->ChangeWindowAttributes(fId, &attr);
186 SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
188 fLabel =
new TGLabel(
this, text);
189 fLabel->SetBackgroundColor(fClient->GetResourcePool()->GetTipBgndColor());
190 fLabel->SetTextColor(fClient->GetResourcePool()->GetTipFgndColor());
192 AddFrame(fLabel, fL1 =
new TGLayoutHints(kLHintsLeft | kLHintsTop,
195 Resize(GetDefaultSize());
202 fDelay =
new TTipDelayTimer(
this, delayms);
208 TGToolTip::~TGToolTip()
218 void TGToolTip::DrawBorder()
220 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
221 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
222 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
223 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
229 void TGToolTip::Show(Int_t x, Int_t y)
239 Emit(
"Show(Int_t,Int_t)", args);
246 void TGToolTip::Hide()
259 void TGToolTip::Reset()
262 gSystem->AddTimer(fDelay);
273 void TGToolTip::Reset(
const TVirtualPad *parent)
278 gSystem->AddTimer(fDelay);
284 Bool_t TGToolTip::HandleTimer(TTimer *)
286 Int_t x = 0, y = 0, px1 = 0, px2 = 0, py1 = 0;
290 gVirtualX->TranslateCoordinates(fWindow->GetId(), GetParent()->GetId(),
291 fX == -1 ? Int_t(fWindow->GetWidth() >> 1) : fX,
292 fY == -1 ? Int_t(fWindow->GetHeight()) : fY,
296 px1 = fPad->XtoAbsPixel(fBox->GetX1());
297 px2 = fPad->XtoAbsPixel(fBox->GetX2());
298 py1 = fPad->YtoAbsPixel(fBox->GetY1());
301 px1 = fPad->XtoAbsPixel(fPad->GetX1());
302 px2 = fPad->XtoAbsPixel(fPad->GetX2());
303 py1 = fPad->YtoAbsPixel(fPad->GetY1());
306 gVirtualX->TranslateCoordinates(gVirtualX->GetWindowID(fPad->GetCanvasID()),
307 GetParent()->GetId(),
308 px1 + ((px2-px1) >> 1), py1,
319 UInt_t screenW = fClient->GetDisplayWidth();
320 UInt_t screenH = fClient->GetDisplayHeight();
322 gVirtualX->QueryPointer(gVirtualX->GetDefaultRootWindow(),
323 dum1, dum2, mx, my, mx, my, mask);
325 fLabel->SetWrapLength(-1);
326 Resize(GetDefaultSize());
329 if (fWidth > (screenW/2))
330 fLabel->SetWrapLength((screenW/2)-15);
331 Resize(GetDefaultSize());
333 if (x + (Int_t)fWidth > (Int_t)screenW) {
334 x = screenW - fWidth;
338 if (y+4 + GetHeight() > screenH) {
339 y = screenH - (fHeight + 25);
346 TGRectangle rect(x, y, x+fWidth, y+fHeight);
347 if (rect.Contains(mx, my)) {
349 if (fWidth+15 < (UInt_t)mx)
350 x = mx - fWidth - 15;
351 else if (my + fHeight+15 < screenH)
353 else if (fHeight+15 < (UInt_t)my)
354 y = my - fHeight - 15;
356 else if (move == 2) {
357 if (mx + fWidth+15 < screenW)
359 else if (fHeight+15 < (UInt_t)my)
360 y = my - fHeight - 15;
361 else if (fWidth+15 < (UInt_t)mx)
362 x = mx - fWidth - 15;
365 if (my + fHeight+15 < screenH)
367 else if (mx + fWidth+15 < screenW)
369 else if (fWidth+15 < (UInt_t)mx)
370 x = mx - fWidth - 15;
371 else if (fHeight+15 < (UInt_t)my)
372 y = my - fHeight - 15;
386 void TGToolTip::SetText(
const char *new_text)
388 fLabel->SetText(
new TGString(new_text));
389 Resize(GetDefaultSize());
395 void TGToolTip::SetDelay(Long_t delayms)
397 fDelay->SetTime(delayms);
405 void TGToolTip::SetPosition(Int_t x, Int_t y)
416 if (fX > (Int_t) fWindow->GetWidth())
417 fX = fWindow->GetWidth();
418 if (fY > (Int_t) fWindow->GetHeight())
419 fY = fWindow->GetHeight();
426 const TGString *TGToolTip::GetText()
const
428 return fLabel->GetText();