[go: up one dir, main page]

Menu

[e0151d]: / src / ytooltip.cc  Maximize  Restore  History

Download this file

122 lines (105 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* IceWM
*
* Copyright (C) 1997-2001 Marko Macek
*/
#include "config.h"
#include "ytooltip.h"
#ifdef CONFIG_TOOLTIP
#include "base.h"
#include "prefs.h"
#include <string.h>
YColor *YToolTip::toolTipBg = 0;
YColor *YToolTip::toolTipFg = 0;
YFont *YToolTip::toolTipFont = 0;
YTimer *YToolTip::fToolTipVisibleTimer = 0;
YToolTip::YToolTip(YWindow *aParent): YWindow(aParent) {
if (toolTipBg == 0)
toolTipBg = new YColor(clrToolTip);
if (toolTipFg == 0)
toolTipFg = new YColor(clrToolTipText);
if (toolTipFont == 0)
toolTipFont = YFont::getFont(toolTipFontName);
fText = 0;
setStyle(wsOverrideRedirect);
}
YToolTip::~YToolTip() {
delete fText; fText = 0;
if (fToolTipVisibleTimer) {
if (fToolTipVisibleTimer->getTimerListener() == this) {
fToolTipVisibleTimer->setTimerListener(0);
fToolTipVisibleTimer->stopTimer();
}
}
}
void YToolTip::paint(Graphics &g, int /*x*/, int /*y*/, unsigned int /*width*/, unsigned int /*height*/) {
g.setColor(toolTipBg);
g.fillRect(0, 0, width(), height());
g.setColor(YColor::black);
g.drawRect(0, 0, width() - 1, height() - 1);
if (fText) {
int y = toolTipFont->ascent() + 2;
g.setFont(toolTipFont);
g.setColor(toolTipFg);
g.drawStringMultiline(3, y, fText);
}
}
void YToolTip::setText(const char *tip) {
delete fText; fText = 0;
if (tip) {
fText = newstr(tip);
if (fText) {
YDimension const size(toolTipFont->multilineAlloc(fText));
setSize(size.w + 6, size.h + 7);
} else {
setSize(20, 20);
}
//!!! merge with below code in locate
int x = this->x();
int y = this->y();
if (x + width() >= desktop->width())
x = desktop->width() - width();
if (y + height() >= desktop->height())
y = desktop->height() - height();
if (y < 0)
y = 0;
if (x < 0)
x = 0;
setPosition(x, y);
}
repaint();
}
bool YToolTip::handleTimer(YTimer *t) {
if (t == fToolTipVisibleTimer && fToolTipVisibleTimer)
hide();
else
display();
return false;
}
void YToolTip::display() {
raise();
show();
if (!fToolTipVisibleTimer && ToolTipTime > 0)
fToolTipVisibleTimer = new YTimer(ToolTipTime);
if (fToolTipVisibleTimer) {
fToolTipVisibleTimer->setTimerListener(this);
fToolTipVisibleTimer->startTimer();
}
}
void YToolTip::locate(YWindow *w, const XCrossingEvent &/*crossing*/) {
int x, y;
x = w->width() / 2;
y = w->height();
w->mapToGlobal(x, y);
x -= width() / 2;
if (x + width() >= desktop->width())
x = desktop->width() - width();
if (y + height() >= desktop->height())
y -= height() + w->height();
if (y < 0)
y = 0;
if (x < 0)
x = 0;
setPosition(x, y);
}
#endif