- Widgets now will be shown. Still some problem with their background

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@820 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-08-03 15:43:21 +00:00
parent b76756c2a8
commit 56d7ddbc5a
3 changed files with 51 additions and 34 deletions

View File

@ -38,6 +38,14 @@
using namespace sgpem; using namespace sgpem;
using Gnome::Glade::Xml; using Gnome::Glade::Xml;
void
test_me()
{
// A test for widget display:
Simulation& sim = Simulation::get_instance();
sim.get_history().add_process("goofy", 0, 0);
}
GuiBuilder::GuiBuilder(const std::string& gladefile) GuiBuilder::GuiBuilder(const std::string& gladefile)
: _refXml(Xml::create(gladefile)) : _refXml(Xml::create(gladefile))
@ -58,7 +66,8 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
_refXml->get_widget("MenuItem.Help.About", help_about); _refXml->get_widget("MenuItem.Help.About", help_about);
AboutDialog* about_dialog = NULL; AboutDialog* about_dialog = NULL;
_refXml->get_widget("AboutDialog", about_dialog); _refXml->get_widget("AboutDialog", about_dialog);
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show)); //help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
help_about->signal_activate().connect(sigc::ptr_fun(test_me));
// Temporary code to test the Schedulables custom widget // Temporary code to test the Schedulables custom widget
Expander* scheds_expander = NULL; Expander* scheds_expander = NULL;
@ -68,9 +77,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
// we have to remember to manually show custom added widgets: // we have to remember to manually show custom added widgets:
scheds_widget->show(); scheds_widget->show();
// A test for widget display:
Simulation& sim = Simulation::get_instance();
sim.get_history().add_process("goofy", 0, 0);
} }

View File

@ -26,9 +26,11 @@
#include <gdkmm/window.h> #include <gdkmm/window.h>
#include <cassert>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
using namespace sgpem; using namespace sgpem;
@ -36,6 +38,7 @@ SchedulablesWidget::SchedulablesWidget()
: Glib::ObjectBase("sgpem_CairoWidget"), : Glib::ObjectBase("sgpem_CairoWidget"),
Gtk::Widget(), _h(1), _buf(NULL) Gtk::Widget(), _h(1), _buf(NULL)
{ {
set_flags(Gtk::NO_WINDOW);
// Register this observer: // Register this observer:
Simulation::get_instance().get_history().attach(*this); Simulation::get_instance().get_history().attach(*this);
} }
@ -60,6 +63,7 @@ SchedulablesWidget::update(const History& history)
// get_window() returns a null pointer // get_window() returns a null pointer
// if the widget has not been realized // if the widget has not been realized
_buf = Gdk::Pixmap::create(get_window(), w, _h); _buf = Gdk::Pixmap::create(get_window(), w, _h);
cairo_t* ctx = gdk_cairo_create(_buf->gobj()); cairo_t* ctx = gdk_cairo_create(_buf->gobj());
// do the drawing... // do the drawing...
@ -69,6 +73,8 @@ SchedulablesWidget::update(const History& history)
// manually force an expose_event? // manually force an expose_event?
cairo_destroy(ctx); cairo_destroy(ctx);
queue_draw();
} }
@ -95,13 +101,13 @@ SchedulablesWidget::calc_height(const History& history) const
void void
SchedulablesWidget::on_realize() SchedulablesWidget::on_realize()
{ {
set_flags(Gtk::REALIZED); if(is_realized()) return;
// Add other events we want to manage (as mouse clicks) Gtk::Widget::on_realize();
// when needed ensure_style();
add_events(Gdk::EXPOSURE_MASK);
GdkWindowAttr attributes; GdkWindowAttr attributes;
memset(&attributes, 0, sizeof(attributes));
Gtk::Allocation alloc = get_allocation(); Gtk::Allocation alloc = get_allocation();
@ -110,17 +116,20 @@ SchedulablesWidget::on_realize()
attributes.width = alloc.get_width(); attributes.width = alloc.get_width();
attributes.height = alloc.get_height(); attributes.height = alloc.get_height();
attributes.wclass = GDK_INPUT_OUTPUT; attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = get_visual()->gobj(); attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
attributes.colormap = get_colormap()->gobj(); attributes.window_type = GDK_WINDOW_CHILD;
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(), Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
&attributes, &attributes,
GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP | Gdk::WA_X | Gdk::WA_Y |
GDK_WA_VISUAL | GDK_WA_WMCLASS); Gdk::WA_WMCLASS);
unset_flags(Gtk::NO_WINDOW);
set_window(window); set_window(window);
// get_style()->attach(window);
window->set_user_data(gobj()); window->set_user_data(gobj());
get_style()->set_background(window, Gtk::STATE_ACTIVE); get_style()->set_background(window, Gtk::STATE_ACTIVE);
_refGC = Gdk::GC::create(window);
} }
void void
@ -147,21 +156,22 @@ SchedulablesWidget::on_size_allocate(const Gtk::Allocation& allocation)
bool bool
SchedulablesWidget::on_expose_event(GdkEventExpose* event) SchedulablesWidget::on_expose_event(GdkEventExpose* event)
{ {
if(!event || event->count > 0)
return false;
// calculated dinamically: // calculated dinamically:
set_size_request(get_allocation().get_width(), _h); int w = get_allocation().get_width();
set_size_request(w, _h);
// Clip to redraw only the smallest possible area // Clip to redraw only the smallest possible area
std::auto_ptr<Gdk::Rectangle> clip_area; std::auto_ptr<Gdk::Rectangle> clip_area;
if(event)
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y, clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
event->area.width, event->area.height)); event->area.width, event->area.height));
else
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(0, 0, w, _h));
// Use double buffering or we're CPU-dead // Use double buffering or we're CPU-dead
// Copy from the buffer to the screen // Copy from the buffer to the screen
if(_buf) if(_buf)
get_window()->draw_drawable(Gdk::GC::create(get_window()), _buf, get_window()->draw_drawable(_refGC, _buf,
clip_area->get_x(), clip_area->get_y(), clip_area->get_x(), clip_area->get_y(),
clip_area->get_x(), clip_area->get_y(), clip_area->get_x(), clip_area->get_y(),
clip_area->get_width(), clip_area->get_height()); clip_area->get_width(), clip_area->get_height());

View File

@ -59,6 +59,7 @@ namespace sgpem
typedef std::vector<area_callback_t> areas_vect_t; typedef std::vector<area_callback_t> areas_vect_t;
Glib::RefPtr<Gdk::Pixmap> _buf; Glib::RefPtr<Gdk::Pixmap> _buf;
Glib::RefPtr<Gdk::GC> _refGC;
}; };
} //~ namespace sgpem } //~ namespace sgpem