Hi,

> Fabio Bracci wrote:
>
> > The problem I am facing now is that I have generated with fluid a window 
> > with a scroll with a group; the group is the one holding the complex widget 
> > structure.
> > In my case I should wrap the group's draw() call with the offscreen code 
> > ... but I can't!
> > /usr/include/FL/Fl_Group.H:56: error: �virtual void 
> > Fl_Group::draw()� is protected
> > Is there a way to trigger the draw() method of a group from the outside?
> > The alternative would be again deriving Fl_Group to customize draw(), but 
> > fluid doesn't know anything about my custom widgets, so I will not be able 
> > to use a Group with offscreen code from fluid.
> >
> > In short: how is it possible to trigger the protected draw() of the inner 
> > Group without dismantling the complex widget (built with fluid)?
>
> First: I just wanted to suggest that we should change all draw methods
> to be public instead of protected, but I did not yet do it. This is just
> for such problems that you encountered here. IMHO, there's no reason to
> protect the draw methods, because draw() is virtual anyway.

I just read a post from Roman Kontor stating that in principle the draw() 
functions should be called just through Fl::flush(), therefore it should be the 
responsibility of the framework ... but this protection is broken, as in some 
widgets draw() is broken.
Here you have two contrasting requirements, I'd think at a design problem ... 
no idea what to suggest, tough.
Does any documentation in the form of object diagrams / UML diagrams / flow 
charts / used software patterns exist?

> Short term solution for your problem: a simple cast of the pointer
> solves your problem, e.g.:
>
> Fl_Widget *wi = (Fl_Widget *)my_group; // cast to base class
> wi->draw(); // this calls Fl_Group::draw() :-)
>
> Maybe you can also use a "short" form without an intermediate variable,
> but this is less intuitive code:
>
> ((Fl_Widget *)my_group)->draw(); // untested, but should work (?)
>
> Another (tested) possibility. Define this somewhere in your code:
>
> static inline void draw_sub(Fl_Widget *W) { W->draw(); }
>
> Then you can write:
>
> draw_sub(my_group); // calls virtual draw() method of my_group.


I like this second solution more, it still relies on the compiler's type 
checking; I dislike C-like type castings, they are error prone ... a safer way 
would be to use a reinterpret_cast<Fl_Widget *>(my_group)
I haven't tested these solutions thoroughly, maybe I'll need the suggestions of 
Roman; in any case now it compiles straight away.

> Albrecht
>
> P.S. I filed STR # 2142, see http://www.fltk.org/str.php?L2142

thanx! I'm working with fltk 1.1.9, I need a stable platform, do you believe 
such bugfixes will be ported down to it?
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to