Paul Davis <[EMAIL PROTECTED]> writes:

> you're not the only ones; i've discussed this issue several times on
> this list in the past.

o Thanks for your analyses (below).  As I said originally, I've
  searched the archives for this, but never found the right
  keywords.  Could you provide some "Subject:" lines?   Searching for
  your name doesn't help -- you post too much to the lists.  (This is
  a compliment, not a complaint.)


> however, if you're really doing
> Model-View-Controller style programming, which is highly desirable and
> it sounds as if you are, then Havoc's suggestion of:
> 
>    handle_widget_state_change () {
>       if (widget->representation_of_object_state() != object->state())
>             widget->set_state (object->state());
>   }
> 
> is the *only* correct route to take here.

o I (possibly mis-) read Havoc's:

  >  if (current_state == gtk_toggle_button_get_active (toggle))
  >    return;
 
  a little differently.  If his "current_state" is your
  "object->state()" (which makes more sense than my interpretation of
  "widget->previous_state()"), and if "handle_widget_state_change()"
  is a GTK signal-handler/callback, I would think it should be:

    handle_widget_state_change () {
        if (widget->representation_of_object_state() != object->state())
            object->set_state (widget->state());
    }

  in order to break the feedback loop that causes me problems:

    1) object ("Model") state changes
    2) object changes widget X ("View") state
    3) widget X is also a "Controller", thus emits a signal which is
       caught by a signal handler which changes object's state
    4) loop back to 1)


> in my C++ code, i tend to use a void * (aka gpointer) as an extra arg
> to all functions that change the state of my objects ("models"), an
> arg i call "src". when the objects emit signals as a result of the
> change, they include the "src" argument. as a result, widgets ("views"
> and/or "controllers") can do things like:
> 
>        handle_widget_state_change (void *src) {
>              if (src == this) {
>                  /* ignore */
>                  return;
>              }
>              ....
>       }
> 
> this lets a widget set the state of its underlying object (when acting
> as a controller), supplying "itself" as the src pointer, and thus
> ignore any notifications from the object when they are sent following
> the object's state change.

o Is the "this" in the above code fragment the object (Model) or the
  widget (View/Controller)?  If object/Model, I don't understand
  because mine don't emit signals (widgets/Controllers emit signals;
  objects/Models do things like gtk_toggle_button_set_active()).  If
  "this" is the widget/Controller, when "src==this" is exactly when
  the action should take place.


--
MARK
[EMAIL PROTECTED]
_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to