DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR Active]
Link: http://www.fltk.org/str.php?L2948
Version: 1.3-feature
This STR spawned from a discussion on fltk.development,
Subject: "RFC: method to find top level window?"
The suggestion is to add a method that returns the top-level window
for the current widget, i.e. the 'window manager window' the widget
is in.
This differs from Fl_Widget::window() which may return a sub-window,
if there is one, not necessarily the top-level window.
I suggested "toplevel_window()" because the term 'top-level' seems
to be used in the code comments, Albrecht offered "top_window()"
as a shorter alternative, which I think I'll go with here.
Attaching a patch suggesting the code implementation,
"toplevel_window.patch".
Also attaching a test program, "test-top_window.cxx"
which compares the return value of window() and top_window() for
various widgets and windows in the presence of sub-windows.
We should also probably do a code check on all of FLTK
to make sure "window()" isn't being used where top_window()
would be correct. I believe it's only recently that FLTK reliably
supported sub-windows, so the chances of apps using them are
higher now, and little problems are more likely to spring up,
such as STR #2944 [2].
Comments welcome.
Link: http://www.fltk.org/str.php?L2948
Version: 1.3-feature
Index: FL/Fl_Widget.H
===================================================================
--- FL/Fl_Widget.H (revision 9868)
+++ FL/Fl_Widget.H (working copy)
@@ -919,12 +919,8 @@
*/
void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
- /** Returns a pointer to the primary Fl_Window widget.
- \retval NULL if no window is associated with this widget.
- \note for an Fl_Window widget, this returns its <I>parent</I> window
- (if any), not <I>this</I> window.
- */
Fl_Window* window() const ;
+ Fl_Window* top_window() const;
/** Returns an Fl_Group pointer if this widget is an Fl_Group.
Index: src/Fl_Window.cxx
===================================================================
--- src/Fl_Window.cxx (revision 9868)
+++ src/Fl_Window.cxx (working copy)
@@ -80,11 +80,33 @@
clear_visible();
}
+/** Returns a pointer to the nearest parent window up the widget hierarchy.
+ This will return sub-windows if there are any, or the parent window if
there's no sub-windows.
+ If this widget IS the top-level window, NULL is returned.
+ \retval NULL if no window is associated with this widget.
+ \note for an Fl_Window widget, this returns its <I>parent</I> window
+ (if any), not <I>this</I> window.
+ \see top_window()
+*/
Fl_Window *Fl_Widget::window() const {
for (Fl_Widget *o = parent(); o; o = o->parent())
if (o->type() >= FL_WINDOW) return (Fl_Window*)o;
return 0;
}
+
+/** Returns a pointer to the top-level window for the widget.
+ In other words, the 'window manager window' that contains this widget.
+ This method differs from window() in that it won't return sub-windows (if
there are any).
+ \returns the top-level window, or NULL if no top-level window is
associated with this widget.
+ \see window()
+*/
+Fl_Window *Fl_Widget::top_window() const {
+ const Fl_Widget *w = this;
+ while (w->parent()) { w = w->parent(); } // walk up the widget
hierarchy to top-level item
+ return w->type() >= FL_WINDOW ? ((Fl_Window*)w) // is top item a
window? If so, return it..
+ : ((Fl_Window*)0); // if not, return 0
+}
+
/** Gets the x position of the window on the screen */
int Fl_Window::x_root() const {
Fl_Window *p = window();
_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev