Re: [gtkmm] Another Events problem
- From: Phillip Neiswanger <sigsegv prodigy net>
- To: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Re: [gtkmm] Another Events problem
- Date: Tue, 17 Feb 2004 23:17:30 -0700
On Sat, 14 Feb 2004 13:20:18 -0700, Phillip Neiswanger
<sigsegv prodigy net> wrote:
In this program the main working widget is a drawingarea. It is
contained in a frame. At certain points it makes sense to allow the
user to split this widget. I wrote some code that would remove the
drawingarea from the frame, construct 2 new drawingarea widgets and
place them in a vertical or horizontal paned widget, then add the paned
widget to the frame and delete the original drawingarea. That code
works and when I split the original drawingarea it generates the 2 paned
drawingareas. Unfortunately, the new drawingareas no longer get any
events even though the code to set up the events is the same. I tried
setting the events and focus parameters in the paned widget, but that
doesn't help. Then it occured to me that the paned widget might be a
windowless widget, so I created an EventBox and stuffed the paned widget
in it and added the eventbox to the frame instead of the paned widget.
So far I can't get that code to work. It just hangs the program. I
don't really care about that because what I really want to know is the
following.
What am I missing? Why don't the drawingareas get events when I put
them in a paned widget? Is there some parameter I need to set in the
paned widget, or do I simple need to get the eventbox code working?
Please excuse me if I'm being very dense. The following is some example
code that readily exercises the problem.
#include <libgnomemm/main.h>
#include <libgnomeuimm/init.h>
#include <libgnomeuimm/app.h>
#include <gtkmm/frame.h>
#include <gtkmm/paned.h>
#include <gtkmm/drawingarea.h>
#include <gdkmm/color.h>
const char *name = "example";
class DerivedDrawingArea : public Gtk::DrawingArea
{
public:
typedef SigC::Signal1<void, DerivedDrawingArea*> SplitJoinSignal;
DerivedDrawingArea();
virtual ~DerivedDrawingArea();
SplitJoinSignal split() { return _split; }
SplitJoinSignal join() { return _join; }
protected:
virtual bool on_expose_event(GdkEventExpose*);
virtual bool on_configure_event(GdkEventConfigure*);
virtual bool on_key_press_event(GdkEventKey*);
private:
SplitJoinSignal _split,
_join;
};
class DerivedFrame : public Gtk::Frame
{
public:
DerivedFrame();
virtual ~DerivedFrame();
void split(DerivedDrawingArea*);
void join(DerivedDrawingArea*);
private:
SigC::Connection _split;
Gtk::Widget *_w;
};
class DerivedHPaned : public Gtk::HPaned
{
public:
DerivedHPaned(DerivedFrame*, DerivedDrawingArea*);
virtual ~DerivedHPaned();
private:
DerivedDrawingArea *dda1,
*dda2;
};
class DerivedApp : public Gnome::UI::App
{
public:
DerivedApp();
virtual ~DerivedApp();
};
DerivedDrawingArea::DerivedDrawingArea()
{
set_flags(get_flags()|Gtk::CAN_FOCUS);
add_events(Gdk::KEY_PRESS_MASK);
}
DerivedDrawingArea::~DerivedDrawingArea()
{
}
bool
DerivedDrawingArea::on_expose_event(GdkEventExpose*)
{
get_window()->clear();
return true;
}
bool
DerivedDrawingArea::on_configure_event(GdkEventConfigure*)
{
get_window()->set_background(Gdk::Color("black"));
return true;
}
bool
DerivedDrawingArea::on_key_press_event(GdkEventKey* e)
{
bool rV = Gtk::DrawingArea::on_key_press_event(e);
if (rV == false)
{
if ( (e->keyval == GDK_S || e->keyval == GDK_s)
&& (e->state & GDK_CONTROL_MASK))
{
_split(this);
}
else if ( (e->keyval == GDK_J || e->keyval == GDK_j)
&& (e->state & GDK_CONTROL_MASK))
{
_join(this);
}
else
std::cerr << "key: " << char(e->keyval) << '\n';
}
return rV;
}
DerivedHPaned::DerivedHPaned(DerivedFrame* df, DerivedDrawingArea*)
{
dda1 = new DerivedDrawingArea;
dda2 = new DerivedDrawingArea;
pack1(*dda1, true, true);
pack2(*dda2, true, true);
dda1->join().connect(SigC::slot(*df, &DerivedFrame::join));
dda2->join().connect(SigC::slot(*df, &DerivedFrame::join));
}
DerivedHPaned::~DerivedHPaned()
{
}
DerivedFrame::DerivedFrame()
{
set_border_width(0);
set_shadow_type(Gtk::SHADOW_NONE);
DerivedDrawingArea *dda = new DerivedDrawingArea;
_split = dda->split().connect(SigC::slot(*this,
&DerivedFrame::split));
_w = dda;
add(*_w);
show_all();
}
DerivedFrame::~DerivedFrame()
{
}
void
DerivedFrame::split(DerivedDrawingArea* dda)
{
_split.disconnect();
DerivedHPaned *dhp = new DerivedHPaned(this, dda);
remove();
delete _w;
add(*dhp);
_w = dhp;
show_all_children();
}
void
DerivedFrame::join(DerivedDrawingArea*)
{
std::cerr << "DerivedFrame::join()\n";
}
DerivedApp::DerivedApp() : Gnome::UI::App(name, name)
{
set_resizable();
set_default_size(640, 480);
set_wmclass(name, name);
set_contents(*Gtk::manage(new DerivedFrame));
show_all();
}
DerivedApp::~DerivedApp()
{
}
int
main(int argc, char *argv[])
{
Gnome::Main main(name, name, Gnome::UI::module_info_get(), argc,
argv);
DerivedApp derivedApp;
main.run(derivedApp);
return 0;
}
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]