FLTK logo

STR #2338

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | SVN ⇄ GIT ]

STR #2338

Application:FLTK Library
Duplicate Of:STR #2948
Status:1 - Closed w/Resolution
Priority:1 - Request for Enhancement, e.g. asking for a feature
Scope:3 - Applies to all machines and operating systems
Subsystem:Core Library
Summary:Propose to add a new method to Fl_Widget Fl_Widget::parent_root()
Version:1.4-feature
Created By:mingodad
Assigned To:AlbrechtS
Fix Version:1.3.3 (SVN: v9876)
Fix Commit:5fda885c0306561ab53266e16d87b3c4e164572c
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

No files


Trouble Report Comments:


Name/Time/Date Text  
 
#1 mingodad
04:25 Apr 09, 2010
Fl_Group* Fl_Widget::parent_root() const {
    Fl_Group *myparent = parent();
    while(myparent) {
        //if the parent parent is null
        //we consider it the root
        if(!myparent->parent()) return myparent;
        myparent = myparent->parent();
    }
    return NULL;
}
 
 
#2 matt
04:41 Apr 09, 2010
Sure, why no. I'd call the function "root()" and eliminate the two consecutive calls to myparent->parent() by storing the first result in a temporary variable.  
 
#3 ianmacarthur
04:58 Apr 09, 2010
If you are the top window, I think this code will return NULL... Should it perhaps return "this" in that case?  
 
#4 ianmacarthur
05:01 Apr 09, 2010
Also... is "root" maybe a misleading name?

On X11, that usually means the root window, which is usually the desktop itself.
I think this will return the top-level application window.

In which case somehting like "top_window" might be a better name?

Or am I missing the point?
--
Ian
 
 
#5 AlbrechtS
06:29 Apr 09, 2010
We could call it top_widget() or top_group(), but please not top_window(). Although not very usual, a widget can be removed from its parent = group (maybe window) and doesn't have a window then.

Since it returns an Fl_Group(), we can't easily return "this" if the widget itself is the top-level _widget_, but is not an Fl_Group. Thus, returning NULL if the widget is top-level itself would be more consistent, unless we return this->as_group() instead (which can also be NULL).

OTOH, if the question was to find the top-level window, then the method should not use parent() but window() internally, with the same restriction that a widget doesn't necessarily have a window. I know that there are some loops that look for the top-level window in the FLTK core, so this would be usable internally as well.

So, maybe we should extend this to add both:
Fl_Widget::top_window() and Fl_Widget::top_group().
 
 
#6 greg.ercolano
10:05 Apr 09, 2010
How is this different from the existing Fl_Widget::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;
}
 
 
#7 AlbrechtS
10:33 Apr 09, 2010
Fl_Widget::window() "stops" at the first Fl_Window it finds (going upwards through the widget tree), which can be a subwindow. Calling it again (in a loop) will eventually find the top-level window (or maybe not, if there is no such window, as I wrote before).  
 
#8 matt
12:54 Nov 14, 2010
Not essential for the 1.3.0 release. Temporarily moved to 1.4 .  
 
#9 AlbrechtS
19:09 Jan 15, 2023
The new method Fl_Widget::top_window() has been added in FLTK 1.3.3 in svn r9871 and enhanced in r9872 and r9876, see also STR #2948.

Closing this STR now.
 
     

Return to Bugs & Features ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.