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 122 123 124 125
|
/* Copyright (C) 2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "MGTreeTooltip.h"
MGTreeTooltip::MGTreeTooltip(Gtk::TreeView *tree)
: _window(Gtk::WINDOW_POPUP), _tree(tree), _showing(false)
{
_window.add(_label);
_window.set_border_width(8);
_window.set_resizable(false);
_label.show();
_label.set_alignment(0.0, 0.5);
_label.signal_expose_event().connect_notify(SigC::slot(*this,&MGTreeTooltip::expose_event));
_window.set_double_buffered(false);
_label.set_double_buffered(false);
Gdk::Color color("#f8fcb8");
tree->get_colormap()->alloc_color(color);
_window.modify_bg(Gtk::STATE_NORMAL, color);
Gdk::Color lcolor("black");
tree->get_colormap()->alloc_color(lcolor);
_label.modify_bg(Gtk::STATE_NORMAL, lcolor);
tree->signal_motion_notify_event().connect_notify(SigC::slot(*this,&MGTreeTooltip::motion_event));
tree->signal_leave_notify_event().connect_notify(SigC::slot(*this,&MGTreeTooltip::leave_event));
}
void MGTreeTooltip::expose_event(GdkEventExpose *event)
{
int w, h;
_window.get_window()->get_size(w,h);
_window.get_window()->draw_rectangle(_window.get_style()->get_black_gc(),
false, 0, 0, w-1, h-1);
}
void MGTreeTooltip::motion_event(GdkEventMotion *motion)
{
_last_x= (gint)motion->x;
_last_y= (gint)motion->y;
_last_rx= (gint)motion->x_root;
_last_ry= (gint)motion->y_root;
if (_showing)
update();
else
{
if (!_timeout)
_timeout= Glib::signal_timeout().connect(SigC::slot(*this,&MGTreeTooltip::timeout), 1000);
}
}
bool MGTreeTooltip::timeout()
{
_showing= true;
_prev_path.clear();
update();
return false;
}
void MGTreeTooltip::leave_event(GdkEventCrossing *event)
{
if (_timeout)
_timeout.disconnect();
_window.hide();
_showing= false;
}
void MGTreeTooltip::update()
{
Gtk::TreePath path;
Gtk::TreeViewColumn *column;
int cx, cy;
if (_tree->get_path_at_pos(_last_x, _last_y, path, column, cx, cy))
{
if (_prev_path.empty() || _prev_path != path)
{
if (_show_signal.emit(path))
{
_prev_path= path;
_window.move(_last_rx+10, _last_ry-cy+40);
_window.show();
if (_window.get_window())
_window.get_window()->clear();
_window.queue_draw();
}
else
_window.hide();
}
}
else
_window.hide();
}
void MGTreeTooltip::set_text(const Glib::ustring &text)
{
if (_window.get_window())
_window.get_window()->clear();
_label.set_markup(text);
}
|