Re: [fltk.development] [RFE] STR #2948: Add a method to Fl_Widgetthat returns its top-level window

2013-04-12 Thread Albrecht Schlosser
On 12.04.2013 18:57, Greg Ercolano wrote:

 Albrecht We're only calling const methods anyway, as x(), y(), window(),
 Albrecht and this code is not subject to be changed in the future.

 Yes, though for some reason as_window() is not const,
 (it probably should be), which is why that cheat is necessary at the end
 there. Maybe using const_castFl_Widget*(w)-as_window() is better,
 which is what I decided to go with in top_window_offset().. will check.

Using const_cast is only another way to write it, but means the
same essentially, doesn't it? However, if some compilers wouldn't
flag a warning for const_cast but would for the old-style cast,
then we could maybe use it, but according to the CMP this shouldn't
be used for fltk 1.1 code, however it should be used for 2.0 code.
1.3 code is not (yet) specified, so we'd have to make a decision
about this first.

Concerning as_window(): ISTR that the first proposal was const, but
for some reason someone removed the const, but I'm not sure about it.

 Note in manolo's implementation, const is cast away at the top
 at the declaration of the variable, but I just switched it to const
 and cast const away only at the place where it was needed, at the
 as_window() call.

 So this does two things:

 1) Keeps the variable const so one can't later add code like
w-label(yoo hoo); without getting an error..
hey, it could be more subtle ;)

Yep, that's what I wrote with other words, isn't it? You cited it
above. I don't think that such a tiny method will ever be changed.
However, I'm not against your proposal, please go ahead...

 2) Highlights exactly where the cheat is needed (at as_window())
so if as_window() ever changes in the future to be const, it's
easier to find and remove the const cast-away.

Fair point.

 Is there a reason as_window() and friends (other virtual
 implementations) are not const methods? Fl_Window::window() is.

You mean: Fl_Window* Fl_Widget::window() const is, right?

Other than what ISTR (see above), I don't know. Probably
Fl_Window* Fl_Widget::window() could be const as well, but
can we change it w/o breaking the ABI?


Albrecht

___
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev


Re: [fltk.development] [RFE] STR #2948: Add a method to Fl_Widgetthat returns its top-level window

2013-04-12 Thread Ian MacArthur
On 12 Apr 2013, at 18:44, Albrecht Schlosser wrote:

 Using const_cast is only another way to write it, but means the
 same essentially, doesn't it? However, if some compilers wouldn't
 flag a warning for const_cast but would for the old-style cast,
 then we could maybe use it, but according to the CMP this shouldn't
 be used for fltk 1.1 code, however it should be used for 2.0 code.
 1.3 code is not (yet) specified, so we'd have to make a decision
 about this first.

I'm in favour of allowing the C++ style casts.
I expect that it probably works with all the extant compilers now?
Does anyone know for sure?




___
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev