- Add untested code to SchedulableWidget, manually inheriting from a raw Gtk::Widget

and doing things by hand


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@819 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-03 11:16:16 +00:00
parent 82289edc14
commit b76756c2a8
3 changed files with 66 additions and 31 deletions

View File

@ -26,7 +26,7 @@
#include "backend/thread.hh"
#include "backend/process.hh"
#include <cairo/cairo.h>
#include <cairo.h>
namespace sgpem
{

View File

@ -24,6 +24,8 @@
#include "backend/history.hh"
#include "backend/simulation.hh"
#include <gdkmm/window.h>
#include <iostream>
#include <memory>
@ -31,12 +33,9 @@ using namespace sgpem;
SchedulablesWidget::SchedulablesWidget()
: Gtk::DrawingArea(), _h(1), _buf(NULL)
: Glib::ObjectBase("sgpem_CairoWidget"),
Gtk::Widget(), _h(1), _buf(NULL)
{
// Add other events we want to manage (as mouse clicks)
// when needed
add_events(Gdk::EXPOSURE_MASK);
// Register this observer:
Simulation::get_instance().get_history().attach(*this);
}
@ -51,17 +50,14 @@ SchedulablesWidget::~SchedulablesWidget()
void
SchedulablesWidget::update(const History& history)
{
if(!is_realized())
return; // Nowhere to draw to.
// Determine the final height before to start drawing
unsigned int w = get_allocation().get_width();
_h = calc_height(history);
// FIXME TO THE EXPERT: this assertion fails.
// is this important???
assert(is_drawable());
// FIXME : write me using double buffering
// PROBLEM : get_window() seems to return a null pointer!!!
// I read on the web that get_window() returns a null pointer
// get_window() returns a null pointer
// if the widget has not been realized
_buf = Gdk::Pixmap::create(get_window(), w, _h);
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
@ -96,6 +92,37 @@ SchedulablesWidget::calc_height(const History& history) const
}
void
SchedulablesWidget::on_realize()
{
set_flags(Gtk::REALIZED);
// Add other events we want to manage (as mouse clicks)
// when needed
add_events(Gdk::EXPOSURE_MASK);
GdkWindowAttr attributes;
Gtk::Allocation alloc = get_allocation();
attributes.x = alloc.get_x();
attributes.y = alloc.get_y();
attributes.width = alloc.get_width();
attributes.height = alloc.get_height();
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = get_visual()->gobj();
attributes.colormap = get_colormap()->gobj();
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
&attributes,
GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP |
GDK_WA_VISUAL | GDK_WA_WMCLASS);
set_window(window);
// get_style()->attach(window);
window->set_user_data(gobj());
get_style()->set_background(window, Gtk::STATE_ACTIVE);
}
void
SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
{
@ -106,22 +133,31 @@ SchedulablesWidget::on_size_request(Gtk::Requisition* requisition)
}
void
SchedulablesWidget::on_size_allocate(const Gtk::Allocation& allocation)
{
set_allocation(allocation);
if(is_realized())
get_window()->move_resize(allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height());
}
bool
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
{
const Gtk::Allocation& allocation = get_allocation();
int width = allocation.get_width();
int height = allocation.get_height();
if(!event || event->count > 0)
return false;
// calculated dinamically:
set_size_request(get_allocation().get_width(), _h);
// Clip to redraw only the smallest possible 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,
event->area.width, event->area.height));
else
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(0, 0, width, height));
// Use double buffering or we're CPU-dead
// Copy from the buffer to the screen
if(_buf)
@ -130,9 +166,6 @@ SchedulablesWidget::on_expose_event(GdkEventExpose* event)
clip_area->get_x(), clip_area->get_y(),
clip_area->get_width(), clip_area->get_height());
// calculated dinamically:
set_size_request(width, _h);
return true;
}

View File

@ -25,13 +25,13 @@
#include "backend/history_observer.hh"
#include <cairo/cairo.h>
#include <gtkmm/drawingarea.h>
#include <cairo.h>
#include <gtkmm/widget.h>
#include <gdkmm/pixmap.h>
namespace sgpem
{
class SchedulablesWidget : public Gtk::DrawingArea, public HistoryObserver
class SchedulablesWidget : public Gtk::Widget, public HistoryObserver
{
public:
SchedulablesWidget();
@ -40,6 +40,8 @@ namespace sgpem
void update(const History& history);
protected:
virtual void on_realize();
virtual void on_size_allocate(const Gtk::Allocation& allocation);
virtual void on_size_request(Gtk::Requisition* requisition);
virtual bool on_expose_event(GdkEventExpose* event);
virtual bool on_button_press_event(GdkEventButton* event);