Author: greg.ercolano
Date: 2013-04-10 13:51:24 -0700 (Wed, 10 Apr 2013)
New Revision: 9871
Log:
Solve STR#2948: Add new method Fl_Widget::top_window() to return the widget's
top-level window.
Docs for existing Fl_Widget::window() revised to clarify the difference between
these two methods.
Docs for window() also moved from .H -> .cxx as per CMP (docs should be where
code implementation is).
Modified:
branches/branch-1.3/FL/Fl_Widget.H
branches/branch-1.3/src/Fl_Window.cxx
Modified: branches/branch-1.3/FL/Fl_Widget.H
===================================================================
--- branches/branch-1.3/FL/Fl_Widget.H 2013-04-10 20:13:12 UTC (rev 9870)
+++ branches/branch-1.3/FL/Fl_Widget.H 2013-04-10 20:51:24 UTC (rev 9871)
@@ -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.
Modified: branches/branch-1.3/src/Fl_Window.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Window.cxx 2013-04-10 20:13:12 UTC (rev
9870)
+++ branches/branch-1.3/src/Fl_Window.cxx 2013-04-10 20:51:24 UTC (rev
9871)
@@ -80,11 +80,32 @@
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 const_cast<Fl_Widget*>(w)->as_window(); // return if window, or
NULL if not
+}
+
/** Gets the x position of the window on the screen */
int Fl_Window::x_root() const {
Fl_Window *p = window();
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit