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: Mon, 01 Mar 2004 23:51:42 -0700
On Sat, 14 Feb 2004 13:20:18 -0700, Phillip Neiswanger
<sigsegv prodigy net> wrote:
Sorry if I'm being dense here. After sending my last message on this
subject, I worked on other stuff, but now I need to get this code
working. I'm including the example program I sent earlier with a few
modifications. These modifications all have to do with focus. I got to
this code after I tried setting the CAN_FOCUS flag of the DerivedFrame.
Doing so stopped the DerivedDrawingArea from receiving key_press events.
I checked the paned widget and it also sets the CAN_FOCUS flag. The way I
think the paned widget should work is when the mouse moves over a child
widget the child widget is given the focus. This is not happening in my
example, so I'm wondering if I'm not setting my flags properly or if
something else is going on. Does anyone have time to look at this?
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
#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*);
virtual bool on_focus_in_event(GdkEventFocus*);
virtual bool on_focus(Gtk::DirectionType);
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();
protected:
virtual bool on_cycle_child_focus(bool);
virtual bool on_cycle_handle_focus(bool);
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::FOCUS_CHANGE_MASK|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;
}
bool
DerivedDrawingArea::on_focus_in_event(GdkEventFocus* e)
{
std::cerr << "DerivedDrawingArea::on_focus_in_event\n";
return DrawingArea::on_focus_in_event(e);
}
bool
DerivedDrawingArea::on_focus(Gtk::DirectionType dt)
{
std::cerr << "DerivedDrawingArea::on_focus\n";
return DrawingArea::on_focus(dt);
}
DerivedHPaned::DerivedHPaned(DerivedFrame* df, DerivedDrawingArea*)
{
add_events(Gdk::FOCUS_CHANGE_MASK);
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()
{
}
bool
DerivedHPaned::on_cycle_child_focus(bool r)
{
std::cerr << "DerivedHPaned::on_cyclde_child_focus\n";
return HPaned::on_cycle_child_focus(r);
}
bool
DerivedHPaned::on_cycle_handle_focus(bool r)
{
std::cerr << "DerivedHPaned::on_cyclde_handle_focus\n";
return HPaned::on_cycle_handle_focus(r);
}
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]