diff --git a/src/schedulable_state_widget.cc b/src/schedulable_state_widget.cc index 7daf8ca..0f35e34 100644 --- a/src/schedulable_state_widget.cc +++ b/src/schedulable_state_widget.cc @@ -18,50 +18,71 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#include "gettext.h" + #include "schedulable_state_widget.hh" +#include + +#include + using namespace sgpem; -Gtk::Tooltips -SchedulableStateWidget::_ttips; +Gtk::Tooltips* +SchedulableStateWidget::_ttips = NULL; SchedulableStateWidget::SchedulableStateWidget(Schedulable::state st) - : _color(1, 1, 1) + : Glib::ObjectBase("sgpem_SchedulableStateWidget"), CairoWidget(), _color(1, 1, 1) { + // Yes, we leak, but this will be up until the end of the app + if(!_ttips) _ttips = new Gtk::Tooltips(); + set_scaling_mode(scaling_to_w); set_state(st); } +SchedulableStateWidget::~SchedulableStateWidget() +{ + _ttips->unset_tip(*this); +} + void SchedulableStateWidget::set_state(Schedulable::state new_state) { + Glib::ustring tip; switch(new_state) { case Schedulable::state_future: _color = Color(1, 1, 1); // White - _ttips.set_tip(*this, "Future"); + tip = _("Future"); break; case Schedulable::state_ready: _color = Color(1, 1, 0); // Yellow - _ttips.set_tip(*this, "Ready"); + tip = _("Ready"); break; case Schedulable::state_running: _color = Color(0, 1, 0); // Green - _ttips.set_tip(*this, "Running"); + tip = _("Running"); break; case Schedulable::state_blocked: _color = Color(0, 0, 1); // Blue - _ttips.set_tip(*this, "Blocked"); + tip = _("Blocked"); break; case Schedulable::state_terminated: _color = Color(0, 0, 0); // Black - _ttips.set_tip(*this, "Terminated"); + tip = _("Terminated"); break; } + if(is_realized()) + { + assert(has_no_window() == false); + _ttips->set_tip(*this, tip); + } + queue_draw(); } diff --git a/src/schedulable_state_widget.hh b/src/schedulable_state_widget.hh index 672c34d..b658a1d 100644 --- a/src/schedulable_state_widget.hh +++ b/src/schedulable_state_widget.hh @@ -27,6 +27,7 @@ #include "cairo_elements.hh" #include "cairo_widget.hh" +#include "glibmm/refptr.h" #include "gtkmm/tooltips.h" namespace sgpem @@ -35,11 +36,12 @@ namespace sgpem { public: SchedulableStateWidget(Schedulable::state st); + ~SchedulableStateWidget(); void set_state(Schedulable::state new_state); protected: - virtual void draw_widget(cairo_t* ctx) = 0; + virtual void draw_widget(cairo_t* ctx); // with this method CairoWidget tells the needed drawing dimensions virtual void calc_drawing_size(size_t& width, size_t& height) const; @@ -48,8 +50,8 @@ namespace sgpem virtual void calc_widget_size(size_t& width, size_t& height) const; private: - Color _color; - static Gtk::Tooltips _ttips; + Color _color; + static Gtk::Tooltips* _ttips; }; } //~ namespace sgpem