home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / faqs / comp / answers / motif-faq / part5 < prev    next >
Encoding:
Internet Message Format  |  1997-10-19  |  55.8 KB

  1. Path: senator-bedfellow.mit.edu!faqserv
  2. From: kenton@rahul.net (Ken Lee)
  3. Newsgroups: comp.windows.x.motif,comp.answers,news.answers
  4. Subject: Motif FAQ (Part 5 of 9)
  5. Supersedes: <motif-faq/part5_875789459@rtfm.mit.edu>
  6. Followup-To: poster
  7. Date: 18 Oct 1997 10:15:29 GMT
  8. Organization: none
  9. Lines: 1427
  10. Approved: news-answers-request@MIT.EDU
  11. Distribution: inet
  12. Expires: 1 Dec 1997 10:06:58 GMT
  13. Message-ID: <motif-faq/part5_877169218@rtfm.mit.edu>
  14. References: <motif-faq/part1_877169218@rtfm.mit.edu>
  15. Reply-To: kenton@rahul.net (Ken Lee)
  16. NNTP-Posting-Host: penguin-lust.mit.edu
  17. Summary: Motif Frequently Asked Questions (with answers).
  18. Keywords: FAQ question answer
  19. X-Last-Updated: 1997/08/27
  20. Originator: faqserv@penguin-lust.MIT.EDU
  21. Xref: senator-bedfellow.mit.edu comp.windows.x.motif:60053 comp.answers:28581 news.answers:114853
  22.  
  23. Archive-name: motif-faq/part5
  24. Last-modified: SEP 1, 1997
  25. Posting-Frequency: irregular
  26. Organization: Kenton Lee, X/Motif Consultant, http://www.rahul.net/kenton/
  27. URL:  http://www.rahul.net/kenton/faqs/mfaq_index.html
  28. Version: 6.3
  29.  
  30. -----------------------------------------------------------------------------
  31. Subject: 114)  TOPIC: LIST WIDGET
  32.  
  33. -----------------------------------------------------------------------------
  34. Subject: 115)  Should I create an XmList widget as a child of automatic
  35. XmScrolledWindow or use the XmCreateScrolledList() convenience function?
  36.  
  37. Answer:  With most implementations, the convenience function use internal
  38. hooks to give somewhat better scrolling performance.
  39.  
  40. Ken Lee, http://www.rahul.net/kenton/
  41.  
  42. -----------------------------------------------------------------------------
  43. Subject: 116)  How do I best put a new set of items into a list?
  44.  
  45. Answer:  Set the new list count and list by XtSetArgs and install them by
  46. XtSetValues.
  47.  
  48.     XmString list[SIZE];
  49.     int list_size;
  50.  
  51.     XtSetArg (args[n], XmNitemCount, list_size); n++;
  52.     XtSetArg (args[n], XmNitems, list); n++;
  53.     XtSetValues (w, args, n);
  54.  
  55.  
  56. or similarly with XtVaSetValues:
  57.  
  58.  
  59.     XtVaSetValues (w,
  60.        XmNitemCount, list_size,
  61.        XmNitems, list,
  62.        NULL);
  63.  
  64.  
  65. Each time the list is reset by this the old contents are freed by the widget
  66. and the new supplied list is copied.  Do *not* free the old list of items
  67. yourself as this would result in the space being freed twice.  It is not
  68. necessary to remove the items one at a time, nor to "zero" out the list first.
  69.  
  70. -----------------------------------------------------------------------------
  71. Subject: 117)  Can I have strings with different fonts in a list?
  72.  
  73. [Last modified: Sept 95]
  74.  
  75. Answer:  Yes. The strings are XmStrings. Each one can be created using a
  76. different character set using a different font.
  77.  
  78. However, arjav@caip.rutgers.edu (ARJAV PARIKH) wrote:
  79.  
  80. If a string is added to the listbox, the font in the listbox overrides the
  81. font set using XmCreateString.  The Command widget label retains the font set
  82. using XmCreateString.  I read in the MOTIF FAQ that it is possible to add
  83. strings with multiple fonts to the listbox.  I learned from one of the tech
  84. support persons that internal code of the listbox overrides the font.
  85.  
  86. Madhusudan Poolu (madhu@corp.sgi.com) replied:
  87.  
  88. You need to create a fontlist for your font and  add it to your listbox widget
  89. using XtVaSetValues ( wList, XmNfontList, yourFontList, NULL).  This technique
  90. can also be used to display multi-font strings in a list box.
  91.  
  92. -----------------------------------------------------------------------------
  93. Subject: 118)  Can I get a bitmap to show in a list item like I can in a
  94. Label?  I want to place a bitmap along with some normal text in my list items.
  95.  
  96. [Last modified: Jan 96]
  97.  
  98. Answer:  Andrew Lister (lister@bain.oz.au) writes:  The XbaeMatrix widget
  99. allows a bitmaps in a cell.  There will be support for colour pixmaps to be
  100. displayed in version 4.4 which should be available very soon. (The XbaeMatrix
  101. can be made to look and behave like a list widget.  The widget is compatible
  102. with Motif 1.2 and Motif 2.0.)  You can get the latest version of XbaeMatrix
  103. from the directory:
  104.         ftp://ftp.x.org/contrib/widgets/motif/
  105.  
  106. Alan Peery (peery@isc.tamu.edu) writes:  Motif 2.0 introduced the "container"
  107. widget, which offers 2-D icon and text layout similar to that found in many
  108. file management programs.  It could probably be used as a 1-D list widget
  109. also.
  110.  
  111. A previous source wrote: In Motif 1.x, you cannot do this.  The list contains
  112. XmStrings, and these only allow text in various character sets. The workaround
  113. is to define your font containing the icons you want. Then you can create a
  114. fontlist containing your icon font and the font you want the text in, and then
  115. make your items multi-segment XmStrings where the first segment contains the
  116. code of the icon you want with a charset that matches the icon font in your
  117. fontlist and the second segment with a charset matching the text font.
  118.  
  119.  
  120. -----------------------------------------------------------------------------
  121. Subject: 119)*  Can I have items with different colors in a list?
  122.  
  123. [Last modified: Sep 97]
  124.  
  125. Answer:  Andrew Lister (lister@bain.oz.au) writes:  The XbaeMatrix widget can
  126. have a different foreground and background in each cell, row or column.  (The
  127. XbaeMatrix can be made to look and behave like a list widget.  The widget is
  128. compatible with Motif 1.2 and Motif 2.0.)  You can get the latest version of
  129. XbaeMatrix from the directory:
  130.         ftp://ftp.x.org/contrib/widgets/motif/
  131.  
  132. Ken Lee wrote:  Not in Motif 1.x.  The list contains XmStrings, and these only
  133. allow text in various character sets.
  134.  
  135. However, in Motif 2.0 you _can_ have multiple colors in the same list since
  136. colored XmStrings are supported.
  137.  
  138. Thanks to Ken Lee, http://www.rahul.net/kenton/, for the update.
  139.  
  140. If you're using Motif 1.2, another possibility is to use SCO Premier Motif
  141. (1.2) library has this extension built into the List widget, along with a few
  142. others. See http://www.premier.sco.com/
  143.  
  144. Thanks to richardo@x.co.uk (Nhi Vanye)
  145.  
  146. -----------------------------------------------------------------------------
  147. Subject: 120)  How can I line up columns in a list?
  148.  
  149. [Last modified: Jan 96]
  150.  
  151. Answer:  Andrew Lister (lister@bain.oz.au) writes:  The XbaeMatrix can do this
  152. too, for both fixed and non fixed width fonts.  (The XbaeMatrix can be made to
  153. look and behave like a list widget.  The widget is compatible with Motif 1.2
  154. and Motif 2.0.)  You can get the latest version of XbaeMatrix from the
  155. directory:
  156.         ftp://ftp.x.org/contrib/widgets/motif/
  157.  
  158. -----------------------------------------------------------------------------
  159. Subject: 121)  Can I grey out an item in a list?  I want to make insensitive
  160. items in a list so that they cannot be selected.
  161.  
  162. Answer:
  163.  
  164. W. Scott Meeks of OSF wrote:
  165.  
  166. Unfortunately, you can't do it directly since the list items aren't individual
  167. widgets.  We've had other requests for this technology, but it didn't make the
  168. cut for 1.2; it should be in some future release.
  169.  
  170. However, you can probably fake it in your application with some difficulty.
  171. First, a list item is an XmString, so you can specify a different charset for
  172. the item than for other items in the list and then specify a font in the
  173. list's fontlist that matches the charset and gives you the visual you want.
  174. The next problem is making the item unselectable.  One idea would be to have
  175. the application keep track of the insensitive items and the items currently
  176. selected.  Then you would set up a selection callback that when called would
  177. check the item selected against the list of insensitive items and if the
  178. selected item matched would deselect that item and reselect the previously
  179. selected items.  Otherwise it would just update the application's list of
  180. selected items.  The major drawback with this approach is that you'll get
  181. flashing whenever the list selects an item and your application immediately
  182. de-selects.  Unfortunately I can't think of a way around this without mucking
  183. with the list internals.
  184.  
  185. Another alternative suggested is to use instead a column of say read only text
  186. widgets which you can make insensitive.
  187.  
  188. -----------------------------------------------------------------------------
  189. Subject: 122)  Can I have multi-line items in a list?
  190. [Last modified: August 92]
  191.  
  192. Answer:  Motif 1.0 and 1.1 both have problems with multi-line items in a list.
  193. They should work okay in Motif 1.2.
  194.  
  195. -----------------------------------------------------------------------------
  196. Subject: 123)  How can I tell the position of selected items in a list?
  197.  
  198. [Last modified: Oct 92]
  199.  
  200. Answer:  W. Scott Meeks wrote:
  201.  
  202. 1) All XmList selection callbacks get an XmListCallbackStruct which includes
  203. the item selected and its position.  In addition, the multiple and extended
  204. selection callbacks also get a list of the selected items.  This approach
  205. requires that your application saves this information if you need it outside
  206. of the immediate callback.
  207.  
  208. 2) At any time you can XtGetValues the XmNselectedItems and
  209. XmNselectedItemCount resources.  The problem with this approach is that
  210. identical items may or may not show up in multiple times in this list and the
  211. position in the selectedItems list may not relate directly to the position in
  212. the items list.
  213.  
  214. 3) You can call XmListGetSelectedPos on the list widget.  This will return a
  215. list of the positions of all selected items.
  216.  
  217. -----------------------------------------------------------------------------
  218. Subject: 124)  How can I configure a scrolled list widget to show a horizontal
  219. scrollbar when some list items are wider than the window?
  220.  
  221. [Last modified: May 97]
  222.  
  223. Answer:  Set *XmList.listSizePolicy: XmCONSTANT
  224.  
  225. Ken Lee, http://www.rahul.net/kenton/
  226.  
  227. -----------------------------------------------------------------------------
  228. Subject: 125)  TOPIC: FILE SELECTION BOX WIDGET
  229.  
  230. -----------------------------------------------------------------------------
  231. Subject: 126)  What is libPW.a and do I need it?  My manual says I need to
  232. link in libPW.a to use the File Selection Box.  I can't find it on my system.
  233.  
  234. [Last modified: Sept 94]
  235.  
  236. Answer:  The libPW.a is the Programmers Workbench library which is an ATT
  237. product not included in Berkeley based systems, hence it is not found in SunOS
  238. or Ultrix, but is found on HP-UX (a Berkeley/ATT hybrid which chose ATT in
  239. this case).  It contains the regex(3) routines (regcmp, regex).  Some systems
  240. which don't have these in the libc.a need to link with -lPW.  Some systems
  241. which have the regex(3) routines in there also have the libPW.a.  If you have
  242. regex(3) in libc, and it works, don't link with libPW.  If you don't have
  243. regex(3) in libc, and you don't have a libPW, then check some sites on the net
  244. for public domain replacements (several exist), or call your vendor.
  245.  
  246. In most versions of Motif (see the doco), you can compile FileSB.c with
  247. -DNO_REGEX if you don't have it.
  248.  
  249.  
  250. Casper H.S. Dik (asper@fwi.uva.nl), Faculty of Mathematics & Computer Science,
  251. University of Amsterdam, sent this update for Solaris 2.x users:
  252.  
  253. The regex and regcmp function are part of libgen in SVR4.  Motif applications
  254. should be linked with -lgen. (However, some SVR4 implementations, especially
  255. those of vendors that once shipped SVR3 still contain libPW.)
  256.  
  257. On Solaris 2.x system, you'll need libgen which is located in /usr/ccs/lib.
  258.  
  259. -----------------------------------------------------------------------------
  260. Subject: 127)  What are these compile errors: Undefined symbol _regcmp and
  261. _regex?
  262.  
  263. [Last modified: Sept 94]
  264.  
  265. Answer:  You need to link in the libPW or libgen library - see previous
  266. question.
  267.  
  268.  
  269. -----------------------------------------------------------------------------
  270. Subject: 128)  What's wrong with the Motif 1.0 File Selection Box?  I can't
  271. set the directory, change the directory or get the file mask to work.
  272.  
  273. Answer:  The 1.0 File Selection Box is broken, and these don't work.  They
  274. weren't fixed until Motif 1.04.  Use these later versions of 1.0 or switch to
  275. Motif 1.1 where it changed a lot.
  276.  
  277. Joe Hildebrand has a work-around for some of this: Before popping up an
  278. XmFileSelectionDialog, change to the directory you want.  When a file is
  279. selected, check if it is a directory, so that we can change to it.  i.e.
  280.  
  281. static void show_file_box_CB(w, client_data, call_data)
  282.    Widget               w;
  283.    Widget               client_data;
  284.    XmAnyCallbackStruct  *call_data;
  285. {
  286.    chdir("/users/hildjj/files");
  287.    XtManageChild(client_data);
  288. }
  289.  
  290. static void val_save(w, client_data, call_data)
  291.    Widget       w;
  292.    Widget       client_data;
  293.    XmSelectionBoxCallbackStruct *call_data;
  294. {
  295.    struct stat buf;  /* struct stat is defined in stat.h */
  296.    char *filename;
  297.  
  298.    /* get the file name from the FileSelectionBox */
  299.    filename = SmX(call_data->value);
  300.  
  301.    /* get the status of the file named filename, and put it into buf */
  302.    if (!stat(filename, &buf))
  303.    {
  304.       /* if it's a directory */
  305.       /* if it's a directory */
  306.       if(S_ISDIR(buf.st_mode))
  307.       {
  308.          /* change to that directory, and update the FileSelectionBox */
  309.         chdir(filename);
  310.         XmFileSelectionDoSearch(w, NULL);
  311.       }
  312.       else
  313.          /* if it's a regular file */
  314.          if(S_ISREG(buf.st_mode))
  315.             /* ask if it should be overwritten */
  316.             XtManageChild(valbox);
  317.          else
  318.             /* it's another kind of file.  What type, i can't think of,
  319.                but it might happen */
  320.             pop_up_error_box(client_data, "Error saving file");
  321.    }
  322.    else  /* we couldn't get the file status */
  323.    {
  324.       /* if it's because the file doesn't exist, we're golden */
  325.       if (errno == ENOENT)
  326.          save_file();
  327.       else   /* there is some other problem getting the status.
  328.                 e.g. bad path */
  329.          pop_up_error_box(client_data, "Error saving file");
  330.    }
  331. }
  332.  
  333. this still doesn't implement the file masking stuff.
  334.  
  335.  
  336. -----------------------------------------------------------------------------
  337. Subject: 129)  How can I keep my file selection boxes from resizing when I
  338. change directories or filters?
  339.  
  340. [Last modified: May 97]
  341.  
  342. Answer:  Set XmNresizePolicy (XmFileSelectionDialog is a subclass of
  343. XmBulletinBoard) to XmRESIZE_NONE.
  344.  
  345.  
  346. -----------------------------------------------------------------------------
  347. Subject: 130)  What's wrong with the FileSelectionBox under Solaris?
  348.  
  349. [Last modified: May 97]
  350.  
  351. Answer:  Jim Guyton (guyton@burton.cs.colorado.edu) writes:
  352.  
  353. While not strictly a Motif problem, this one had me confused for [awhile].
  354.  
  355. If under Solaris the entries in a FileSelectionBox look strange and seem to be
  356. missing the first two characters of many filenames, then be sure you're
  357. linking -lc before -lucb.
  358.  
  359. If on the other hand, the filenames look strange and seem to have two garbage
  360. characters in front of every filename, be sure to link -lucb before -lc.
  361.  
  362. There are two versions of readdir().  The one in -lucb returns a structure
  363. that has the filename at an offset of 8 bytes (which matches
  364. /usr/ucbinclude/sys/dir.h).
  365.  
  366. But the version in -lc returns the filename at an offset of 10 bytes (which
  367. matches /usr/include/dirent.h).
  368.  
  369. So depending on how Motif was built for your Solaris, vs. how you link your
  370. application, your filenames could be two bytes off in either direction.
  371.  
  372.  
  373. Harry Cohen (hbcohen@bell.tds-eagan.lmco.com) writes:  I also had this problem
  374. (the missing horizontal scroll bar with Solaris 2.5.1 and 2.4) and have talked
  375. with Sun. This is a problem with the Sun Motif library in /usr/dt/lib.
  376.  
  377. You need to install the following Sun patches to correct this problem:  For
  378. Solaris 2.5.1: patch 103461-03 For Solaris 2.4:   patch 102226-19
  379.  
  380. Note: For Solaris 2.4, the horizontal scroll problem existed in a previous
  381. patch release, so most people haven't seen it.
  382.  
  383.  
  384. Scott W. Sadler (sws@iti-oh.com) writes:  We had this same problem, and it
  385. took a while to figure it out.  If you use the Motif libraries out of
  386. /usr/dt/lib, the file selection box gives the problem you indicate.  However,
  387. if you use the Motif libraries out of /opt/SUNWspro/Motif_Solaris24/dt/lib,
  388. all is fine.
  389.  
  390. Make sure your LD_LIBRARY_PATH, is set correctly to pick up the right shared
  391. libraries at run time.  Also check out the "-R" option to the linker to encode
  392. the library search paths.  Finally use the "ldd" program to make sure that you
  393. are picking up the correct libraries.
  394.  
  395.  
  396. -----------------------------------------------------------------------------
  397. Subject: 131)  TOPIC: FORM WIDGET
  398.  
  399.  
  400. -----------------------------------------------------------------------------
  401. Subject: 132)  Why don't labels in a Form resize when the label is changed?
  402. I've got some labels in a form. The labels don't resize whenever the label
  403. string resource is changed. As a result, the operator has to resize the window
  404. to see the new label contents. I am using Motif 1.1.
  405.  
  406. Answer:  This problem may happen to any widget inside a Form widget. The
  407. problem was that the Form will resize itself when it gets geometry requests
  408. from its children. If its preferred size is not allowed, the Form will
  409. disallow all geometry requests from its children. The workaround is that you
  410. should set any ancestor of the Form to be resizable. For the shell which
  411. contains the Form you should set the shell resource XmNallowShellResize to be
  412. True (by default, it is set to FALSE).  There is currently an inconsistency on
  413. how resizing is being done, and it may get fixed in Motif 1.2.
  414.  
  415. db@sunbim.be (Danny Backx) wrote:
  416.  
  417. Basically what you have to do is set the XmNresizePolicy on the Form to
  418. XmRESIZE_NONE.  The facts seem to be that XmRESIZE_NONE does NOT mean "do not
  419. allow resizes".  You may also have to set XmNresizable on the form to True.
  420.  
  421. -----------------------------------------------------------------------------
  422. Subject: 133)  How can I center a widget in a form?
  423.  
  424. [Last modified: Nov 96]
  425.  
  426. Answer:  One of Motif's trickier questions.  The problems are that: Form gives
  427. no support for centering, only for edge attachments, and the widget must stay
  428. in the center if the form or the widget is resized.  Just looking at
  429. horizontal centering (vertical is similar) some solutions are:
  430.  
  431.  a.  Use the table widget instead of Form.  A hack free solution is from Dan
  432.      Heller:
  433.  
  434.      /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  435.       * This program is freely distributable without licensing fees and
  436.       * is provided without guarantee or warranty expressed or implied.
  437.       * This program is -not- in the public domain.  This program is
  438.       * taken from the Motif Programming Manual, O'Reilly Volume 6.
  439.       */
  440.  
  441.      /* corners.c -- demonstrate widget layout management for a
  442.       * BulletinBoard widget.  There are four widgets each labeled
  443.       * top-left, top-right, bottom-left and bottom-right.  Their
  444.       * positions in the bulletin board correspond to their names.
  445.       * Only when the widget is resized does the geometry management
  446.       * kick in and position the children in their correct locations.
  447.       */
  448.      #include <Xm/BulletinB.h>
  449.      #include <Xm/PushBG.h>
  450.  
  451.      char *corners[] = {
  452.          "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right",
  453.      };
  454.  
  455.      static void resize();
  456.  
  457.      main(argc, argv)
  458.      int argc;
  459.      char *argv[];
  460.      {
  461.          Widget toplevel, bboard;
  462.          XtAppContext app;
  463.          XtActionsRec rec;
  464.          int i;
  465.  
  466.          /* Initialize toolkit and create toplevel shell */
  467.          toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
  468.              &argc, argv, NULL, NULL);
  469.  
  470.          /* Create your standard BulletinBoard widget */
  471.          bboard = XtVaCreateManagedWidget("bboard",
  472.              xmBulletinBoardWidgetClass, toplevel, NULL);
  473.  
  474.          /* Set up a translation table that captures "Resize" events
  475.           * (also called ConfigureNotify or Configure events).  If the
  476.           * event is generated, call the function resize().
  477.           */
  478.          rec.string = "resize";
  479.          rec.proc = resize;
  480.          XtAppAddActions(app, &rec, 1);
  481.  
  482.       /******** WARNING! Next statement is questionable in 1996. See
  483.        ******** "Can you reuse the return value from XtParseTranslationTable?"
  484.        ******** If someone corrects this code, send it to ksall@cen.com.
  485.        ********/
  486.  
  487.          XtOverrideTranslations(bboard,
  488.              XtParseTranslationTable("<Configure>: resize()"));
  489.  
  490.          /* Create children of the dialog -- a PushButton in each corner. */
  491.          for (i = 0; i < XtNumber(corners); i++)
  492.              XtVaCreateManagedWidget(corners[i],
  493.                  xmPushButtonGadgetClass, bboard, NULL);
  494.  
  495.          XtRealizeWidget(toplevel);
  496.          XtAppMainLoop(app);
  497.      }
  498.  
  499.      /* resize(), the routine that is automatically called by Xt upon the
  500.       * delivery of a Configure event.  This happens whenever the widget
  501.       * gets resized.
  502.       */
  503.      static void
  504.      resize(w, event, args, num_args)
  505.      CompositeWidget w;   /* The widget (BulletinBoard) that got resized */
  506.      XConfigureEvent *event;  /* The event struct associated with the event */
  507.      String args[]; /* unused */
  508.      int *num_args; /* unused */
  509.      {
  510.          WidgetList children;
  511.          int width = event->width;
  512.          int height = event->height;
  513.          Dimension w_width, w_height;
  514.          short margin_w, margin_h;
  515.  
  516.          /* get handle to BulletinBoard's children and marginal spacing */
  517.          XtVaGetValues(w,
  518.              XmNchildren, &children,
  519.              XmNmarginWidth, &margin_w,
  520.              XmNmarginHeight, &margin_h,
  521.              NULL);
  522.  
  523.          /* place the top left widget */
  524.          XtVaSetValues(children[0],
  525.              XmNx, margin_w,
  526.              XmNy, margin_h,
  527.              NULL);
  528.  
  529.          /* top right */
  530.          XtVaGetValues(children[1], XmNwidth, &w_width, NULL);
  531.  
  532.          /* To Center a widget in the middle of the BulletinBoard (or Form),
  533.           * simply call:
  534.           *   XtVaSetValues(widget,
  535.                XmNx,    (width - w_width)/2,
  536.                XmNy,    (height - w_height)/2,
  537.                NULL);
  538.           * and return.
  539.           */
  540.          XtVaSetValues(children[1],
  541.              XmNx, width - margin_w - w_width,
  542.              XmNy, margin_h,
  543.              NULL);
  544.  
  545.          /* bottom left */
  546.          XtVaGetValues(children[2], XmNheight, &w_height, NULL);
  547.          XtVaSetValues(children[2],
  548.              XmNx, margin_w,
  549.              XmNy, height - margin_h - w_height,
  550.              NULL);
  551.  
  552.          /* bottom right */
  553.          XtVaGetValues(children[3],
  554.              XmNheight, &w_height,
  555.              XmNwidth, &w_width,
  556.              NULL);
  557.          XtVaSetValues(children[3],
  558.              XmNx, width - margin_w - w_width,
  559.              XmNy, height - margin_h - w_height,
  560.              NULL);
  561.      }
  562.  
  563.  b.  No uil solution has been suggested, because of the widget size problem.
  564.  
  565.  c.  Cameron Hayne (hayne@crim.ca) suggests another solution:
  566.  
  567.      Attach the widget with XmATTACH_POSITION but offset it by half of its
  568.      width.  You will likely have to create the widget first and then query it
  569.      to find out its width. Thus the following function is useful - you can
  570.      call it immediately after the widget is created.
  571.  
  572.      void    center_it(Widget wgt)
  573.      {
  574.              Dimension       width;
  575.              XtVaGetValues(wgt, XmNwidth, &width, NULL);
  576.              XtVaSetValues(wgt, XmNleftAttachment, XmATTACH_POSITION,
  577.                              XmNleftPosition, 50,  /* assumes fractionBase is 100 */
  578.                              XmNleftOffset, -width/2, NULL);
  579.      }
  580.  
  581.      The idea is: get the size of the widget and then offset it by half that
  582.      much from position 50.  The above function will likely only work for
  583.      primitive widgets if you call it immediately after the widget is created.
  584.      For manager widgets you will likely have to wait to call the center_it()
  585.      function until after the widget has been realized since it is only then
  586.      that a manager widget's size is finally determined.  (Refer to discussion
  587.      by Daniel Dardailler "Application's Geometry Management Advanced
  588.      Guidelines" in this FAQ.)
  589.  
  590. -----------------------------------------------------------------------------
  591. Subject: 134)  How do I line up two columns of widgets of different types?  I
  592. have a column of say label widgets, and a column of text widgets and I want to
  593. have them lined up horizontally. The problem is that they are of different
  594. heights. Just putting them in a form or rowcolumn doesn't line them up
  595. properly because the label and text widgets are of different height.
  596.  
  597. If you want the geometry to look like this
  598.  
  599.           -------------------------------------
  600.          |          -------------------------- |
  601.          |a label  |Some text                 ||
  602.          |          -------------------------- |
  603.                            ------------------- |
  604.          |a longer label  |Some more text     ||
  605.          |                 ------------------- |
  606.          |                    ---------------- |
  607.          |a very long label  |Even more text  ||
  608.          |                    ---------------- |
  609.           -------------------------------------
  610.  
  611. try
  612.  
  613. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  614.  * This program is freely distributable without licensing fees and
  615.  * is provided without guarantee or warranty expressed or implied.
  616.  * This program is -not- in the public domain.  This program is
  617.  * taken from the Motif Programming Manual, O'Reilly Volume 6.
  618.  */
  619.  
  620. /* text_form.c -- demonstrate how attachments work in Form widgets.
  621.  * by creating a text-entry form type application.
  622.  */
  623.  
  624. #include <Xm/PushB.h>
  625. #include <Xm/PushBG.h>
  626. #include <Xm/LabelG.h>
  627. #include <Xm/Text.h>
  628. #include <Xm/Form.h>
  629.  
  630. char *prompts[] = {
  631.     "Name:", "Phone:", "Address:",
  632.     "City:", "State:", "Zip:",
  633. };
  634.  
  635. main(argc, argv)
  636. int argc;
  637. char *argv[];
  638. {
  639.     Widget toplevel, mainform, subform, label, text;
  640.     XtAppContext app;
  641.     char buf[32];
  642.     int i;
  643.  
  644.     toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
  645.         &argc, argv, NULL, NULL);
  646.  
  647.     mainform = XtVaCreateWidget("mainform",
  648.         xmFormWidgetClass, toplevel,
  649.         NULL);
  650.  
  651.     for (i = 0; i < XtNumber(prompts); i++) {
  652.         subform = XtVaCreateWidget("subform",
  653.             xmFormWidgetClass,   mainform,
  654.             /* first one should be attached for form */
  655.             XmNtopAttachment,    i? XmATTACH_WIDGET : XmATTACH_FORM,
  656.             /* others are attached to the previous subform */
  657.             XmNtopWidget,        subform,
  658.             XmNleftAttachment,   XmATTACH_FORM,
  659.             XmNrightAttachment,  XmATTACH_FORM,
  660.             NULL);
  661.         label = XtVaCreateManagedWidget(prompts[i],
  662.             xmLabelGadgetClass,  subform,
  663.             XmNtopAttachment,    XmATTACH_FORM,
  664.             XmNbottomAttachment, XmATTACH_FORM,
  665.             XmNleftAttachment,   XmATTACH_FORM,
  666.             XmNalignment,        XmALIGNMENT_BEGINNING,
  667.             NULL);
  668.         sprintf(buf, "text_%d", i);
  669.         text = XtVaCreateManagedWidget(buf,
  670.             xmTextWidgetClass,   subform,
  671.             XmNtopAttachment,    XmATTACH_FORM,
  672.             XmNbottomAttachment, XmATTACH_FORM,
  673.             XmNrightAttachment,  XmATTACH_FORM,
  674.             XmNleftAttachment,   XmATTACH_WIDGET,
  675.             XmNleftWidget,       label,
  676.             NULL);
  677.         XtManageChild(subform);
  678.     }
  679.     /* Now that all the forms are added, manage the main form */
  680.     XtManageChild(mainform);
  681.  
  682.     XtRealizeWidget(toplevel);
  683.     XtAppMainLoop(app);
  684. }
  685.  
  686. If you resize horizontally it stretches the text widgets.  If you resize
  687. vertically it leaves space under the bottom (if you don't resize, this is not
  688. problem).
  689.  
  690. If you want the text widgets to be lined up on the left, as in
  691.  
  692.           ----------------------------------------
  693.          |                    ------------------- |
  694.          |          a label  |Some text          ||
  695.          |                    ------------------- |
  696.                               ------------------- |
  697.          |   a longer label  |Some more text     ||
  698.          |                    ------------------- |
  699.          |                    ------------------- |
  700.          |a very long label  |Even more text     ||
  701.          |                    ------------------- |
  702.           ----------------------------------------
  703.  
  704. try this
  705.  
  706. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  707.  * This program is freely distributable without licensing fees and
  708.  * is provided without guarantee or warranty expressed or implied.
  709.  * This program is -not- in the public domain.  This program is
  710.  * taken from the Motif Programming Manual, O'Reilly Volume 6.
  711.  */
  712.  
  713. /* text_entry.c -- This demo shows how the RowColumn widget can be
  714.  * configured to build a text entry form.  It displays a table of
  715.  * right-justified Labels and Text widgets that extend to the right
  716.  * edge of the Form.
  717.  */
  718. #include <Xm/LabelG.h>
  719. #include <Xm/RowColumn.h>
  720. #include <Xm/Text.h>
  721.  
  722. char *text_labels[] = {
  723.     "Name:", "Phone:", "Address:", "City:", "State:", "Zip:",
  724. };
  725.  
  726. main(argc, argv)
  727. int argc;
  728. char *argv[];
  729. {
  730.     Widget toplevel, rowcol;
  731.     XtAppContext app;
  732.     char buf[8];
  733.     int i;
  734.  
  735.     toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
  736.         &argc, argv, NULL, NULL);
  737.  
  738.     rowcol = XtVaCreateWidget("rowcolumn",
  739.         xmRowColumnWidgetClass, toplevel,
  740.         XmNpacking,        XmPACK_COLUMN,
  741.         XmNnumColumns,     XtNumber(text_labels),
  742.         XmNorientation,    XmHORIZONTAL,
  743.         XmNisAligned,      True,
  744.         XmNentryAlignment, XmALIGNMENT_END,
  745.         NULL);
  746.  
  747.     /* simply loop thru the strings creating a widget for each one */
  748.     for (i = 0; i < XtNumber(text_labels); i++) {
  749.         XtVaCreateManagedWidget(text_labels[i],
  750.             xmLabelGadgetClass, rowcol,
  751.             NULL);
  752.         sprintf(buf, "text_%d", i);
  753.         XtVaCreateManagedWidget(buf,
  754.             xmTextWidgetClass, rowcol,
  755.             NULL);
  756.     }
  757.  
  758.     XtManageChild(rowcol);
  759.     XtRealizeWidget(toplevel);
  760.     XtAppMainLoop(app);
  761. }
  762.  
  763. This makes all objects exactly the same size.  It does not resize in nice
  764. ways.
  765.  
  766. If you want the text widgets lined up on the left, and the labels to be the
  767. size of the longest string, resizing nicely both horizontally and vertically,
  768. as in
  769.  
  770.  
  771.          -------------------------------------
  772.         |                    ---------------- |
  773.         |          a label  |Some text       ||
  774.         |                    ---------------- |
  775.                              ---------------- |
  776.         |   a longer label  |Some more text  ||
  777.         |                    ---------------- |
  778.         |                    ---------------- |
  779.         |a very long label  |Even more text  ||
  780.         |                    ---------------- |
  781.          -------------------------------------
  782.  
  783.  
  784. Answer:  Do this:  to get the widgets lined up horizontally, use a form but
  785. place the widgets using XmATTACH_POSITION.  In the example, attach the top of
  786. the first label to the form, the bottomPosition to 33 (33% of the height).
  787. Attach the topPosition of the second label to 33 and the bottomPosition to 66.
  788. Attach the topPosition of the third label to 66 and the bottom of the label to
  789. the form.  Do the same with the text widgets.
  790.  
  791. To get the label widgets lined up vertically, use the right attachment of
  792. XmATTACH_OPPOSITE_WIDGET: starting from the one with the longest label, attach
  793. widgets on the right to each other. In the example, attach the 2nd label to
  794. the third, and the first to the second.  To get the text widgets lined up,
  795. just attach them on the left to the labels.  To get the text in the labels
  796. aligned correctly, use XmALIGNMENT_END for the XmNalignment resource.
  797.  
  798.         /* geometry for label 2
  799.         */
  800.         n = 0;
  801.         XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  802.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  803.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  804.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  805.         XtSetArg (args[n], XmNtopPosition, 66); n++;
  806.         XtSetValues (label[2], args, n);
  807.  
  808.         /* geometry for label 1
  809.         */
  810.         n = 0;
  811.         XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  812.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  813.         XtSetArg (args[n], XmNbottomPosition, 66); n++;
  814.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  815.         XtSetArg (args[n], XmNtopPosition, 33); n++;
  816.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  817.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  818.         XtSetArg (args[n], XmNrightWidget, label[2]); n++;
  819.         XtSetValues (label[1], args, n);
  820.  
  821.         /* geometry for label 0
  822.         */
  823.         n = 0;
  824.         XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  825.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  826.         XtSetArg (args[n], XmNbottomPosition, 33); n++;
  827.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  828.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  829.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  830.         XtSetArg (args[n], XmNrightWidget, label[1]); n++;
  831.         XtSetValues (label[0], args, n);
  832.  
  833.         /* geometry for text 0
  834.         */
  835.         n = 0;
  836.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  837.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  838.         XtSetArg (args[n], XmNbottomPosition, 33); n++;
  839.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  840.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  841.         XtSetArg (args[n], XmNleftWidget, label[0]); n++;
  842.         XtSetValues (text[0], args, n);
  843.  
  844.         /* geometry for text 1
  845.         */
  846.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  847.         XtSetArg (args[n], XmNtopPosition, 33); n++;
  848.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  849.         XtSetArg (args[n], XmNbottomPosition, 66); n++;
  850.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  851.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  852.         XtSetArg (args[n], XmNleftWidget, label[1]); n++;
  853.         XtSetValues (text[1], args, n);
  854.  
  855.         /* geometry for text 2
  856.         */
  857.         XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  858.         XtSetArg (args[n], XmNtopPosition, 66); n++;
  859.         XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  860.         XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  861.         XtSetArg (args[n], XmNleftWidget, label[2]); n++;
  862.         XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  863.         XtSetValues (text[2], args, n);
  864.  
  865. -----------------------------------------------------------------------------
  866. Subject: 135)  TOPIC: PUSHBUTTON WIDGET
  867.  
  868. -----------------------------------------------------------------------------
  869. Subject: 136)  Why can't I use accelerators on buttons not in a menu?
  870.  
  871. [Last modified: Sept 94]
  872.  
  873. Answer:
  874.  
  875. It is apparently a difficult feature to implement, but OSF are considering
  876. this for the future. It is problematic trying to use the Xt accelerators since
  877. the Motif method interferes with this.  one workaround suggested is to
  878. duplicate your non-menu button by a button in a menu somewhere, which does
  879. have a menu-accelerator installed.  When the user invokes what they think is
  880. the accelerator for the button they can see Motif actually invokes the button
  881. on the menu that they can't see at the time. Another method is described below
  882. and was contributed by Harald Albrecht of Institute of Geometry and Practical
  883. Mathematics Rhine Westphalia Technical University Aachen (RWTH Aachen),
  884. Germany
  885.  
  886.  
  887. albrecht@igpm.rwth-aachen.de wrote (Jul 8, 1993):
  888.  
  889. NOTE: Pointers to a more recent solution by the same author follow this code
  890. sample.
  891.  
  892. My work-around of this problem looks like this: (I've written that code for a
  893. Motif Object Library in C++ so please forgive me for being object orientated!)
  894. The hack consists of a rewritten message loop which checks for keypresses
  895. <MAlt>+<key>. If MessageLoop() finds such a keypress HandleAcc() ist called
  896. and the widget tree is searched for a suitable widget with the right mnemonic.
  897.  
  898.  
  899. // --------------------------------------------------------------------------
  900. // traverse the widget tree starting with the given widget.
  901. //
  902. BOOL TraverseWidgetTree(Widget w, char *pMnemonic, XKeyEvent *KeyEvent)
  903. {
  904.     Widget               wChild;
  905.     WidgetList           ChildList;
  906.     int                  NumChilds, Child;
  907.     KeySym               LabelMnemonic;
  908.     char                 *pMnemonicString;
  909.  
  910. // Check if the widget is a subclass of label -- then it may have an
  911. // accelerator attached...
  912.     if ( XtIsSubclass(w, xmLabelWidgetClass) ) {
  913. // ok. Now: get the widget's mnemonic, convert it to ASCII and compare
  914. // it with the Key we're looking for.
  915.         XtVaGetValues(w, XmNmnemonic, &LabelMnemonic, NULL);
  916.         pMnemonicString = XKeysymToString(LabelMnemonic);
  917.         if ( pMnemonicString &&
  918.              (strcasecmp(pMnemonicString, pMnemonic) == 0) ) {
  919.             // stimulate the keypress
  920.             XmProcessTraversal((Widget)w, XmTRAVERSE_CURRENT);
  921.             KeyEvent->type      = KeyPress;
  922.             KeyEvent->window    = XtWindow(w);
  923.             KeyEvent->subwindow = XtWindow(w);
  924.             KeyEvent->state     = 0;
  925.             KeyEvent->keycode   =
  926.                 XKeysymToKeycode(XtDisplay(w), XK_space);
  927.             XSendEvent(XtDisplay(w), XtWindow(w),
  928.                        True,
  929.                        ButtonPressMask, (XEvent*) KeyEvent);
  930.             KeyEvent->type      = KeyRelease;
  931.             XSendEvent(XtDisplay(w), XtWindow(w),
  932.                        True,
  933.                        ButtonReleaseMask, (XEvent*) KeyEvent);
  934.             return True;
  935.         }
  936.     }
  937. // if this widget is a subclass of Composite check all the widget's
  938. // childs.
  939.     if ( XtIsSubclass(w, compositeWidgetClass) ) {
  940. // if we're in a menu (or something like that) forget this leaf of the
  941. // widget tree!
  942.         if ( XtIsSubclass(w, xmRowColumnWidgetClass) ) {
  943.             unsigned char RowColumnType;
  944.             XtVaGetValues(w, XmNrowColumnType, &RowColumnType, NULL);
  945.             if ( RowColumnType != XmWORK_AREA ) return False;
  946.         }
  947.         XtVaGetValues(w, XmNchildren, &ChildList,
  948.                          XmNnumChildren, &NumChilds, NULL);
  949.         for ( Child = 0; Child < NumChilds; ++Child ) {
  950.             wChild = ChildList[Child];
  951.             if ( TraverseWidgetTree(wChild, pMnemonic, KeyEvent) )
  952.                 return True;
  953.         }
  954.     }
  955.     return False;
  956. } // TraverseWidgetTree
  957. // --------------------------------------------------------------------------
  958. // handle accelerators (keypress MAlt + key)
  959. //
  960. #define MAX_MAPPING 10
  961. BOOL HandleAcc(Widget w, XEvent *event)
  962. {
  963.            Widget         widget, OldWidget;
  964.     static char           keybuffer[MAX_MAPPING];
  965.            int            CharCount;
  966.     static XComposeStatus composeStatus;
  967.  
  968. // convert KeyPress to ASCII
  969.     CharCount = XLookupString((XKeyEvent*) event,
  970.                               keybuffer, sizeof(keybuffer),
  971.                               NULL, &composeStatus);
  972.     keybuffer[CharCount] = 0;
  973. // Only one char is alright -- then search the widget tree for a widget
  974. // with the right mnemonic
  975.     if ( CharCount == 1 ) {
  976.         keybuffer[0] = tolower(keybuffer[0]);
  977.         widget = w;
  978.         while ( (widget != NULL) &&
  979.                 !XtIsSubclass(widget, shellWidgetClass) ) {
  980.             OldWidget = widget; widget = XtParent(widget);
  981.         }
  982.         if ( !widget ) widget = OldWidget;
  983.         return TraverseWidgetTree(widget,
  984.                                   keybuffer, (XKeyEvent*) event);
  985.     }
  986.     return False; // no-one found.
  987. } // HandleAcc
  988. // --------------------------------------------------------------------------
  989. // modified message loop
  990. // loops until the Boolean pFlag points to is set to False
  991. void MessageLoop(Boolean *pFlag)
  992. {
  993.     XEvent nextEvent;
  994.  
  995.     while ( *pFlag ) {
  996.         if ( XtAppPending(AppContext) ) {
  997.             XtAppNextEvent(AppContext, &nextEvent);
  998.             if ( nextEvent.type == KeyPress ) {
  999. // Falls es ein Tastendruck ist, bei dem auch noch die ALT-Taste
  1000. // (=Modifier 1) gedrueckt ist, koennte es ein Accelerator sein!
  1001.                 if ( nextEvent.xkey.state & Mod1Mask )
  1002.                     if ( HandleAcc(XtWindowToWidget(nextEvent.xkey.display,
  1003.                                                     nextEvent.xkey.window),
  1004.                                    &nextEvent) )
  1005.                         continue; // Mitteilung konnte ausgeliefert werden
  1006.                                   // und darf daher nicht den ueblichen
  1007.                                   // Weg gehen!
  1008.             }
  1009.             XtDispatchEvent(&nextEvent);
  1010.         }
  1011.     }
  1012. } // TApplication::MessageLoop
  1013.  
  1014.  
  1015. Harald Albrecht albrecht@igpm.rwth-aachen.de Institute of Geometry and
  1016. Practical Mathematics Rhine Westphalia Technical University Aachen (RWTH
  1017. Aachen), Germany
  1018.  
  1019. NOTE: Harald Albrecht has re-designed his solution so that you can assign
  1020. hotkeys to *every* widget by placing a label near that widget. Get the code
  1021. from:
  1022.  
  1023.   ftp.informatik.rwth-aachen.de (137.226.112.172)
  1024.   in: /pub/packages/Mnemonic/Mnemonic.tar.gz
  1025.  
  1026. or from the WWW:
  1027.  
  1028.    file://134.130.161.30/arc/pub/unix/html/motifcorner.html
  1029.  
  1030. -----------------------------------------------------------------------------
  1031. Subject: 137)  TOPIC: TOGGLEBUTTON WIDGET
  1032.  
  1033. -----------------------------------------------------------------------------
  1034. Subject: 138)  What widgets give the look of push buttons, but behavior of
  1035. toggle buttons?
  1036.  
  1037. Answer:  Use the XmToggleButton widget, setting XmNindicatorOn to False and
  1038. XmNshadowThickness to 2.
  1039.  
  1040. Ken Lee, http://www.rahul.net/kenton/
  1041.  
  1042. Also set XmNfillOnSelect to True. Otherwise, the background color of the
  1043. button will not stay in the "armed" state.
  1044.  
  1045. thanks to Glenn McMillen, mcmillen@meadow.mdso.vf.ge.com
  1046.  
  1047. In Motif 1.2 (and later), if you specify a XmNselectColor and set
  1048. XmNindicatorOn to False, then you need to set XmNfillOnSelect to True.
  1049. XmNfillOnSelect is not necessary if you are not setting a XmNselectColor.
  1050.  
  1051. Ken Lee, http://www.rahul.net/kenton/
  1052.  
  1053.  
  1054. -----------------------------------------------------------------------------
  1055. Subject: 139)  Can I customize XmToggleButton to use my own indicator graphic
  1056. (e.g., a check mark)?
  1057.  
  1058. [Last modified: Nov 96]
  1059.  
  1060. Answer:  There is no direct resource for the graphic.  One way to work around
  1061. this is to disable the indicator (XmNindicatorOn False) and then install
  1062. selected/unselected pixmaps containing both your graphic and your text
  1063. (XmNselectPixmap and XmNselectPixmap).  Also disable the button shadows
  1064. (XmNshadowThickness 0) if you don't want those.
  1065.  
  1066. Ken Lee, http://www.rahul.net/kenton/
  1067.  
  1068. -----------------------------------------------------------------------------
  1069. Subject: 140)  TOPIC: ICON WIDGET and PIXMAPS
  1070.  
  1071. -----------------------------------------------------------------------------
  1072. Subject: 141)  How can I add multi-colored icons to my application?
  1073.  
  1074. [Last modified: Sept 94]
  1075.  
  1076. Answer:  Get the Xpm (X PixMap file format) widgets.  There is a tutorial in
  1077. the directory ftp.x.org:/contrib/docs/xpm_tut and source code in the directory
  1078. ftp.x.org:/contrib/libraries.  Documentation is part of the tar file found in
  1079. /contrib/libraries.  The /contrib/libraries directory also contains xpm.FAQ.
  1080.  
  1081. There is also a mailing list: xpm-talk@sophia.inria.fr.
  1082.  
  1083. -----------------------------------------------------------------------------
  1084. Subject: 142)  Can I use XmGetPixmap in Motif 1.2 to create colored images?
  1085.  
  1086. [Last modified: Oct 95]
  1087.  
  1088. Answer:  Doug Rand (drand@sgi.com) writes:
  1089.  
  1090. XmGetPixmap only converts XBM [X bitmap] files in 1.2.  In 2.0 it supports XPM
  1091. [X Pixmap] files.  You can register a more capable converter and set the
  1092. pixmap via resources as a workaround.  You can also use libXpm
  1093. directly...[Note that] even now there isn't a "standard" color pixmap file
  1094. format.  There are several.  It is relatively recently that many people have
  1095. settled on XPM.  But even so not everyone has done this.
  1096.  
  1097. -----------------------------------------------------------------------------
  1098. Subject: 143)  Why does XpmCreatePixmapFromData fail with a pixmap containing
  1099. a large number of colors?  XpmCreatePixmapFromData gives me a -4 errno (which
  1100. is XpmColorFailed) when I try using a pixmap with 242 colors
  1101.  
  1102. [Last modified: Oct 95]
  1103.  
  1104. Answer:  Ramiro Estrugo (restrugo@fateware.com) writes:
  1105.  
  1106.   If you are allocating 242 colors in an 8 bit display, then you are likely to
  1107. run out of colors.  If you carefully read the Xpm manual, you will notice that
  1108. one of the Xpm values that you can modify is the "closeness".  This value will
  1109. control the actual closness of the colors allocated by the Xpm library.
  1110. According to the Xpm manual:
  1111.  
  1112.   o The "closeness" field(s) (when set) control if and how colors
  1113.     are found when they failed to be allocated.  If the color cannot
  1114.     be allocated, Xpm looks in the colormap for a color that matches
  1115.     the desired closeness.
  1116.  
  1117.   o The value is an integer in the range 0 (black) - 65535 (white)
  1118.  
  1119.   o A closeness of less than 10000 will cause only "close" colors to
  1120.     match.
  1121.  
  1122.   o A cliseness of more than 50000 will allow quite disimilar colors
  1123.     to match.
  1124.  
  1125.   o A closeness of more than 65535 will allow any color to match.
  1126.  
  1127.   o A value of 40000 seems reasonable for many situations requiring
  1128.     reasonable but not perfect color matches.
  1129.  
  1130. Try it and your application is less likely to die or look "ugly" due to the
  1131. lack of colors.  The worst that can happed is that the colors you get are not
  1132. 100% what you wanted them to be.  Most of the time, you might not even notice
  1133. the difference.  This is usually due to badly designed icons or duplicate
  1134. color entries (close rgb values) in .xpm files.
  1135.  
  1136. NOTE: for even more control over Xpm color allocation, you can control the
  1137. closeness of each RGB color component individually.
  1138.  
  1139. For example:
  1140.  
  1141. XpmAttributes   attrib;
  1142. int             valuemask;
  1143. attrib.valuemask |= XpmCloseness;
  1144. attrib.closeness = 40000;
  1145.  
  1146. /* also */
  1147.  
  1148. attrib.valuemask |= XpmRGBCloseness;
  1149. attrib.red_closeness = RED_CLOSENESS;
  1150. attrib.green_closeness = GREEN_CLOSENESS;
  1151. attrib.blue_closeness = BLUE_CLOSENESS;
  1152. pix = XpmCreateXYZFromABC(...,&attrib);
  1153.  
  1154. Also, look in the Xpm documentation for more color control parameters.
  1155.  
  1156. -----------------------------------------------------------------------------
  1157. Subject: 144)  How can I convert a Sun/GIF/TIFF image to a pixmap?
  1158.  
  1159. [Last modified: Oct 94]
  1160.  
  1161. Answer:  An application called "xv" (interactive image display for the X
  1162. Window System) is useful for displaying and converting many image formats.
  1163. From the man page:
  1164.  
  1165.      xv is an X11 program that displays images in the GIF,  JPEG,
  1166.      TIFF,  PBM, PGM, PPM, X11 bitmap, PDS/VICAR, Sun Rasterfile,
  1167.      and PM formats on 1-, 2-, 4-, 6-, 8-, 16-, 24-, and 32-bit X
  1168.      displays.   xv  will also read compress-ed versions of these
  1169.      files.
  1170.  
  1171. You can get "xv" (shareware by John Bradley et al) from:
  1172.  
  1173.         ftp://ftp.cis.upenn.edu/pub/xv
  1174. or:
  1175.         ftp://ftp.x.org/R5contrib/xv-3.01.tar.gz
  1176.  
  1177. Another useful conversion package is "pbm" (portable bitmap file format) by
  1178. Jef Poskanzer et al, available from:
  1179.  
  1180.         ftp://ftp.x.org/R5contrib/netpbm-1mar1994.tar.gz
  1181. or:
  1182.         ftp://ftp.x.org/R5contrib/pbmplus10dec91.tar.Z (much older :-)
  1183.  
  1184. You might also want to check the X11 FAQ for additional conversion options:
  1185.  
  1186.         ftp://ftp.x.org/contrib/faqs/FAQ
  1187.  
  1188. -----------------------------------------------------------------------------
  1189. Subject: 145)  How can I use Motif's pre-defined pixmaps?
  1190.  
  1191. [Last modified: May 97]
  1192.  
  1193. Answer:  Motif 1.2 loads the following into its image cache:  background,
  1194. 25_foreground, 50_foreground, 75_foreground, horizontal, vertical,
  1195. slant_right, and slant_left.  These are defined in "man XmInstallImage".  You
  1196. can retrieve them with XmGetPixmap or XmGetPixmapByDepth.
  1197.  
  1198. Ken Lee, http://www.rahul.net/kenton/
  1199.  
  1200. -----------------------------------------------------------------------------
  1201. Subject: 146)  TOPIC: SCALE AND SCROLLBAR WIDGET
  1202.  
  1203. -----------------------------------------------------------------------------
  1204. Subject: 147)*  Can the XmScale widget have arrows or tick marks in Motif 2.0?
  1205.  
  1206. [Last modified: Sep 97]
  1207.  
  1208. Answer:  Daniel Dardailler (danield@w3.org) writes:
  1209.  
  1210. In 2.0 and 2.1, Scale gets arrows (on both sides or same side), thermometer
  1211. look, thumb slider option, tick marks, and editable resource.
  1212.  
  1213. -----------------------------------------------------------------------------
  1214. Subject: 148)  How can I set the color of a XmScale widget's trough?
  1215.  
  1216. [Last modified: May 95]
  1217.  
  1218. Answer:  Ken Lee, http://www.rahul.net/kenton/, wrote: There is no direct API
  1219. for setting this, but you can set it through resource files with
  1220. "*XmScale*troughColor: red".
  1221.  
  1222. Ken Sall, ksall@cen.com, adds:  If you need to do this at runtime, you can use
  1223. XtGetValues to get the scale's children, find the scrollbar, and set the
  1224. XmNtroughColor:
  1225.  
  1226. #include <Xm/ScrollBar.h>  // for XmIsScrollBar
  1227.  
  1228.         Pixel selectColor; // assume this is set to the desired color
  1229.         WidgetList *kids;
  1230.         int nkids;
  1231.         Arg argList[1], tmpargs[2];
  1232.         int i, s, t ;
  1233.  
  1234.         i = 0;
  1235.         XtSetArg ( argList[i], XmNtroughColor, selectColor ); i++;
  1236.  
  1237.         // Unfortunately, scale does not have a direct way
  1238.         // to get its scrollbar widget, so use Composite resources
  1239.         s = 0;
  1240.         XtSetArg (tmpargs[s], XmNnumChildren, &nkids ); s++ ;
  1241.         XtSetArg (tmpargs[s], XmNchildren, &kids ); s++ ;
  1242.         XtGetValues ( widgetId, tmpargs, s );
  1243.         for ( t = 0; t < nkids; t++ )
  1244.             {
  1245.             if ( XmIsScrollBar ( (Widget) kids[t]) ) // from ScrollBar.h
  1246.                 {
  1247.                 XtSetValues ( (Widget) kids[t], argList, i );
  1248.                 }
  1249.             }
  1250.  
  1251. -----------------------------------------------------------------------------
  1252. Subject: 149)  How does Motif implement mouse button auto-repeat on the
  1253. scrollbar's arrow buttons?
  1254.  
  1255. [Last modified: May 97]
  1256.  
  1257. Answer:  It installs a timer and checks the button state at each timeout.  If
  1258. the button is still down, it repeats the action.  You can do this in your
  1259. application, too.
  1260.  
  1261. Ken Lee, http://www.rahul.net/kenton/
  1262.  
  1263. -----------------------------------------------------------------------------
  1264. Subject: 150)  TOPIC: LABEL WIDGET
  1265.  
  1266. -----------------------------------------------------------------------------
  1267. Subject: 151)  How can I align the text in a label (button, etc) widget?
  1268.  
  1269. Answer:  The alignment for the label widget is controlled by the resource
  1270. XmNalignment, and the default centers the text. Use this resource to change it
  1271. to left or right alignment.  However, when the label (or any descendant) is in
  1272. a row column, and XmNisAligned is True (the default), the row column aligns
  1273. text using its resource XmNentryAlignment. If you want simultaneous control
  1274. over all widgets use this, but otherwise turn XmNisAligned off and do it
  1275. individually.
  1276.  
  1277.  
  1278. -----------------------------------------------------------------------------
  1279. Subject: 152)  Why doesn't label alignment work in a RowColumn?
  1280.  
  1281. Answer:  RowColumn has a  resource XmNisAligned (default True) and and
  1282. XmNentryAlignment (default XmALIGNMENT_BEGINNING).  These control alignment of
  1283. the labelString in Labels and descendants. Set XmNisAligned to False to turn
  1284. this off.
  1285.  
  1286. -----------------------------------------------------------------------------
  1287. Subject: 153)  How can I set a multiline label?
  1288.  
  1289. [Last modified: Mar 96]
  1290.  
  1291. Answer:  In .Xdefaults
  1292.  
  1293.       *XmLabel*labelString:              Here\nis\nthe\nLabel
  1294.  
  1295. This method does not seem to work in some of the older Motif 1.0 versions.
  1296.  
  1297. In code,
  1298.  
  1299.       char buf[128];
  1300.       XmString msg;
  1301.       sprintf(buf, "Here\nis\nthe\nLabel");
  1302.       msg = XmStringCreateLtoR(buf, XmSTRING_DEFAULT_CHARSET);
  1303.       XtSetArg (args[n], XmNlabelString, msg);
  1304.  
  1305. Gives a four line label, using the escape sequence \n for a newline.  Here's
  1306. another approach from Jean-Philippe Martin-Flatin <syj@ecmwf.int>
  1307.  
  1308. #include <Xm/Xm.h>
  1309. #include <string.h>
  1310.  
  1311. /*-----------------------------------------------------
  1312.     Create a new XmString from a char*
  1313.  
  1314.     This function can deal with embedded 'newline' and
  1315.     is equivalent to XmStringCreateLtoR,
  1316.     except it does not use non AES compliant charset
  1317.     XmSTRING_DEFAULT_CHARSET
  1318. ----------------------------------------------------*/
  1319. XmString xec_NewString(char *s)
  1320. {
  1321.     XmString xms1;
  1322.     XmString xms2;
  1323.     XmString line;
  1324.     XmString separator;
  1325.     char     *p;
  1326.     char     *t = XtNewString(s);   /* Make a copy for strtok not to */
  1327.                                     /* damage the original string    */
  1328.  
  1329.  
  1330.     separator = XmStringSeparatorCreate();
  1331.     p         = strtok(t,"\n");
  1332.     xms1      = XmStringCreateLocalized(p);
  1333.  
  1334.     while (p = strtok(NULL,"\n"))
  1335.     {
  1336.         line = XmStringCreateLocalized(p);
  1337.         xms2 = XmStringConcat(xms1,separator);
  1338.         XmStringFree(xms1);
  1339.         xms1 = XmStringConcat(xms2,line);
  1340.         XmStringFree(xms2);
  1341.         XmStringFree(line);
  1342.     }
  1343.  
  1344.     XmStringFree(separator);
  1345.     XtFree(t);
  1346.     return xms1;
  1347. }
  1348.  
  1349.  
  1350. Do not use XmStringCreateLocalized() - it does not process the newline
  1351. character in the way you want.   In Motif 1.x, XmStringCreateLocalized() does
  1352. NOT process newlines, but XmStringCreateLtoR() does.
  1353.  
  1354. Thanks to Paul Tomblin (ptomblin@xcski.com) for the newline clarification.
  1355.  
  1356. -----------------------------------------------------------------------------
  1357. Subject: 154)  How can I have a vertical label?
  1358.  
  1359. Answer:  Make a multiline label with one character per line, as in the last
  1360. question. There is no way to make the text rotated by 90 degrees though.
  1361.  
  1362.  
  1363. -----------------------------------------------------------------------------
  1364. Subject: 155)  How can I have a Pixmap in a Label?
  1365.  
  1366. Answer:  Bob Hays (bobhays@spss.com) wrote:
  1367.  
  1368.     Pixmap px_disarm, px_disarm_insens;
  1369.  
  1370.     Widget Label1;
  1371.     Pixel   foreground, background;
  1372.     Arg     args[4];
  1373.     Arg     arg[] = {
  1374.                 { XmNforeground, &foreground },
  1375.                 { XmNbackground, &background }
  1376.     };
  1377.  
  1378.     Label1 = XmCreateLabel ( Shell1, "Label1",
  1379.                                        (Arg *) NULL, (Cardinal) 0 );
  1380.     XtGetValues ( Label1, arg, XtNumber ( arg ) );
  1381.     px_disarm =
  1382.       XCreatePixmapFromBitmapData(display,
  1383.                                 DefaultRootWindow(display),
  1384.                                 mtn_bits, mtn_width, mtn_height,
  1385.                                 foreground,
  1386.                                 background,
  1387.                                 DefaultDepth(display,DefaultScreen(display)));
  1388.     px_disarm_insens =
  1389.       XCreatePixmapFromBitmapData(display,
  1390.                                 DefaultRootWindow(display),
  1391.                                 mtn_ins_bits, mtn_ins_width, mtn_ins_height,
  1392.                                 foreground,
  1393.                                 background,
  1394.                                 DefaultDepth(display,DefaultScreen(display)));
  1395.  
  1396.     n = 0;
  1397.     XtSetArg(args[n], XmNlabelType, XmPIXMAP);  n++;
  1398.     XtSetArg(args[n], XmNlabelPixmap, px_disarm);  n++;
  1399.     XtSetArg(args[n], XmNlabelInsensitivePixmap, px_disarm_insens ); n++;
  1400.     XtSetValues ( Label1, args, n );
  1401.     XtManageChild(Label1);
  1402.  
  1403. That will cause the foreground and background of your pixmap to be inherited
  1404. from the one that would be used by OSF/Motif when the label is displayed.  The
  1405. advantage is that this will utilize any resource values the user may have
  1406. requested without looking explicitly into the resource database.  And, you
  1407. will have a pixmap handy if the application insensitizes the label (without an
  1408. XmNlabelInsensitivePixmap your label will go empty if made insensitive).
  1409.  
  1410. [Bob's original code was for a PushButton. Just change all Label to PushButton
  1411. for them.]
  1412.  
  1413. -----------------------------------------------------------------------------
  1414. Subject: 156)  Why doesn't the XmLabel widget obey the XmNwith and XmNheight
  1415. that I give it?
  1416.  
  1417. [Last modified: May 95]
  1418.  
  1419. Answer:  By default, XmLabel ignores these resources and instead computes a
  1420. size based on the size of the label string or pixmap.  You can change this
  1421. behavior by setting XmNrecomputeSize to False.  (Note that setting
  1422. XmNrecomputeSize to False can dramatically improve performance if you have
  1423. alot of labels or change them frequently.)
  1424.  
  1425. Ken Lee, http://www.rahul.net/kenton/
  1426.  
  1427. -----------------------------------------------------------------------------
  1428. Subject: 157)  How do you set the background color of a label widget using
  1429. XtVaTypedArg?
  1430.  
  1431. [Last modified: July 96]
  1432.  
  1433. Answer:  Use the XmNbackground resource to control the background color, e.g.
  1434.  
  1435.     strcpy(bgcolor, "yellow");
  1436.     XtVaSetValues(widget,
  1437.                 XtVaTypedArg, XmNbackground, XtRString, bgcolor,
  1438.                 strlen(bgcolor)+1, NULL);
  1439.  
  1440. The length of the color string is plus one to include the null character.
  1441. XtRString is the type to be converted.  The conversion is required because
  1442. XmNbackground expects a Pixel type.
  1443.  
  1444. Thanks to Martin Squicciarini (msquicci@resd.vf.ge.com).
  1445.  
  1446. -----------------------------------------------------------------------------
  1447. END OF PART FIVE
  1448.