RE: [gtkmm] Two beginners questions to signal handling



Hi,

On Tue,  6 Jan 2004, Gene Ruebsamen <gene erachampion com> wrote:

> >is there a way to connect the signal handler
> >    B::something_in_B_selected() to A::update_values_in_A()?
> >   class A : public Gtk::VBox
> >   class B : public Gtk::VBox

> Here's an example (someone can step in and tell me if this is the
> preferred way of doing things):
>    B::something_in_B_selected() to A::update_values_in_A()?
>    class A : public Gtk::VBox
>    class B : public Gtk::VBox
> // Example given here
> The key is to pass a MainWindow pointer to the MainMenu constructor.
> You can then use this pointer to MainWindow to connect your signals
> to any signal handler in MainWindow.  I've declared MainMenu to be
> a friend of MainWindow in order to allow access to the protected
> signal handlers.

> If anyone has a better way of doing this, please speak up. =)
 
I CAN'T MAKE THE LETTERS ANY BIGGER; but ...

If the goal is just to get your program working, this is as good
a way as any - but it defeats the whole purpose of classes.

One way would be -
Provide class A with a register() interface function so
that if an event in B occurs, it is left to A to decide upon
the necessary action - maybe postpone it! The main thing is
to act through interfaces so that instances don't become classes!

e.g.
class A
{
typedef enum { E1, E2, E3 } ACTION;
  class_B		b;
  
 void register( ACTION now ) { if( can_do_it( now ) ) do_it(); }
}


Another way would be -
Since in the example given it appears that the MainWindow and 
the MainMenu are essentially in existence together or not at all;
one could derive MainGate

e.g.
class MainGate : public Gtk::Window, public Gtk::Menu
{
 // class definition 
};

and do the signal connection in MainGate c'tor or func. where
the data of both parent classes are accessible.

Hope this is useful.

- arvind r.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]