Re: GTK architecture



On Fri, Feb 14, 2003 at 04:23:00PM -0500, Havoc Pennington wrote:
> On Fri, Feb 14, 2003 at 10:17:49PM +0100, Ernst De Ridder wrote:
> > I've just begun examining the architecture of gtk, and was a bit shocked to
> > find out that all event handling is hardcoded in the widgets. Am I missing
> > something here?
> > 
> > If yes, what? If no, how did this happen and are there any plans to remedy
> > this? 
> > 
> 
> I think you'll have to explain a bit more what you mean by "hardcoded
> in widgets" and what alternative architecture you are talking
> about. Concrete examples perhaps.

Example: gtkspinbutton.c, function gtk_spin_button_button_press
It checks the position of the mouse, to determine which arrow the mouse is
on. And then:

     if (event->button == 1)
       start_spinning (spin, GTK_ARROW_UP, spin->adjustment->step_increment);
     else if (event->button == 2)
       start_spinning (spin, GTK_ARROW_UP, spin->adjustment->page_increment);

I have no problems with this function checking the position of the mouse. 
After all, only the drawing function knows precisely where everything is 
drawn. But I would not like it to decide how to react to this event, because 
hardwiring the control into the view makes it too difficult to change the 
control (e.g. for accessibility reasons, or to experiment with new user 
interfaces). I would like the view to pass the event to a controller, 
together with information on where the event occured, e.g. 'this event on
arrow-up'. The controller checks the event (say left-click) and signals the
model (GtkAdjustment) 'step-decrement', the model handles this and updates the
view.

What do you think?

Ernst




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