Fanning Software Consulting

Finding the Top-Level Base Widget

QUESTION: I realize the ID of the top-level base is often in the event structure, but in my program I have several top-level bases. Sometimes I need to know the top-level base of a particular widget hierarchy and that value is not in the event structure. Given that I know a widget ID in the proper hierarchy, how can I find the ID of the widget at the top of that hierarchy?

ANSWER: Well, you can fool around for an hour and write a slick recursive function like I did, or you can save yourself the effort (not to mention the embarrassment when it is pointed out to you) and find the proper ID in a single line. Assuming the widget ID you know is in the variable widgetID, you should try something like this:

   parent = widgetID
   WHILE Widget_Info(parent, /Parent) NE 0 DO $
      parent = Widget_Info(parent, /Parent)

Web Coyote's Guide to IDL Programming