From steele@skisas.usask.ca Fri Oct 20 18:12:34 1995 Newsgroups: comp.lang.idl-pvwave Path: tribune.usask.ca!news.sasknet.sk.ca!rover.ucs.ualberta.ca!unixg.ubc.ca!van-bc!news.rmii.com!newsjunkie.ans.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!csn!rsinc!info From: info@rsinc.com (Research Systems Inc.) Subject: Answers To IDL 4 Motif Widget Questions Message-ID: Sender: news@rsinc.com Nntp-Posting-Host: h6.rsinc.com Organization: Research Systems, Inc. Date: Fri, 13 Oct 1995 20:48:27 GMT Lines: 371 Widget Layout Changes in IDL Version 4 -------------------------------------- In IDL version 4, the sizing and layout of IDL's Motif widgets changed in several ways. Some users have found that IDL widget programs that behaved in a satisfactory manner with previous versions of IDL exhibit new, unwanted behaviors under IDL version 4. This document provides some background information, explains what changed in IDL, and shows how to solve some common problems users have encountered when upgrading to IDL version 4. This document is also available as a text file from the following ftp servers: Research Systems, Inc. Address: ftp.rsinc.com (192.5.156.17) Location: Boulder, Colorado USA Login as: ftp Password: @ Directory: pub/rsi/idl/notes File name: widgets.txt University of Colorado at Boulder Address: boulder.colorado.edu (128.138.240.1) Location: University of Colorado, Boulder Account: ftp Password: @ Directory: pub/rsi/idl/notes File name: widgets.txt NOTE: The solutions presented in this document assume that you are using IDL version 4.0.1. If you are using a previous version (notably IDL version 4.0), the first step in solving widget layout problems is to upgrade to IDL version 4.0.1. IDL version 4.0.1 is a free upgrade from version 4.0. Contact Research Systems or your IDL distributor for information if you do not have IDL version 4.0.1. Contact information is included at the end of this document. Background Information: ----------------------- The Motif Widgets in versions of IDL prior to IDL version 4 used the Motif XmRowColumn widget to do row/column style layout. When IDL widgets were originally implemented, this seemed like a natural solution to the layout problem. Over the years, however, we have encountered the following problems with this solution: - The exact behavior of the Motif XmRowColumn widget has changed from Motif version to Motif version as various features were added and bugs were fixed. This has been a consistency issue for IDL on various Motif platforms. - The Motif XmRowColumn widget deals poorly with widgets that are added to it after it has been realized. Often, no room is made for the added widgets, or they are forced into too-small or inappropriate spaces. - The IDL programmer lacked enough control over the final sizes of the children of row or column bases. - The way that XmRowColumn resizes its children is somewhat unpredicatable. For example, sometimes label and button widgets grow or shrink along with their labels, but not always. - Microsoft Windows and the Macintosh lack functionality similar to XmRowColumn, so IDL handled the layout itself. This resulted in layouts that differed somewhat from the Motif version. The difference between Windows, Macintosh, and Motif layouts was a problem for cross platform development, which is usually one of IDL's strong features. These problems are the underlying issues that correspond to most of the widget problems reported by users of pre-version 4 IDL. As we moved into IDL version 4 development, it was clear to us that we needed to change our approach to IDL widget layout, both for reasons of consistency and to resolve recurring user complaints. What Changed: ------------- As described above, the main source of problems in IDL's Motif widget layout was the use of the Motif XmRowColumn layout widget. For IDL version 4, we dropped the use of XmRowColumn and began using the same layout code used for the Windows and Macintosh versions of IDL. This change resulted in a number of improvements to the behavior of IDL widgets. For example: - Cross-platform consistency of widget layout has been greatly improved. - Children can be added to widget bases after realization in a predictable way. - The XSIZE and YSIZE keywords -- which were considered "hints" in previous versions of IDL -- are now uniformly obeyed, even after the widget has been realized. - If the programmer explicitly sets a size for a widget, the pre-set size is maintained no matter what happens to the widget's contents. However, if no explicit size is set, the widget's "natural" size is used, and the widget will resize itself to fit its contents. - The GEOMETRY keyword to WIDGET_INFO allows an IDL program to obtain detailed size and layout information about a widget. Overall, this change has greatly improved the consistency of IDL widgets, and has almost eliminated an entire category of user complaints. However, it has caused some problems in existing programs: - Layout flicker when adding children to an already realized widget base. - Changed sizing behavior when a widget value changes: Either the widget used to resize and no longer does, or it used to stay constant and now it changes. This seeming contradiction is due to the fact that the old layout method was inconsistent in its resizing behavior. - Problems creating uniform grids of labels and buttons. Solutions and Workarounds ------------------------- The online version of the IDL User's Guide for IDL version 4.0.1 has some useful discussion of widget sizing and layout issues. In particular, the solution to the layout flicker problem (using the new UPDATE keyword to WIDGET_CONTROL) is explained there. Other problems and their solutions are described below. Dynamic Resizing (desired or otherwise): ---------------------------------------- In IDL version 4, resizing rules are much more consistent and predicatable than in previous versions: - If an explicit size is set for a widget (XSIZE or YSIZE keywords), that size is used. - If no explicit size is set, the widget's "natural" size at the time it is realized is used. - Once realized, the size of a widget does not automatically change unless the widget's dynamic resize property has been set. This is done using the DYNAMIC_RESIZE keyword to the label, button, or droplist widgets. - The GEOMETRY keyword to WIDGET_INFO returns layout information for a specified widget. - The size of a widget can always be altered using the XSIZE and YSIZE keywords to WIDGET_CONTROL, even after realization. To enable dynamic resizing of label, button, or droplist widgets: - Do not set an explicit size. - Specify the DYNAMIC_RESIZE keyword. To prevent dynamic resizing, do one of the following: - Set the size explicitly. To do this without hardwiring a specific size, use WIDGET_INFO to find the natural size and then set it explicitly: GEO = WIDGET_INFO(w, /GEOMETRY) WIDGET_CONTROL, w, xsize=GEO.XSIZE, ysize=GEO.YSIZE - Make sure the DYNAMIC_RESIZE keyword is not specified. One common problem encountered by IDL customers is that the labels in their widget applications used to dynamically resize when the label values changed, but now this does not happen. The DYNLABEL procedure, included below, sets the DYNAMIC_RESIZE keyword for any labels contained in the specified widget tree when used with IDL version 4 or later. (For older IDL versions, it simply returns without changing anything, so it can be used with any version of IDL.) To use DYNLABEL, do the following: 1) Include the text between the ---cut here--- lines below in your widget program. Make sure you place the DYNLABEL procedure (and its companion routine, DYNLABEL_CALL) before any routines that call it in your .pro file. 2) Call DYNLABEL on the line just above where you realize your widget program, passing it the top level widget ID for the widget hierarchy. For example: base = WIDGET_BASE(/COLUMN) ... widget code ... DYNLABEL, base WIDGET_CONTROL, base, /REALIZE ---cut here--- PRO dynlabel_call, w ; Called by DYNLABEL. Does recursive search for ; label widgets and sets their DYNAMIC_RESIZE property type = WIDGET_INFO(w, /TYPE) IF (type EQ 5) THEN BEGIN WIDGET_CONTROL, /DYNAMIC_RESIZE, w ENDIF ELSE IF (type EQ 0) THEN BEGIN child = WIDGET_INFO(W, /CHILD) WHILE (child NE 0) DO BEGIN DYNLABEL_CALL, CHILD CHILD = WIDGET_INFO(CHILD, /SIBLING) ENDWHILE ENDIF END PRO dynlabel, tlb ; For IDL versions 4.0 and newer, find all label widgets ; rooted and the specified top level widget and set their ; DYNAMIC_RESIZE property. IF (((BYTE(!version.release))(0) - (BYTE('0'))(0)) GE 4) THEN $ dynlabel_call, tlb END ---cut here--- We find this technique of using WIDGET_INFO to find widgets of a certain type recursively to be very handy. You can use it to avoid spreading awkward version-dependent code throughout your applications. Grids Of Labels And Buttons: ---------------------------- To produce a uniform grid of labels or buttons across multiple rows or columns, taking the lengths of the various labels into account, do the following: 1) Create a row/column base and fill it with the buttons. Do not specify explicit sizing for the buttons. 2) Use the GEOMETRY keyword to WIDGET_INFO to find the largest button. 3) Use the XSIZE and YSIZE keywords to WIDGET_CONTROL to explicitly set all buttons to this size. 4) Realize the base. Although explicitly setting widget sizes is a bad idea in general, it is reasonable in this case because the size used is not chosen in an arbitrary way. This solution allows for variations between systems, such as the use of different fonts. For example, the following IDL statements create a row/column base containing 4 uniformly sized buttons with labels of varying length. buttons = ['Rocky', 'Bullwinkle', 'Borris', 'Natasha'] base = WIDGET_BASE(COLUMN=2) xs = 0 ys = 0 FOR i = 0, N_ELEMENTS(buttons)-1 DO BEGIN b = WIDGET_BUTTON(base, VALUE=buttons(i)) geo = WIDGET_INFO(b, /GEOMETRY) if (geo.scr_xsize GT xs) THEN xs = geo.scr_xsize if (geo.scr_ysize GT ys) THEN ys = geo.scr_ysize ENDFOR b = WIDGET_INFO(base, /CHILD) WHILE (b NE 0L) DO BEGIN WIDGET_CONTROL, b, XSIZE=xs, YSIZE=ys b = WIDGET_INFO(b, /SIBLING) ENDWHILE WIDGET_CONTROL, base, /REALIZE ------------------------------------------------------------------------------ Contact Information ------------------------------------------------------------------------------ Contacting Research Systems, Inc. --------------------------------- Research Systems, Inc. 2995 Wilderness Place Boulder, CO 80301 USA Phone: 303-786-9900 Fax: 303-786-9909 E-mail (internet): info@rsinc.com E-mail (SPAN): ORION::IDL Contacting International Distributors of Research Systems Products ------------------------------------------------------------------ Austria, Germany, Lichtenstein, Luxembourg, Switzerland, Netherlands CreaSo, GmbH Telephone: 49 8105 25055 Talhof Str. 30 Fax: 49 8105 25623 D82205 Gilching Contact: Bernhard Kortmann Germany E-mail: 100137.2421@compuserve.com Japan Adam Net Ltd. Telephone: 81 35802 2251 Yushimadai Bldg. 2-31-27 Fax: 81 35802 2249 Yushima, Bunkyo-ku Contact: Taro Ishiguro Tokyo, 113, Japan E-mail: taro@adamnet.co.jp Canada Barrodale Computing Ltd. Telephone: 604-721-2206 8-1560 Church Avenue Fax: 604-721-2219 Victoria, B.C., V8P 2H1 Contact: Dr. Ian Barrodale Canada E-mail: ibarroda@csr.uvic.ca United Kingdom Floating Point Systems UK Ltd. Telephone: 44/734 776333 Ash Court Fax: 44/734 776433 23 Rose Street Contact: Ken Murphy Wokingham E-mail: ken@floating.demon.co.uk Berks RG11 1XS United Kingdom France Fast Parallel Solutions France Telephone: 33 1 46 87 25 22 1 Place Gustave Eiffel Fax: 33 1 46 87 71 38 Silic 267 Contact: Louis Tauziet 94578 Rungis Cedex, France E-mail: 100347.1577@compuserve.com Italy Alliant Computer Systems SRL Telephone: 39 39 6091766 Centro Direzionale Colleoni Fax: 39 39 6091779 Palazzo Taurus Contact: Chris Stuart Ingresso 3 E-mail: cs@alliant.cise.it 20041 Agrate Brianza MI, Italy Brazil SulSoft Telephone: 55 51 488 22 57 Rua Sao Luis, 1050 Fax: 55 51 470 41 13 94060-630 Gravatai - RS Contact: Michael Steinmayer Brazil E-mail: mis@inf.ufrgs.br Korea Intersys Telephone: 82 42 869 4746 373-1 KuSung-Dong Fax: 82 42 862 9239 YuSung-Gu Contact: Jong-Sik Yoon Tae Jun 305-701 E-mail: jysoon@isl.kaist.ac.kr Korea PRC, Hong Kong 3-Link Systems Telephone: 33 146 87 2522 140 Robinson Road Fax: 33 146 87 7138 # 05-03 Chow House Contact: Harry Lee Singapore 0106 E-mail: zdlee@singnet.com.sg