home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / motif-faq / part4 < prev    next >
Text File  |  2004-05-05  |  55KB  |  1,419 lines

  1. Path: senator-bedfellow.mit.edu!dreaderd!not-for-mail
  2. Message-ID: <motif-faq/part4_1083675484@rtfm.mit.edu>
  3. Supersedes: <motif-faq/part4_1082292761@rtfm.mit.edu>
  4. Expires: 17 Jun 2004 12:58:04 GMT
  5. References: <motif-faq/part1_1083675484@rtfm.mit.edu>
  6. X-Last-Updated: 2002/01/31
  7. Organization: none
  8. Subject: Motif FAQ (Part 4 of 9)
  9. Newsgroups: comp.windows.x.motif,comp.answers,news.answers
  10. Keywords: FAQ question answer
  11. From: kenton@rahul.net (Ken Lee)
  12. Reply-To: kenton@rahul.net (Ken Lee)
  13. Approved: news-answers-request@MIT.EDU
  14. Followup-To: poster
  15. Summary: Motif Frequently Asked Questions (with answers).
  16. Originator: faqserv@penguin-lust.MIT.EDU
  17. Date: 04 May 2004 12:59:11 GMT
  18. Lines: 1398
  19. NNTP-Posting-Host: penguin-lust.mit.edu
  20. X-Trace: 1083675551 senator-bedfellow.mit.edu 561 18.181.0.29
  21. Xref: senator-bedfellow.mit.edu comp.windows.x.motif:75187 comp.answers:57052 news.answers:270856
  22.  
  23. Archive-name: motif-faq/part4
  24. Last-modified: 1 FEB 2002
  25. Posting-Frequency: irregular
  26. Organization: Kenton Lee, X/Motif Consultant, http://www.rahul.net/kenton/
  27. URL:  http://www.rahul.net/kenton/mfaq.html
  28. Version: 8.1
  29.  
  30. ----------------------------------------------------------------------------
  31. Subject: 67)  Is there an mwm virtual desktop manager?
  32. [Last modified: Sep 97]
  33.  
  34. Answer: David Kaelbling (drk@x.org) reports: In OSF/Motif 2.0, mwm supports
  35. both workspaces (see the f.cci function and the wsm demo for a sample
  36. interface) and a virtual root window.  To manipulate the virtual screen
  37. f.goto, f.pan, and f.track_pan were added, as were iconPinned and clientPinned
  38. client resources.
  39.  
  40. Peter E. Wagner (pwagner@panix.com): Imagine that your "desktop" extends
  41. beyond the view provided by your monitor.  A virtual window manager gives you
  42. access to the space beyond your viewport (i.e. your screen) by allowing you to
  43. move the viewport to other areas of the extended desktop.
  44.  
  45. The first one is Solbourne's swm, which spawned vtwm/tvtwm/olvwm.
  46.  
  47. David B. Lewis created one.  suresh@unipalm.co.uk has further developed it
  48. into the UniPalm product DOORS, which is only available as a source code
  49. extension to the MOTIF window manager.  The price of the source and unlimited
  50. right to distribute binaries is 10,000 pounds Sterling.  Alternately, source
  51. and right to use within one company is 2,000 pounds Sterling.  Contact Peter
  52. Dawe
  53.  
  54. Unipalm Limited                         Voice: +44 (0) 223 420002
  55. 216 The Science Park                    Fax:   +44 (0) 223 426868
  56. CAMBRIDGE
  57. CB4 4WA
  58.  
  59. An enhancement request for such an object has been filed with OSF.
  60.  
  61. Tim Failes (tim@aus.oz.au) of Advanced User Systems Pty Ltd writes: IXI (now
  62. SCO) has a fully supported product called Panorama which provides this
  63. facility.  Panorama allows the user to pan around the virtual work space,
  64. dynamically change the size of the virtual workspace, and also access windows
  65. via an icon box.  Panorama also includes a point-and-click tool for setting
  66. resources such as colours, focus policy, etc. [SCO contact information appears
  67. in the "Where can I get Motif?" subject. -ed]
  68.  
  69. -----------------------------------------------------------------------------
  70. Subject: 68)  Why does mwm 1.2 crash on startup?
  71. [Last modified: March 93]
  72.  
  73. Answer: David Brooks wrote: The commonest cause of early mwm demise is as
  74. follows:
  75.  
  76. - You, or someone, built Xlib in the default way using the Xsi
  77.   internationalization functions.
  78.  
  79. - Your Xlib wasn't installed completely (or at all).
  80.  
  81. - Early on, mwm calls the function XmbTextListToTextProperty, which calls
  82.   _XConvertMBToCT, which looks for the Xsi locale database, finds it
  83.   missing, ignores this fact and tries to dereference zero.
  84.  
  85. The workaround is to find the database *somewhere*, and point the environment
  86. variable XNLSPATH at it.  For example, in my personal X source tree:
  87.  
  88.         setenv XNLSPATH /home/X11r5src/mit/lib/nls/Xsi
  89.  
  90. -----------------------------------------------------------------------------
  91. Subject: 69)  How do I obtain the size of a unmanaged shell widget?
  92.  
  93. Answer: In the code below, use getsize() for widgets which have been managed,
  94. and getsize2() for newly created shell widgets which have not yet been
  95. managed.
  96.  
  97. getsize2() takes two widget parameters because popup dialogs etc.  _consist_
  98. of two separate widgets - the parent shell and the child bulletin board, form,
  99. whatever.  This important distinction (somewhat glossed over in the Motif
  100. manuals) is the cause of a large number of queries in comp.windows.x.motif.
  101. XmCreate...Dialog() functions return the (bulletin board, form, whatever)
  102. _child_ of the pair, not the parent shell.
  103.  
  104. getsize2() takes the _shell_ widget as it's first parameter, and the shell's
  105. _child_ (the bulletin board, form, whatever) as it's second.  Thus, if you are
  106. using code like widget = XmCreate...Dialog() to create your popup dialogs, use
  107. code like getsize2(XtParent(widget),widget,&width,&height) to get the width
  108. and height. If you use e.g. XmCreateDialogShell() or XtCreatePopupShell(),
  109. then you are creating the the shell widget and it's child explicitly, and can
  110. just pass them into getsize2() with no problem.
  111.  
  112. Note: getsize2() calls getsize().
  113.  
  114. /* getsize(widget,width,height);
  115.  * Widget widget;
  116.  * int *width,*height;
  117.  *
  118.  * returns the width and height of a managed widget */
  119.  
  120.  
  121. void getsize(l,w,h) Widget l; int *w,*h; { Dimension w_,h_,b_;
  122.  
  123. static Arg size_args[] =
  124.   {
  125.   { XmNwidth,0 },
  126.   { XmNheight,0 },
  127.   { XmNborderWidth,0 },
  128.   };
  129.  
  130. size_args[0].value = (XtArgVal)&w_; size_args[1].value = (XtArgVal)&h_;
  131. size_args[2].value = (XtArgVal)&b_;
  132.  
  133. XtGetValues(l,size_args,3);
  134.  
  135. if (w) *w = w_ + b_; if (h) *h = h_ + b_; } /*
  136. getsize2(shell,child,width,height);
  137.  * Widget shell,child;
  138.  * int *width,*height;
  139.  *
  140.  * returns the width, height of an unmanaged shell widget */
  141.  
  142. void getsize2(p,c,w,h) Widget p,c; int *w,*h; { XtSetMappedWhenManaged(p,0);
  143.  
  144. XtManageChild(c);
  145.  
  146. getsize(p,w,h);
  147.  
  148. XtUnmanageChild(c);
  149.  
  150. XtSetMappedWhenManaged(p,-1); } submitted by: [ Huw Rogers  Communications
  151. Software Engineer, NEC Corporation, Tokyo, Japan ] [ Email:
  152. rogersh@ccs.mt.nec.co.jp  Fax: +81-3-5476-1005  Tel: +81-3-5476-1096 ]
  153.  
  154. -----------------------------------------------------------------------------
  155. Subject: 70)  How can I create a shell widget with a non-default visual type?
  156. [Last modified: Feb 00]
  157.  
  158. Answer: You must specify the colormap, visual type, and depth for the shell
  159. before it is realized.  If you don't specify all three resources (or specify
  160. them incorrectly), you will probably get BadMatch protocol errors from your X
  161. server.
  162.  
  163. Ken Lee, http://www.rahul.net/kenton/
  164.  
  165.  
  166. Mike Stroyan, mike_stroyan@fc.hp.com, adds:
  167.   It is convenient to use XrmPutResource to cause all widgets to pick up a
  168. consistent set of visual, depth, and colormap.  It is just very difficult to
  169. get at each and every shell including menushells created by functions like
  170. XmVaCreateSimpleMenuBar and XmVaCreateSimpleOptionMenu.
  171.  
  172. This example uses the default visual for menus, but a non-default for the top
  173. level shell:
  174.  
  175. if (!non_default_dialogs) {
  176.     /* Set default depth and colormap of shell widgets, especially menus */
  177.     Screen *default_screen;
  178.     int default_depth;
  179.     Colormap default_colormap;
  180.     XrmDatabase db = XtDatabase(display);
  181.     XrmValue v;
  182.  
  183.     default_screen = DefaultScreenOfDisplay(display);
  184.     default_depth = DefaultDepthOfScreen(default_screen);
  185.     default_colormap = DefaultColormapOfScreen(default_screen);
  186.     v.size = sizeof(default_depth);
  187.     v.addr = (XtPointer) &default_depth;
  188.     XrmPutResource(&db,"*XmMenuShell.depth", XmRInt, &v);
  189.     XrmPutResource(&db,"*XmDialogShell.depth", XmRInt, &v);
  190.     v.size = sizeof(default_colormap);
  191.     v.addr = (XtPointer) &default_colormap;
  192.     XrmPutResource(&db,"*XmMenuShell.colormap", XmRColormap, &v);
  193.     XrmPutResource(&db,"*XmDialogShell.colormap", XmRColormap, &v);
  194. }
  195.  
  196. /* Get visual information. */
  197. template.screen = DefaultScreen(display);
  198. template.class = TrueColor;
  199. template.depth = 24;
  200. mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
  201. vilist = XGetVisualInfo(display, mask, &template, &nvisual);
  202. if (nvisual == 0) {
  203.     fprintf(stderr, "Cannot find an acceptable visual!0);
  204.     exit(1);
  205. }
  206. visual = vilist[0].visual;
  207. depth = vilist[0].depth;
  208. XFree((char *) vilist);
  209.  
  210. private_colormap = XCreateColormap(display, DefaultRootWindow(display),
  211.     visual, AllocNone);
  212. {
  213.     XColor real, exact;
  214.     XAllocNamedColor(display, private_colormap, "Green", &real, &exact);
  215.     green = real.pixel;
  216. }
  217.  
  218. XtVaSetValues(toplevel,
  219.     XmNdepth, depth,
  220.     XmNvisual, visual,
  221.     XmNcolormap, private_colormap,
  222.     NULL);
  223.  
  224. if (non_default_dialogs) {
  225.     /* Set non-default visual for all widgets. */
  226.     XrmDatabase db = XtDatabase(display);
  227.     XrmValue v;
  228.     v.size = sizeof(visual);
  229.     v.addr = (XtPointer) &visual;
  230.     XrmPutResource(&db,"*visual", XmRVisual, &v);
  231. }
  232.  
  233.  
  234. -----------------------------------------------------------------------------
  235. Subject: 71)  Can a non-shell Motif widget have a different visual type from
  236. its parent?
  237. [Last modified: May 97]
  238.  
  239. Answer: None of the standard Motif widgets support this.  You can, however,
  240. write your own subclasses that have different visual types.  You'll have to
  241. override the Realize method in your subclass.  Becareful to set the colormap
  242. and depth properly to match your visual type.
  243.  
  244. Ken Lee
  245.  
  246. -----------------------------------------------------------------------------
  247. Subject: 72)  Why do I get BadMatch errors from my menus when I use a non-
  248. default visual type for my application shell?
  249. [Last modified: Sept 95]
  250.  
  251. Answer: Unfortunately, the visual type and depth attributes are copied
  252. differently from parent to child.  To be safe you use non-default visuals on
  253. any of your widgets and use these as parents for shell widgets (including
  254. menus), you should set the visual type, depth, and colormap on the child
  255. shells.
  256.  
  257. Ken Lee
  258.  
  259. -----------------------------------------------------------------------------
  260. Subject: 73)  How do I popup a scrolled list on top of other widgets?
  261. [Last modified: Sept 95 ]
  262.  
  263. Put it in an override redirect shell and do a XMapRaise on the shell's window.
  264. That will do it.  If you're using Motif then just use a VendorShell with
  265. XmNoverrideRedirect set to true.
  266.  
  267. Thanks to Doug Rand (drand@sgi.com)
  268.  
  269. -----------------------------------------------------------------------------
  270. Subject: 74)  How can I keep my application's window always on top of all
  271. other applications' windows?
  272. [Last modified: Sep 97]
  273.  
  274. Answer: Some window managers have features supporting this.  Mwm does not.
  275. The ICCCM does not specify a standard protocol for using the feature.
  276.  
  277. Note:  some applications attempt to implement this by periodically popping
  278. themselves to the top of the stack (perhaps in response to visibility change
  279. events).  This is very poor practice and should be avoided.  If more than one
  280. of a user's applications try this hack, the user will not be pleased.
  281.  
  282. Ken Lee
  283.  
  284. -----------------------------------------------------------------------------
  285. Subject: 75)  How can I maximize my top level shell?
  286. [Last modified: Apr 98]
  287.  
  288. Answer: There is no explicit support for this.  Maximizing makes sense in
  289. single tasking operating systems where the user must choose one application to
  290. be active.  Motif usually runs in multi-tasking operating systems where
  291. several applications may be active and having one take over the screen is
  292. undesirable.
  293.  
  294. If you must make your application full screen, use the Xlib macros to compute
  295. the root window size and set the width and height of your shell to this size.
  296. You may want to leave a little space around the edges for the window manager
  297. frame.
  298.  
  299. Ken Lee
  300.  
  301. -----------------------------------------------------------------------------
  302. Subject: 76)  TOPIC: MOTIF DEVELOPMENT TOOLS (GUI BUILDERS and UIMS's)
  303.  
  304. -----------------------------------------------------------------------------
  305.  
  306. Subject: 77)*  What GUI tools exist to assist in developing Motif
  307. applications?
  308. [Last modified: Feb 02 ]
  309.  
  310. Answer: This subject was very out-of-date and has been deleted.  Some popular
  311. tools are listed at: http://www.rahul.net/kenton/xsites.framed.html
  312.  
  313. -----------------------------------------------------------------------------
  314. Subject: 78)  TOPIC: GEOMETRY MANAGEMENT
  315.  
  316. -----------------------------------------------------------------------------
  317. Subject: 79)  Why is geometry management so important?
  318. [Last modified: Sept 94]
  319.  
  320. Answer: Geometry management is a key element of Motif applications for reasons
  321. which include, but are not limited to, the following:
  322.  
  323.  
  324.     The user should be able to re-size the shell and get
  325.     some reasonable geometry response (other than clipping).
  326.  
  327.     The user should be able to tailor fonts and have the
  328.     widgets adjust accordingly.  (Many people over 40 simply
  329.     can't read small fonts without serious eye strain.)
  330.  
  331.     When the designers decide to change a label, the widgets
  332.     should re-adjust accordingly.
  333.  
  334.     Some labels must be set dynamically and the widgets should
  335.     re-layout accordingly.
  336.  
  337.     An internationalized application must work with several resource
  338.     files, one for each supported natural language.  The labels in each
  339.     file have different lengths and the application should adjust
  340.     accordingly.
  341.  
  342.  
  343. -----------------------------------------------------------------------------
  344. Subject: 80)  Why don't my labels resize in a RowColumn widget?  I have a
  345. RowColumn widget in my application, with several rows and columns of XmLabels.
  346. When I update the text in the labels, the label's width does not get updated.
  347. [Last modified: Oct 94]
  348.  
  349. Answer: Make sure all the ancestor widget resize mechanisms are enabled:
  350.  
  351.    - on shells, set XmNallowShellResize
  352.    - on row column, set XmNresizeWidth and XmNresizeHeight
  353.    - on bulletin board and form, set XmNresizePolicy
  354.  
  355. Also, set XmNrecomputeSize on the label itself.  The shell resource is off by
  356. default; the others should be on by default.
  357.  
  358. Ken Lee
  359.  
  360. -----------------------------------------------------------------------------
  361. Subject: 81)  Does XmRowColumn support multiple columns with different column
  362. widths?
  363. [Last modified: Apr 98]
  364.  
  365. Answer: XmRowColumn was designed for simple layouts like menu panes and tool
  366. bars.  For more sophisticated layouts, you should use an XmForm widget
  367. instead.
  368.  
  369. Ken Lee
  370.  
  371. -----------------------------------------------------------------------------
  372. Subject: 82)  Why do composite widgets (including dialogs) that were created
  373. after their parents were realized appear smaller under 1.2.3 and later?
  374. [Last modified: Dec 97]
  375.  
  376. A. Thanks to David Brooks (dbrooks@ics.com) for pointing me to Daniel
  377. Dardailler (daniel@x.org) who wrote this scholarly treatise:
  378.  
  379.       Application's Geometry Management Advanced Guidelines:
  380.       =====================================================
  381.       (or "How to properly manage children of already realized parent")
  382.  
  383. Xt Background:
  384. -------------
  385.  
  386.     XtCreateWidget:        call Initialize ;
  387.  
  388.     XtManageChild:         if (parent realized)
  389.                               call ChangeManaged ;
  390.                               call Realize ;
  391.  
  392.     XtRealizeWidget:       postorder ChangeManaged loop ;
  393.                            preorder Window-creation loop ;
  394.  
  395. Creating a widget only invokes its Initialize method (its parent's
  396. InsertPosition method too, but that has nothing to do with GM).
  397. Composite widgets, by opposition to Primitive, does
  398. not usually get a correct size at initialization time, since their
  399. correct size is based on their children sizes, which do not exist yet
  400. at this time.
  401.  
  402. Applications usually create an entire tree of managed but
  403. unrealized widgets and then realize their top level widget, which recursively
  404. realize every widgets in the tree. During the creation process, the
  405. managing of the unrealized widgets is a no-op (only mark them managed).
  406.  
  407. When XtRealizeWidget(toplevel) happens, the change_managed methods of
  408. all the composite widgets in the tree are called in bottom-to-top
  409. order, thus giving each of them a chance to determine their own size
  410. based on their children *current* sizes (composite or not).
  411. Using the current size of the children in this situation is fine,
  412. since they should also be the children's preferred size, not
  413. yet constrained by the parents layout (post-order traversal).
  414.  
  415. When one create a widget inside an already realized parent, this is
  416. a different story and the order of management vs realization is important.
  417.  
  418. Consider a MessageBox created in a realized Frame.
  419. The MessageBox itself creates a bunch of managed children
  420. inside its Initialize method.
  421. If you manage the MessageBox right after its creation, the Frame
  422. ChangeManaged will be called (since it is realized), and its will use
  423. the MessageBox current size as its base for its own size.
  424. Unfortunately, the MessageBox ChangeManaged proc has never been called!
  425. so its current size is whatever the default is, usually a non-settable
  426. value (needed for tracking real initial size setting).
  427. The MessageBox ChangeManaged has not been called because its children
  428. were created and managed at a time where it wasn't realized.
  429.  
  430. What to do ?
  431.  
  432. The first solution would be to have all the ChangeManaged methods in
  433. Motif call XtQueryGeometry instead of using the current size if it's
  434. not the first time (i.e. if they're already realized).
  435. But this is a lot of code to change and a kind of expensive run-time
  436. process as it results in non-linear traversal order of the realized
  437. tree (looks like an O(n!) but I'm not sure).
  438. It's not even guaranteed that it will always work fine, since it relies on
  439. the assumption that the geometry queried is the same that the geometry
  440. asked for any manager (I mean, it might be the case, but if it's not,
  441. it's just more code to fix in a very "bc-sensitive" part of Xm).
  442.  
  443. This other solution lies into the application, and is to realize a
  444. manager first and then to manage it.
  445. By realizing it, you are forcing its ChangeManaged proc to be
  446. called (XtRealizeWidget does that), it will get a correct size and
  447. this size will be used by its parent ChangeManaged when
  448. you'll manage the manager. By explicitly realizing the branch
  449. before managing its root, you are reproducing the ordering that
  450. is typical of most applications at startup.
  451.  
  452. So the trick is:
  453.  
  454.     XtCreateWidget(realize_parent, MessageBox);
  455.     XtRealizeWidget(MessageBox);  /* needed */
  456.     XtManageChild(MessageBox);
  457.  
  458. and the model is:
  459.  
  460.     "Always explicitly realize a composite widget child of an already
  461.      realized parent before managing it if all its children have been
  462.      already managed"
  463.  
  464. One can always realize every widget children of realized parents, that
  465. won't hurt, but it's useless for Primitives and Composites that
  466. get more children added later in the program.
  467. Why? because Primitives get their correct size at initialization
  468. time anyway and adding a child to a Composite will generate a geometry
  469. request and a layout that will have the same effect as if the
  470. ChangeManaged method had been called (well, nearly the same effect,
  471. that a complication I will address later).
  472.  
  473. If we consider Motif, this trick is only useful for MessageBox,
  474. SelectionBox and subclasses, and Scale, since those are the only
  475. Composites that create managed children in their Initialize method and
  476. don't usually get additional kids from the application.
  477.  
  478. However, any application that re-creates this order of actions will
  479. need to apply the "realize<manage" method too.
  480. For instance:
  481.  
  482.     XtCreateWidget(realize_parent, DrawingArea);
  483.     XtRealizeWidget(DrawingArea);   /* not needed */
  484.     XtManageChild(DrawingArea);
  485.     XtCreateWidget(DrawingArea, any_child) ;
  486.     XtManageChild(any_child);
  487. but
  488.     XtCreateWidget(realize_parent, DrawingArea);
  489.     XtCreateWidget(DrawingArea, any_child) ;
  490.     XtManageChild(any_child);
  491.     XtRealizeWidget(DrawingArea);   /* needed */
  492.     XtManageChild(DrawingArea);
  493.  
  494. Now this is becoming interesting: there are exceptions to the model :-)
  495.  
  496. The first one is the Xt Shell widget, which has what I consider to be a
  497. bug, but what MIT has, until recently, always considered to be a specific
  498. behavior overridable by a subclass (like our VendorShell):
  499. the ChangeManaged method always resizes the child to its own size
  500. when the Shell is realized.
  501.  
  502. A side effect of this behavior is that even the realized<managed trick
  503. won't work for direct descendant of Shell widget:
  504.  
  505.     XtCreateWidget(realize_shell, MessageBox);
  506.     XtRealizeWidget(MessageBox);  /* needless */
  507.     XtManageChild(MessageBox);    /* will get resized anyway */
  508.  
  509. To get rid of this problem, one needs to add a regular manager
  510. between the Shell and the MessageBox in this case, for the sake
  511. of having this manager doing a request to the Shell from its
  512. ChangeManaged proc. This request will then be handled by the Shell
  513. geometry manager, not its ChangeManaged proc, and it will take into
  514. account the child size.
  515. Note that we could also change our VendorShell ChangeManaged code to not
  516. systematically envelop the Xt Shell ChangeManaged class method, and
  517. check for the already realized case, but I would rather wait
  518. for an Xt fix instead (I'm working on it).
  519.  
  520. If you broader the scope of the Xt Shell situation, you find that there are
  521. also some resources in Xm that come into effect upon geometry request
  522. reception but are not used in the ChangeManaged method.
  523.  
  524. Take the PanedWindow constraint resource XmNallowResize for instance,
  525. which controls the validity of a geometry request made by a PW child.
  526.  
  527. If you do:
  528.  
  529.     XtCreateWidget(realize_shell, PanedWindow);
  530.     XtManageChild(PanedWindow);
  531.  
  532.     XtCreateWidget(PanedWindow, button);
  533.     XtManageChild(button);
  534.  
  535. that works fine since the ChangeManaged of the PanedWindow will
  536. handle the insertion of the button and allowResize won't be used.
  537.  
  538. But if you add a manager in this hierarchy:
  539.  
  540.     XtCreateWidget(realize_parent, PanedWindow);
  541.     XtManageChild(PanedWindow);
  542.  
  543.     XtCreateWidget(PanedWindow, manager);
  544.     XtManageChild(manager);
  545.  
  546.     XtCreateWidget(manager, button);
  547.     XtManageChild(button);
  548.  
  549. That doesn't work anymore since the button management results in
  550. its parent manager's ChangeManaged being called, which in turn makes a
  551. *request* to the PanedWindow, resulting in a No reply because
  552. of allowResize (set to False by default).
  553.  
  554. The PanedWindow parent wouldn't have been realized that everything
  555. would have worked fine, since no request would have been made.
  556. It really depends on the early realization scheme.
  557.  
  558. I think XmNresizable in Form is the only other resource to present
  559. this problem. There is not much to do in those cases except than
  560. setting the corresponding resource to True, which makes sense.
  561.  
  562. - Daniel Dardailler (daniel@x.org)
  563.  
  564.  
  565. In addition, John Michael Davison <davisonj@panix.com> sends this suggestion.
  566. I think it's overkill for most people, but you may want to consider it if you
  567. have problems in this area:
  568.  
  569. /* Workaround for motif 1.2.3-style geometry management */
  570. void
  571. smart_manage_child(Widget widget)
  572. {
  573.     assert(widget != 0);
  574.  
  575. #if XmVersion >= 1002 && XmUPDATE_LEVEL >= 3
  576.     /* In Motif 1.2.3 and later:
  577.     /*     "Always explicitly realize a composite widget child of an already
  578.     /*     realized parent before managing it..."
  579.     /* Note that this is unnecessary for simple UI objects (i.e. wrappers for
  580.     /* Motif "Primitive" widgets.)
  581.     */
  582.     if (XtIsManaged(widget))
  583.         return;
  584.     if (!XtIsRealized(widget) && XtIsComposite(widget))
  585.     {
  586.         Widget parent_widget = XtParent(widget);
  587.         if (parent_widget && XtIsRealized(parent_widget))
  588.             XtRealizeWidget(widget);
  589.     }
  590. #endif  /* XmVersion >= 1002 && XmUPDATE_LEVEL >= 3 */
  591.     XtManageChild(widget);
  592. }
  593.  
  594. - John Michael Davison <davisonj@panix.com>
  595.  
  596.  
  597. FYI - Asente & Swick (p. 207) says:
  598.  
  599. If the child's parent is realized, XtManageChild and XtManageChildren
  600. automatically realize any widgets passed to them that are not currently
  601. realized, causing the creation of their windows.  However, you should
  602. explicitly realize a composite child of a realized widget before managing the
  603. child to ensure that the child appears with its correct size.
  604.  
  605. - Ken Lee, http://www.rahul.net/kenton/
  606.  
  607. -----------------------------------------------------------------------------
  608. Subject: 83)  How does the ScrolledWindow manage resizing?
  609. [Last modified: June 95]
  610.  
  611. Answer: The scrolled window should resize its immediate child when it is
  612. resized.  The child is XmNworkWindow in the default application-defined
  613. scrolling mode or XmNclipWindow in the automatic scrolling mode.  In either
  614. case, you can then resize your row column.  If you set XmNadjustLast, the
  615. children of a one column row column will be automatically resized.
  616.  
  617. Ken Lee
  618.  
  619. -----------------------------------------------------------------------------
  620. Subject: 84)  Does the XmPanedWindow widget support horizontal paning?
  621. [Last modified: May 97]
  622.  
  623. Answer: In Motif 2.x it does, but not in Motif 1.x.  There are, however, some
  624. 3rd party horizontal paned widgets listed in the Widget FAQ:
  625.  
  626.  
  627. http://reality.sgi.com/widgetFAQ/
  628.  
  629. Ken Lee
  630.  
  631. -----------------------------------------------------------------------------
  632. Subject: 85)  TOPIC: TEXT WIDGET
  633.  
  634. -----------------------------------------------------------------------------
  635. Subject: 86)  How do XmTextField and a single line XmText widget differ?
  636. [Last modified: Oct 94]
  637.  
  638. Answer: XmTextField is designed to be a lightweight, single line text editor.
  639. It does not provide as much functionality as does XmText in order to achieve
  640. better performance.
  641.  
  642. Thanks to Kevin Till, kev@osf.org
  643.  
  644. -----------------------------------------------------------------------------
  645. Subject: 87)  Why does  pressing RETURN in a text widget do nothing?  This
  646. happens using Motif 1.0 when I have a text widget inside a bulletin board (or
  647. form) inside a dialog shell. (In Motif 1.1 it is fixed for both text and list
  648. widgets.)
  649.  
  650. Answer: In single line mode, pressing the <return> key usually invokes the
  651. activate() action, and in multi-line mode, the newline() action.  However,
  652. whenever a widget is the child of a bulletin board widget which is the child
  653. of a dialog shell, the bulletin board forces all of its children to translate
  654. <return> to the bulletin board action Return() which is usually associated
  655. with the default button of the dialog.  To restore the text actions of
  656. activate() or newline(), you need to overide the Return() action of the
  657. bulletin board.
  658.  
  659.  
  660. /* declarations */
  661. /* for a single line widget */
  662. char newTrans[] = "<Key>Return : activate()";
  663. /* for a multi line widget */
  664. char newTrans[] = "<Key>Return : newline()";
  665. XtTranslations transTable;
  666.  
  667. /* in executable section */
  668.  
  669. transTable = XtParseTranslationTable(newTrans);
  670.  
  671. /* after creating but before managing text widget */
  672.  
  673. XtOverrideTranslations(textWidget, transTable);
  674.  
  675.  
  676. -----------------------------------------------------------------------------
  677. Subject: 88)  Can you reuse the return value from XtParseTranslationTable?
  678. [Last modified: Nov 96]
  679.  
  680. Answer: The following is a conversation circa 30 Sep 1996 between Kaleb
  681. Keithley (kaleb@x.org) and Tim Behrendsen (tim@a-sis.com, tim@airshields.com>.
  682. The latter suggested this appear in the Motif FAQ.
  683.  
  684. B> Can the return value from XtParseTranslationTable be saved
  685. TB> off and reused for the lifetime of the application?
  686.  
  687. KK> Yes.
  688.  
  689. TB> Ah!  The answer.  Thank you.
  690. KK>
  691. KK>    XtVaSetValues(widget,
  692. KK>        XmNtranslations, XtParseTranslationTable(table), NULL);
  693.  
  694. TB> which implies it's a one-shot deal (otherwise, this would cause
  695. TB> a memory leak).
  696.  
  697. KK> No, you can always retrieve them with Xt(Va)GetValues.
  698.  
  699. TB> You can, but if you don't and use the technique to wantonly
  700. TB> create and destroy dialogs, it seems you will get a memory
  701. TB> leak.
  702.  
  703. KK> That's correct.
  704.  
  705. TB> In fact, what's scary is this technique is used in the Motif
  706. TB> FAQ list; I knew I saw it somewhere reasonably authoritative
  707. TB> ([approx.] Question 133; code by Dan Heller, O'Reilly and Associates).
  708. TB> He does the following:
  709.  
  710. TB>        XtOverrideTranslations(bboard,
  711. TB>             XtParseTranslationTable("<Configure>: resize()"));
  712.  
  713. TB> This has to be unquestionably broken code, if the translation
  714. TB> tables are never freed or never reused.  Obviously, I can't
  715. TB> extract out the table from overridden translations.
  716.  
  717. KK> You can't extract the original translations, that's correct.
  718.  
  719. TB> Come to think of it; how is this handled when translations are
  720. TB> parsed in resource files?  If I have lots of translation
  721. TB> overrides, do they simply burn up space that can't be reused?
  722. TB> Does it get burned up over and over as I create widgets that
  723. TB> use those translation resources?
  724.  
  725. KK> Yup and yup.
  726.  
  727.  
  728. -----------------------------------------------------------------------------
  729. Subject: 89)  When I add text to a scrolling text widget, how can I get the
  730. new text to show?
  731. [Last modified: Sept 94]
  732.  
  733. Answer: Use the (fully supported) function XmTextShowPosition:
  734.  
  735. void XmTextShowPosition(w, position)
  736. Widget w;
  737. XmTextPosition position;
  738.  
  739. where the position is the number of characters from the beginning of the
  740. buffer of the text to be displayed. If you don't know how many characters are
  741. in the buffer, use XmTextGetLastPosition.
  742.  
  743. position = XmTextGetLastPosition(w)
  744.  
  745.  
  746. -----------------------------------------------------------------------------
  747. Subject: 90)  How do I scroll text to display the most recently added
  748. information?
  749. [Last modified: Aug 95]
  750.  
  751. Answer: If you're using the XmScrolledText widget, use XmTextSetTopCharacter()
  752. or XmTextScroll().
  753.  
  754. Ken Lee
  755.  
  756. -----------------------------------------------------------------------------
  757. Subject: 91)  Does the text widget support 16 bit character fonts?
  758. [Last modified: November 92]
  759.  
  760. Answer: R5 has support for 16 bit character sets, and Motif 1.2 uses that.
  761. Neither Motif 1.0 nor 1.1 support 16 bit sets.
  762.  
  763. -----------------------------------------------------------------------------
  764. Subject: 92)  How can I stop the text widget from echoing characters typed?  I
  765. need to turn off echo for password input.
  766.  
  767. Answer: Use the XmNmodifyVerifyCallback to tell when input is received. Set
  768. the `doit' field in the XmTextVerifyCallbackStruct to False to stop the echo.
  769. (In Motif 1.0 this will cause a beep per character: Live with it, because at
  770. 1.1 you can turn it off.) Note that password hiding is inherently insecure in
  771. X - someone may have an X grab on the keyboard and be reading all characters
  772. typed in anyway.
  773.  
  774. Another solution often proposed is to set the foreground and background
  775. colours to be the same, effectively hiding the text.  This has a major flaw:
  776. someone may select the text (triple click the mouse to get the line), and then
  777. paste the password into say an xterm with *different* foreground and
  778. background colours.  This immediately shows the password.
  779.  
  780. -----------------------------------------------------------------------------
  781. Subject: 93)  How can I replace characters typed with say a `*'?  I want to
  782. replace input for password entry.
  783. [Last modified: Nov 96]
  784.  
  785. Answer: The solution involves the use of XmNmodifyVerifyCallback and then
  786. examining the XmTextVerifyCallbackStruct.  The following program from Dan
  787. Heller and Paula Ferguson illustrates this:
  788.  
  789. /* Written by Dan Heller and Paula Ferguson.
  790. * Copyright 1994, O'Reilly & Associates, Inc.
  791. * Permission to use, copy, and modify this program without
  792. * restriction is hereby granted, as long as this copyright
  793. * notice appears in each copy of the program source code.
  794. * This program is freely distributable without licensing fees and
  795. * is provided without guarantee or warrantee expressed or implied.
  796. * This program is -not- in the public domain.
  797. *
  798. * 9Sept1996 RAF -- this is a working version, at least under Sol2.4,
  799. * using gcc.  I only modified check_passwd().
  800. *
  801. */
  802.  
  803. /* password.c -- prompt for a password. All input looks like
  804. * a series of *'s.  Store the actual data typed by the user in
  805. * an internal variable.  Don't allow paste operations.  Handle
  806. * backspacing by deleting all text from insertion point to the
  807. * end of text.
  808. */
  809. #include <Xm/Text.h>
  810. #include <Xm/LabelG.h>
  811. #include <Xm/RowColumn.h>
  812. #include <ctype.h>
  813.  
  814. void check_passwd();
  815. char *passwd; /* store user-typed passwd here. */
  816.  
  817. main(argc, argv)
  818. int argc;
  819. char *argv[];
  820. {
  821. Widget        toplevel, text_w, rowcol;
  822. XtAppContext  app;
  823.  
  824. XtSetLanguageProc (NULL, NULL, NULL);
  825.  
  826. toplevel = XtVaAppInitialize (&app, "Demos",
  827. NULL, 0, &argc, argv, NULL, NULL);
  828.  
  829. rowcol = XtVaCreateWidget ("rowcol",
  830. xmRowColumnWidgetClass, toplevel,
  831. XmNorientation, XmHORIZONTAL,
  832. NULL);
  833.  
  834. XtVaCreateManagedWidget ("Password:",
  835. xmLabelGadgetClass, rowcol, NULL);
  836. text_w = XtVaCreateManagedWidget ("text_w",
  837. xmTextWidgetClass, rowcol, NULL);
  838.  
  839. XtAddCallback(text_w, XmNmodifyVerifyCallback, check_passwd, NULL);
  840. XtAddCallback(text_w, XmNactivateCallback, check_passwd, NULL);
  841.  
  842. XtManageChild (rowcol);
  843. XtRealizeWidget (toplevel);
  844. XtAppMainLoop (app);
  845. }
  846.  
  847. /* check_passwd() -- handle the input of a password. */
  848. void
  849. check_passwd(text_w, client_data, call_data)
  850. Widget        text_w;
  851. XtPointer     client_data;
  852. XtPointer     call_data;
  853. {
  854. char *new;
  855. char *oldpasswd;
  856. int len;
  857. XmTextVerifyCallbackStruct *cbs =
  858. (XmTextVerifyCallbackStruct *) call_data;
  859.  
  860. if (cbs->reason == XmCR_ACTIVATE) {
  861. printf ("4assword: %s0, passwd);
  862. return;
  863. }
  864.  
  865. if( cbs->text->length > 1 ) {
  866. cbs->doit = False; /* don't allow paste operations; make the */
  867. return;            /* user type the password! */
  868. }
  869.  
  870. if( cbs->startPos < cbs->endPos ) {
  871. /* shrink the password by moving endPos... characters forward to
  872. /* the point of deletion */
  873. memmove( &(passwd[cbs->startPos]),
  874.          &(passwd[cbs->endPos]),
  875.          strlen(passwd) - cbs->endPos + 1 );
  876. if( cbs->text->length == 0 ) /* then just a delete, not a replace */
  877.     return;
  878. }
  879.  
  880. new = XtMalloc( cbs->text->length + 1 );
  881. strncpy( new, cbs->text->ptr, cbs->text->length ); /* just the new chars */
  882. new[cbs->text->length]=' ';
  883.  
  884. if( passwd ) {
  885. /* open a hole for the new characters, and insert them
  886. /* in the proper place */
  887. passwd = XtRealloc( passwd, strlen(passwd) + cbs->text->length + 1 );
  888. memmove( &(passwd[cbs->startPos + cbs->text->length]),
  889.          &(passwd[cbs->startPos]),
  890.          strlen(passwd) - cbs->startPos + 1 );
  891. memcpy( &(passwd[cbs->startPos]), new, cbs->text->length );
  892. } else {
  893. passwd = new;
  894. }
  895.  
  896. memset( cbs->text->ptr, '*', cbs->text->length ); /* makes it all stars */
  897.  
  898. }
  899.  
  900.  
  901. Thanks to OM1_JDA@pki-nbg.philips.de (Joerg Danne) for alerting me to updating
  902. this code sample. Thanks also to Russell Fink (rfink@polaris.umuc.edu) for
  903. providing the Nov. 1996 code update.
  904.  
  905. -----------------------------------------------------------------------------
  906. Subject: 94)  How can I make a text widget insensitive without graying out the
  907. text?
  908. [Last modified: Dec 98]
  909.  
  910. This is mostly a problem in Motif 1.2 and later, since grayed-out text is
  911. sometimes difficult to read.
  912.  
  913. Instead of making the widget insensitive, set XmNeditable to false.
  914.  
  915. Ken Lee
  916.  
  917. -----------------------------------------------------------------------------
  918. Subject: 95)  How can I best add a large piece of text to a scrolled text
  919. widget?
  920. [Last modified: Sept 94]
  921.  
  922. [NOTE: This problem is probably only relevant for Motif 1.0 which probably no
  923. one is using anymore. If you know this to still be a problem, send mail to
  924. kenton@nojunk.rahul.net. I'll probably remove this question otherwise.]
  925.  
  926. In some versions of Motif 1.0 even using XmTextSetString, it insists on adding
  927. the text one line at a time, adjusting the scroll bar each time. It looks
  928. awful and is slow.
  929.  
  930. Answer: If you don't have this problem, use XmTextSetString to set all of the
  931. text in the widget.  If you do have this slowdown problem even using
  932. XmTextSetString, unmanage the widget, add the text and then manage it again.
  933. This may cause the window to blink, but you have to put up with that or switch
  934. to a different version of Motif.
  935.  
  936. -----------------------------------------------------------------------------
  937. Subject: 96)  How can I get the correct colors for scrolled text widget
  938. scrollbars (Sun only)?
  939. [Last modified: Nov 97]
  940.  
  941. Answer: Michael Hall <mhall@semy.com> writes:
  942.  
  943. I have found a fix to a bug which is common on SUN platforms.  The problem is
  944. that the scroll bars on scrolled text widgets are not colored or shaded
  945. correctly.
  946.  
  947.  
  948. scrolledWindowText2 = XtVaCreateManagedWidget("scrolledWindowText2",
  949.     xmScrolledWindowWidgetClass,
  950.     form1,
  951.     XmNscrollBarDisplayPolicy, XmSTATIC,
  952.     NULL );
  953.  
  954. runValuesText = XtVaCreateManagedWidget("runValuesText",
  955.     xmTextWidgetClass,
  956.     scrolledWindowText2,
  957.     XmNeditMode, XmMULTI_LINE_EDIT ,
  958.     XmNeditable, FALSE,
  959.     NULL );
  960.  
  961. /* workaround a Motif bug - text widget scroll bars are wrong color,
  962. and not shaded. */
  963. /* by Michael Hall */
  964.  
  965. /* just to get background */
  966. junkScroll = XmCreateScrollBar(form1, "junkScroll", NULL, 0);
  967. XtVaGetValues(junkScroll,
  968.     XmNbackground, &junkPixel,
  969.     NULL);
  970. XtVaGetValues(XtParent(runValuesText),
  971.     XmNchildren, &kids,
  972.     XmNnumChildren, &numkids,
  973.     NULL);
  974. for (n=0;n<numkids;n++)
  975. {
  976. if (XmIsScrollBar(kids[n]))
  977. {
  978.  XtVaSetValues(kids[n],
  979.    XmNbackground, junkPixel,
  980.    XmNshadowThickness, 30,
  981.    XmNwidth, 200,
  982.    XmNheight, 200,
  983.    NULL);
  984.  XmChangeColor(kids[n], junkPixel);
  985. }
  986. }
  987.  
  988.  
  989. -----------------------------------------------------------------------------
  990. Subject: 97)  How can I highlight text in the Text widget?
  991.  
  992. Answer: argv@zipcode.com (Dan Heller) wrote:
  993.  
  994. If you don't need font or color changes, you can do all this using a Text
  995. widget very easily [in Motif 1.1, anyway].
  996.  
  997. loop() {
  998.     pos = offset_of_pattern_in_text_widget(pattern, text_w);
  999.     search_len = strlen(pattern);
  1000.     XmTextSetHighlight(text_w, pos, pos+search_len,
  1001.                 XmHIGHLIGHT_SELECTED);
  1002. }
  1003.  
  1004.  
  1005. There are two choices for highlighting: reverse video (HIGHLIGHT_SELECTED) and
  1006. underlined (HIGHLIGHT_SECONDARY_SELECTED).  Be careful that your users won't
  1007. confuse your highlights with actual selections!
  1008.  
  1009. -----------------------------------------------------------------------------
  1010. Subject: 98)  How can I select all of the text in a widget programmatically?
  1011. So that some initial text is displayed, but anything typed replaces it.
  1012. [Last modified: July 95]
  1013.  
  1014. Answer: XmTextSetSelection(Text1, 0, XmTextGetLastPosition(Text1), event-
  1015. >xbutton.time);
  1016.  
  1017. where Text1 is the widget in question (obviously) and event is some event that
  1018. triggered this call.  You can use XtLastTimestampProcessed( display) instead
  1019. of xbutton.time if you don't happen to have an event pointer handy.
  1020.  
  1021. Jon A. Christopher (jac8792@tam2000.tamu.edu) writes:
  1022.  
  1023. I have had difficulty getting this to work as described (even though it agrees
  1024. with the documentation).  I believe that it may be because I usually change
  1025. the TextField to some value and then try to select it.  I haven't looked at
  1026. the internals of the TextField widget, but it must only select the text if the
  1027. text hasn't changed since the time specified.  Ususally the
  1028. "LastTimestampProcessed" will be be *before* you modify the text, and the
  1029. selection is therefore ignored.  I'd suggest using the CurrentTime variable.
  1030. This is an X variable which, if used will make sure that your text is always
  1031. selected.
  1032.  
  1033. -----------------------------------------------------------------------------
  1034. Subject: 99)  Can I customize the pointer cursor or insert position indicator
  1035. used by the text widget?
  1036. [Last modified: May 97]
  1037.  
  1038. Answer: No.  These are hard coded.
  1039.  
  1040. Ken Lee
  1041.  
  1042. -----------------------------------------------------------------------------
  1043. Subject: 100)  How can I change colours of text in the Text widget?  I want
  1044. some of the text in one colour, some in another.
  1045. [Last modified: Feb 98]
  1046.  
  1047. Answer: In Motif 1.x, you can't.  Text stores an ordinary string, and points
  1048. where `highlights' of various types begin and end.  These highlights are all
  1049. the control you have over components of the text.
  1050.  
  1051. In the Motif 2.0 CSText widget, XmStrings may be different colors in the same
  1052. widget.
  1053.  
  1054. Note, however, that the CSText widget was dropped from Motif 2.1.
  1055.  
  1056. Ken Lee
  1057.  
  1058. -----------------------------------------------------------------------------
  1059. Subject: 101)  How can I change the font of text in the Text widget?  I want
  1060. some of the text in one font, some in another.
  1061. [Last modified: Feb 98]
  1062.  
  1063. Answer: You can't in Text (see the previous question).  If you wanted readonly
  1064. text, you could do it by using a label instead.  Label uses XmStrings, which
  1065. can contain multiple character sets in the one string.
  1066.  
  1067. If you are using Motif 2.0, however, XmStrings are now permitted in CSText
  1068. widgets, which solves this particular problem.
  1069.  
  1070. Note, however, that the CSText widget was dropped from Motif 2.1.
  1071.  
  1072. Ken Lee
  1073.  
  1074. -----------------------------------------------------------------------------
  1075. Subject: 102)  Is there an emacs binding for the text widget?
  1076.  
  1077. Answer: This set is due to Kee Hinckley:
  1078.  
  1079. *XmText.translations: #override\n\
  1080. Ctrl <Key>b:            backward-character()\n\
  1081. Alt <Key>b:             backward-word()\n\
  1082. Meta <Key>b:            backward-word()\n\
  1083. Shift Alt <Key>b:       backward-word(extend)\n\
  1084. Shift Meta <Key>b:      backward-word(extend)\n\
  1085. Alt <Key>[:             backward-paragraph()\n\
  1086. Meta <Key>[:            backward-paragraph()\n\
  1087. Shift Alt <Key>[:       backward-paragraph(extend)\n\
  1088. Shift Meta <Key>[:      backward-paragraph(extend)\n\
  1089. Alt <Key><:             beginning-of-file()\n\
  1090. Meta <Key><:            beginning-of-file()\n\
  1091. Ctrl <Key>a:            beginning-of-line()\n\
  1092. Shift Ctrl <Key>a:      beginning-of-line(extend)\n\
  1093. Ctrl <Key>osfInsert:    copy-clipboard()\n\
  1094. Shift <Key>osfDelete:   cut-clipboard()\n\
  1095. Shift <Key>osfInsert:   paste-clipboard()\n\
  1096. Alt <Key>>:             end-of-file()\n\
  1097. Meta <Key>>:            end-of-file()\n\
  1098. Ctrl <Key>e:            end-of-line()\n\
  1099. Shift Ctrl <Key>e:      end-of-line(extend)\n\
  1100. Ctrl <Key>f:            forward-character()\n\
  1101. Alt <Key>]:             forward-paragraph()\n\
  1102. Meta <Key>]:            forward-paragraph()\n\
  1103. Shift Alt <Key>]:       forward-paragraph(extend)\n\
  1104. Shift Meta <Key>]:      forward-paragraph(extend)\n\
  1105. Ctrl Alt <Key>f:        forward-word()\n\
  1106. Ctrl Meta <Key>f:       forward-word()\n\
  1107. Ctrl <Key>d:            kill-next-character()\n\
  1108. Alt <Key>BackSpace:     kill-previous-word()\n\
  1109. Meta <Key>BackSpace:    kill-previous-word()\n\
  1110. Ctrl <Key>w:            key-select() kill-selection()\n\
  1111. Ctrl <Key>y:            unkill()\n\
  1112. Ctrl <Key>k:            kill-to-end-of-line()\n\
  1113. Alt <Key>Delete:        kill-to-start-of-line()\n\
  1114. Meta <Key>Delete:       kill-to-start-of-line()\n\
  1115. Ctrl <Key>o:            newline-and-backup()\n\
  1116. Ctrl <Key>j:            newline-and-indent()\n\
  1117. Ctrl <Key>n:            next-line()\n\
  1118. Ctrl <Key>osfLeft:      page-left()\n\
  1119. Ctrl <Key>osfRight:     page-right()\n\
  1120. Ctrl <Key>p:            previous-line()\n\
  1121. Ctrl <Key>g:            process-cancel()\n\
  1122. Ctrl <Key>l:            redraw-display()\n\
  1123. Ctrl <Key>osfDown:      next-page()\n\
  1124. Ctrl <Key>osfUp:        previous-page()\n\
  1125. Ctrl <Key>space:        set-anchor()
  1126.  
  1127.  
  1128. ! If you'd like the Delete key to work like backspace instead of deleting
  1129. ! backwards, add the following definition to the lines above.
  1130. !       <Key>osfDelete: delete-previous-character()\n\
  1131.  
  1132. ! These aren't included because they could intefere with
  1133. | menu accelerators (or vice versa)
  1134. !       Alt <Key>p:             backward-paragraph()\n\
  1135. !       Meta <Key>p:            backward-paragraph()\n\
  1136. !       Shift Alt<Key>p:        backward-paragraph(extend)\n\
  1137. !       Shift Meta<Key>p:       backward-paragraph(extend)\n\
  1138. !       Alt <Key>w:             copy-clipboard()\n\
  1139. !       Meta <Key>w:            copy-clipboard()\n\
  1140. !       Ctrl Alt <Key>w:        cut-clipboard()\n\
  1141. !       Ctrl Meta <Key>w:       cut-clipboard()\n\
  1142. !       Alt <Key>y:             paste-clipboard()\n\
  1143. !       Meta <Key>y:            paste-clipboard()\n\
  1144. !       Alt <Key>f:             forward-word()\n\
  1145. !       Meta <Key>f:            forward-word()\n\
  1146. !       Alt <Key>n:             forward-paragraph()\n\
  1147. !       Meta <Key>n:            forward-paragraph()\n\
  1148. !       Shift Alt <Key>n:       forward-paragraph(extend)\n\
  1149. !       Shift Meta <Key>n:      forward-paragraph(extend)\n\
  1150. !       Shift Alt <Key>f:       forward-word(extend)\n\
  1151. !       Shift Meta <Key>f:      forward-word(extend)\n\
  1152. !       Alt <Key>d:             kill-next-word()\n\
  1153. !       Meta <Key>d:            kill-next-word()\n\
  1154. !       Alt <Key>h:             select-all()\n\
  1155. !       Meta <Key>h:            select-all()\n\
  1156.  
  1157. Similar sets of translations have been suggested by others.
  1158.  
  1159. -----------------------------------------------------------------------------
  1160. Subject: 103)  What if I have problems with the backspace/delete keys?
  1161. [Last modified: Dec 94]
  1162.  
  1163. Answer: mclarnon@maths.ox.ac.uk (Gerald.McLarnon) writes:
  1164.  
  1165. I am running a precompiled program based on motif and am having some problems
  1166. with the backspace/delete keys. Following the instructions of the faq I put th
  1167. e following lines in my .Xdefaults file
  1168.  
  1169. *XmText.translations: #override      <Key>osfDelete: delete-previous-character()
  1170. *XmTextField.translations: #override         <Key>osfDelete: delete-previous-character()
  1171.  
  1172. This meant that in dialogue boxes (such as 'Open File') the delete key deleted
  1173. to the left, but not in the main application window.
  1174.  
  1175. Any hints for someone who isn't much of an X-pert?
  1176.  
  1177. David Kaelbling <drk@x.org> replied:
  1178.  
  1179. There are a couple possibilities.  In addition to the precedence of loading
  1180. resource files (explained in section 2.3 of the X11R5 X Toolkit Intrinsics
  1181. manual), resource values in the database are chosen based on a "most explicit
  1182. match" algorithm (i.e. those with the most qualifiers on the left hand side
  1183. win -- see section 15.2 of the X11R5 Xlib - C Library manual).  So if this
  1184. application's app-defaults file or fallback resources says
  1185. *Foo*XmText.translations:... that value will be used instead of yours.
  1186.  
  1187. Find the app-defaults file for your application and look to see if it
  1188. specifies translations for text widgets in the main application; if it does
  1189. you'll need to make yours at least as explicit.
  1190.  
  1191. If the app-defaults file isn't the problem then the application may be hard-
  1192. wiring the translations.  If that's the case you'll probably have to change
  1193. your virtual key bindings so that the key you think of as osfDelete is really
  1194. osfBackSpace.  You can do that for an individual application by setting its
  1195. defaultVirtualBindings resource, or for all Motif applications with a
  1196. $HOME/.motifbind file ("man xmbind" and "man VirtualBindings" give more detail
  1197. and alternatives).  In either case you'll need to specify a complete list of
  1198. virtual key bindings; there is no equivalent to #override.  To find out your
  1199. current virtual key bindings run "xprop -root | fgrep BINDINGS" and clean up
  1200. the result.
  1201.  
  1202. -----------------------------------------------------------------------------
  1203. Subject: 104)  How can I use a file as the text source for a Text widget?
  1204.  
  1205. Answer: You can't do it directly like you can with the Athena Text widget.
  1206. Instead, read the text from the file into a string (all of it!) and then use
  1207. XmTextSetString.  Alternatively, read blocks of characters and add them at the
  1208. end of the text using XmTextInsertString.  The following is an excerpt from
  1209. Dan Heller's "file_browser.c":
  1210.  
  1211. /* file_browser.c -- use a ScrolledText object to view the
  1212. * contents of arbitrary files chosen by the user from a
  1213. * FileSelectionDialog or from a single-line text widget.
  1214. */
  1215.  
  1216. struct stat statb;
  1217.  
  1218. /* make sure the file is a regular text file and open it */
  1219. if (stat(filename, &statb) == -1 ||
  1220.     (statb.st_mode & S_IFMT) != S_IFREG ||
  1221.     !(fp = fopen(filename, "r"))) {
  1222. if ((statb.st_mode & S_IFMT) == S_IFREG)
  1223.     perror(filename); /* send to stderr why we can't read it */
  1224. else
  1225.     fprintf(stderr, "%s: not a regular file\n", filename);
  1226. XtFree(filename);
  1227. return;
  1228. }
  1229.  
  1230. /* put the contents of the file in the Text widget by allocating
  1231. * enough space for the entire file, reading the file into the
  1232. * allocated space, and using XmTextFieldSetString() to show the file.
  1233. */
  1234. if (!(text = XtMalloc((unsigned)(statb.st_size+1)))) {
  1235. fprintf(stderr, "Can't alloc enough space for %s", filename);
  1236. XtFree(filename);
  1237. fclose(fp);
  1238. return;
  1239. }
  1240.  
  1241. if (!fread(text, sizeof(char), statb.st_size+1, fp))
  1242. fprintf(stderr, "Warning: may not have read entire file!\n");
  1243.  
  1244. text[statb.st_size] = 0; /* be sure to NULL-terminate */
  1245.  
  1246. /* insert file contents in Text widget */
  1247. XmTextSetString(text_w, text);
  1248.  
  1249.  
  1250. -----------------------------------------------------------------------------
  1251. Subject: 105)  How can put Text in overstrike mode instead of insert?
  1252. [Last modified: Mar 95]
  1253.  
  1254. Answer: (Be sure to read the update after the first answer. This is also a
  1255. second update which cautions against the approach.)
  1256.  
  1257. There is no direct way. This was posted by Edmond Pitt (ejp@bohra.cpg.oz) The
  1258. correct answer to the question is to put the following in a modifyVerify
  1259. callback, where 'mvcb' is the XmTextVerifyCallbackStruct, and 'overstriking'
  1260. is defined by you:
  1261.  
  1262. if (overstriking && mvcb->text->length == 1)
  1263. {
  1264. _XmTextDisableRedisplay(w,FALSE);
  1265. XtCallActionProc(w,"delete-next-character",mvcb->event,0);
  1266. _XmTextEnableRedisplay(w);
  1267. }
  1268.  
  1269. _XmText{Dis,En}ableRedisplay() are XmText{Dis,En}ableRedisplay() in 1.0, but
  1270. X11R3 has no XtCallActionProc() anyway. For this environment you need my 1.0.3
  1271. Text widget patches posted last year & available on request.
  1272.  
  1273. An update was provided by Ingeborg (inca@osf.org):
  1274.  
  1275. In 1.2 and later releases, there is an action function toggle-overstrike()
  1276. which will toggle between overstrike and insert mode. Before 1.2.3, there is
  1277. no visual difference, and at most one character will get overstruck. In 1.2.3,
  1278. a block cursor was added as a visual cue to that the widget is in overstrike
  1279. mode, and the code was fixed to overstrike the actual number of characters
  1280. input (this makes a difference if you have preediting - for example in
  1281. japanese).
  1282.  
  1283. There is no default binding in 1.2, but the recommended key is osfInsert
  1284. without modifiers.  No resource exists.
  1285.  
  1286.  
  1287. Ed Kaltenbach (kaltenba@ataway.aptec.com) wrote:
  1288.  
  1289. I was simulating overstrike mode in the Text Field widget by using
  1290. the delete_next_character solution listed in subject 71.
  1291. When the software is compiled with Motif 1.2.2, the modifyVerify
  1292. callback does not get called for the last character when XmNmaxLength
  1293. is specified.  It seems that the check if maxLength has been reached
  1294. is done before the modifyVerify gets called and it keeps the modifyVerify
  1295. from being called.  Is this a Motif bug? Does anybody have a solution that
  1296. will work with Versions 1.1 and 1.2 of Motif?
  1297.  
  1298.  
  1299. Phil Day <phil@cfmu.eurocontrol.be> responded to Ed (and apologized for only
  1300. sending pseudocode!):
  1301.  
  1302. I've had the same problem, and for my money it's a bug.  My workaround is to
  1303. make all text widgets (I don't use textfield because of some other problems in
  1304. the past) have XmNmaxLength > XmNcolumns, so that the modifyVerify callback
  1305. gets a chance to do its stuff.
  1306.  
  1307. If you only want to support overstrike for typing, 1 extra charater is enough,
  1308. but if you want to support cut-and-paste for any length string you need
  1309. maxLength = 2*columns.  In the modifyVerify you have to check the result is <
  1310. columns.
  1311.  
  1312. I've tried using the Motif 1.2 support for overstrike, but this just seems to
  1313. work on a kind of pending-delete and only works for the single charater
  1314. replacement caes (that's my main argument for calling it a bug).
  1315.  
  1316. I don't use delete-next-character (I can't remember why just now, but I know I
  1317. had some problem with it).  Instead I have something like the following:
  1318.  
  1319. modifyVerify()
  1320. {
  1321. if (acceptable)
  1322.         XmReplaceText(...)
  1323.  
  1324. cd->doit = False;
  1325. // we've just done it, we don't wnat Motif to !
  1326.  
  1327. XtVaSetValues (w,
  1328.            XmNverifyBell, False,
  1329.            NULL);
  1330. // Otherwise we'll get a beep.
  1331. }
  1332.  
  1333. valueChanged()
  1334. {
  1335.  
  1336. XtVaSetValues (w,
  1337.            XmNverifyBell, True,
  1338.            NULL);
  1339. // turned off in modifyVerify
  1340.  
  1341. }
  1342.  
  1343. Glenn Mandelkern <gmandel@Corp.Megatest.Com> writes about a problem with the
  1344. above solution.
  1345.  
  1346.  
  1347. We have been running our software on Sparc 20's, under Motif 1.1
  1348. and Motif 1.2, X11R5, Solaris 2.4.
  1349. Unfortunately, some colleagues and I have found a disturbing side effect
  1350. when following this suggestion.  Calling XtVaSetValues() in the
  1351. modifyVerifyCallback causes the Text widget to flash.
  1352.  
  1353. The O'Reilly guides say not to call XtVaSetValues() during text
  1354. modification callbacks.  Motif Volume 6 has this on page 511 and
  1355. Motif Volume 6A has it on page 496.
  1356.  
  1357. I myself thought it would be fairly trivial to just switch the bell
  1358. on and off.  But since XtVaSetValues() calls XmText's set_values() method,
  1359. my guess is that its set_values() does something that causes this.
  1360.  
  1361. So when you enter characters, the Text widget flashes.  It also slows
  1362. down the performance of the Text widget.  You'll see this on a multi-line
  1363. Text widget, especially with it occupying a full screen with text.
  1364.  
  1365. If you want to see this, take the editor.c program in Volume 6 or 6A,
  1366. then add a modifyVerifyCallback to the text_output widget.  Then inside
  1367. that callback, call XtVaSetValues with the XmNverifyBell like above.
  1368.  
  1369. This is a common "mistake", one which I've done more than once.
  1370. I remember also that when I did not have the XtVaSetValues() in place,
  1371. I got the beeps.
  1372.  
  1373. So now we've reworked the application as follows:
  1374. 1.  The Text widget is initially created with XmNverifyBell
  1375.     set to False.
  1376.  
  1377. 2.  We ring the bell using XBell() when we detect a condition
  1378.     for which we want to veto text modifications.
  1379.  
  1380. For our application, this provides the wanted feedback and gets rid
  1381. of the flashes.
  1382.  
  1383.  
  1384. -----------------------------------------------------------------------------
  1385. Subject: 106)  How can I make the Delete key do a Backspace?  Related
  1386. question: How can I swap Delete and Backspace?
  1387. [Last modified: Oct 94]
  1388.  
  1389. Answer: Put this in your .Xdefaults
  1390.  
  1391. *XmText.translations: #override <Key>osfDelete: delete-previous-character()
  1392.  
  1393.  
  1394. Additional information from David Kaelbling <drk@x.org>:
  1395.  
  1396. You can also supply an arbitrary file name to xmbind (so you can conditionally
  1397. run xmbind from your .xinitrc file based on the hostname, architecture,
  1398. xdpyinfo output, or whatever).
  1399.  
  1400. Some people prefer to use xmodmap to swap the keysyms for all applications,
  1401. but what you're doing will work fine if you specify all of the virtual key
  1402. bindings.  The current bindings are stored on the root window -- use "xprop
  1403. -root" and look for a _MOTIF_BINDINGS or _MOTIF_DEFAULT_BINDINGS property.
  1404. OSF/Motif is also distributed with a "bindings" directory containing all the
  1405. fallback virtkey binding files.
  1406.  
  1407. There are several ways to do display-specific customization: make
  1408.  
  1409. -----------------------------------------------------------------------------
  1410. Subject: 107)  Can I change the tab stops in the XmText widget?
  1411. [Last modified: May 95]
  1412.  
  1413. Answer: No.
  1414.  
  1415. Ken Lee
  1416.  
  1417. -----------------------------------------------------------------------------
  1418. END OF PART FOUR
  1419.