Re: [gtkmm] Application Design Problem
- From: Ivan Popivanov <popivan gmx net>
- To: Ivan Popivanov <popivan gmx net>
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] Application Design Problem
- Date: Sat, 06 Dec 2003 03:09:04 -0500
Resolved, my use of gtk was erroneous.
Ivan Popivanov wrote:
Hi,
Here is an outline of the hierarchy design that I came up with for my
application:
Main Window: GtkWindow: main application window
GtkVBox: to hold the menu, toolbar, application client area
Client Area: not sure about the type of this object, see below
GtkFixed: to manage the coordinate of few widgets that will be
needed in the client area
MyObjects: see below
For the client area I need something that I can draw on. My first
thought was GtkDrawingArea, however, I run into problems when I tried
to attach the GtkFixed child. GtkDrawingArea is not a container right?
Then I tried GtkWindow and it didn't work either (the name is kind of
misleading, isn't it). At the end I decided that probably the best
match is GtkBin, the reason, the client area is going to have a single
child, namely the GtkFixed.
My objects I created as GtkMisc (after few other tries), because I
want them to be window less, like GtkLabel. I added function members
to handle EXPOSE events.
THE PROBLEM is that I receive the expose event in the Client Area, so
I can draw the background etc, however, I don't get any expose events
in MyObjects. They are on the top of the client area, but they don't
receive any draw messages. It seems to me that in gtkmm a signal
(event) is propagated to only one widget.
One more thing, although I'm using gtkmm, I'm suspisous that it's a
Gtk problem.
Any idea/explanation about event propagation in gtkmm?
TIA,
Ivan
------------------------------------------------------------------------
#include <gdkmm.h>
#include <gtkmm.h>
#define APP_TITLE "Blah"
class HandView : public Gtk::Misc
{
public:
HandView( );
protected:
virtual bool on_expose_event( GdkEventExpose *event );
virtual bool on_configure_event( GdkEventConfigure *event );
};
class ViewWnd : public Gtk::Bin
{
public:
ViewWnd( );
protected:
virtual bool on_expose_event( GdkEventExpose *event );
private:
Gtk::Fixed fixed_;
HandView hand_view_;
};
class FrameWnd : public Gtk::Window
{
public:
FrameWnd( );
private:
Gtk::VBox wnd_vbox_;
ViewWnd view_;
};
inline
FrameWnd::FrameWnd( )
{
set_title( APP_TITLE );
/*
view_.add_events( Gdk::EXPOSURE_MASK |
Gdk::STRUCTURE_MASK |
Gdk::BUTTON_PRESS_MASK |
Gdk::POINTER_MOTION_MASK |
Gdk::BUTTON_RELEASE_MASK );
*/
wnd_vbox_.pack_start( view_ );
add( wnd_vbox_ );
show_all_children( );
}
inline
ViewWnd::ViewWnd( )
{
fixed_.put( hand_view_, 5, 5 );
add( fixed_ );
}
bool
ViewWnd::on_configure_event( GdkEventConfigure *event )
{
printf( "ViewWnd: Configure: rect( x = %d, y = %d, w = %d, h = %d )\n",
event->x, event->y,
event->width, event->height );
return true;
}
bool
ViewWnd::on_expose_event( GdkEventExpose *event )
{
printf( "ViewWnd: Expose: rect( x = %d, y = %d, w = %d, h = %d )\n",
event->area.x, event->area.y,
event->area.width, event->area.height );
Glib::RefPtr<Gdk::Window> win = get_window( );
Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(win);
Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap( );
Gdk::Color color;
color.set_red( 0xffff );
color.set_green( 0 );
color.set_blue( 0xffff );
colormap->alloc_color( color );
gc->set_rgb_fg_color( color );
int x, y, w, h;
int depth;
win->get_geometry( x, y, w, h, depth );
win->draw_rectangle( gc, true, 0, 0, w, h );
return false;
}
inline
HandView::HandView( )
{
set_size_request( 100, 100 );
}
bool
HandView::on_expose_event( GdkEventExpose *event )
{
printf( "HandView: Expose: rect( x = %d, y = %d, w = %d, h = %d )\n",
event->area.x, event->area.y,
event->area.width, event->area.height );
return false;
}
int
main( int argc, char **argv )
{
Gtk::Main kit( argc, argv );
FrameWnd frame_wnd;
Gtk::Main::run( frame_wnd );
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]