diff options
Diffstat (limited to 'src/TooltipWindow.cc')
-rw-r--r-- | src/TooltipWindow.cc | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/TooltipWindow.cc b/src/TooltipWindow.cc new file mode 100644 index 0000000..025cc68 --- /dev/null +++ b/src/TooltipWindow.cc | |||
@@ -0,0 +1,109 @@ | |||
1 | // TooltipWindow.hh | ||
2 | // Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | |||
23 | #include "TooltipWindow.hh" | ||
24 | #include "Screen.hh" | ||
25 | #include "FbWinFrameTheme.hh" | ||
26 | |||
27 | |||
28 | TooltipWindow::TooltipWindow(const FbTk::FbWindow &parent, BScreen &screen, | ||
29 | FbTk::ThemeProxy<FbWinFrameTheme> &theme): | ||
30 | OSDWindow(parent, screen, theme), | ||
31 | delay(-1) { | ||
32 | |||
33 | FbTk::RefCount<FbTk::Command<void> > raisecmd(new FbTk::SimpleCommand<TooltipWindow>(*this, &TooltipWindow::raiseTooltip)); | ||
34 | timer.setCommand(raisecmd); | ||
35 | timer.fireOnce(true); | ||
36 | |||
37 | } | ||
38 | |||
39 | void TooltipWindow::showText(const std::string &text) { | ||
40 | |||
41 | lastText = text.c_str(); | ||
42 | if (delay == 0) | ||
43 | raiseTooltip(); | ||
44 | else | ||
45 | timer.start(); | ||
46 | |||
47 | } | ||
48 | |||
49 | void TooltipWindow::raiseTooltip() { | ||
50 | |||
51 | if (lastText.size() == 0) | ||
52 | return; | ||
53 | |||
54 | resize(lastText); | ||
55 | reconfigTheme(); | ||
56 | int h = m_theme->font().height() + m_theme->bevelWidth() * 2; | ||
57 | int w = m_theme->font().textWidth(lastText, lastText.size()) + m_theme->bevelWidth() * 2; | ||
58 | |||
59 | Window root_ret; // not used | ||
60 | Window window_ret; // not used | ||
61 | int rx = 0, ry = 0; | ||
62 | int wx, wy; // not used | ||
63 | unsigned int mask; // not used | ||
64 | |||
65 | XQueryPointer(display(), m_screen.rootWindow().window(), | ||
66 | &root_ret, &window_ret, &rx, &ry, &wx, &wy, &mask); | ||
67 | |||
68 | // mouse position | ||
69 | int mx = rx; | ||
70 | int my = ry; | ||
71 | |||
72 | // center the mouse horizontally | ||
73 | rx -= w/2; | ||
74 | int yoffset = 10; | ||
75 | if (ry >= yoffset + h) | ||
76 | ry -= yoffset + h; | ||
77 | else | ||
78 | ry += yoffset; | ||
79 | |||
80 | // check that we are not out of screen | ||
81 | int outOfBound = rx + w - m_screen.width(); | ||
82 | if (outOfBound > 0) | ||
83 | rx -= outOfBound; | ||
84 | if (rx < 0) | ||
85 | rx = 0; | ||
86 | |||
87 | moveResize(rx,ry,w, h); | ||
88 | |||
89 | show(); | ||
90 | clear(); | ||
91 | m_theme->font().drawText(*this, m_screen.screenNumber(), | ||
92 | m_theme->iconbarTheme().text().textGC(), lastText, | ||
93 | lastText.size(), m_theme->bevelWidth(), | ||
94 | m_theme->bevelWidth() + m_theme->font().ascent()); | ||
95 | } | ||
96 | |||
97 | |||
98 | void TooltipWindow::show() { | ||
99 | if (m_visible) | ||
100 | return; | ||
101 | m_visible = true; | ||
102 | raise(); | ||
103 | FbTk::FbWindow::show(); | ||
104 | } | ||
105 | |||
106 | void TooltipWindow::hide() { | ||
107 | timer.stop(); | ||
108 | OSDWindow::hide(); | ||
109 | } | ||