From: sglanger@vela.acs.oakland.edu (LANGER STEVEN C)
Subject: Heller update
Organization: Oakland University, Rochester MI.
Distribution: na
Date: Sun, 24 Jan 1993 15:49:16 GMT

Hi netter's;
  Here is the latest update. Keep the contributions coming.
  This list has been forwarded to O'Reilly and Assoc.
--steve


******************************************************************
Since Dan Heller's book (Vol. 6 Motif Programming Manual) is arguably
the Bible of this group, I think it would be a benefit to all of us to 
keep a running list of the typos, errors and points that could maybe
profit from a little clarification. This will help the readers of this
group profit from other's experience and (since I will send this update
periodically to O'Reilly and Assoc.) will help Dan Heller when the
second edition rolls around. I volunteer to update this list as you
fellow readers send me your suggestions.

As to format, I've already been informed that the page numbers I quote
do not match with others, so I suggest the following

Example  Chapter-number		program.c

	5-10 lines of code around the point in question with
        the trouble spot underlined thus
-------------------------------------^

  Your description of the problem and the code showing the solution.

Remember, every clarification reported here will help someone avoid the 
pain you had to go through ;-) 

I'd also like to thank Jeffrey Wood, Bob Hays, Chris Pirson, S. Ramakrishnan,
Mark Lanzo and Dan Heller for the advice which they selflessly doled out to me 
during the initial steep climb up the "X learning curve".

***********************************************************************

Example 5-5 	the PostDialog routine

PostDialog (Widget parent, int dialog_type, char *msg)
{
	Widget dialog;
	XmString text;

	dialog = XmCreateMessageDialog (parent, "dialog", NULL, 0);
	text = XmStringCreateSimple (dialog, msg);
----------------------------------------------^
this will not compile, XmStringCreateSimple only takes char *msg

should be
	text = XmStringCreateSimple (msg);

**********************************************************************

Example 5-10		the askuser routine

	/* While the user hasn't provided an answer, simulate main loop
	*
	*
	*/

	while (answer == 0)
		XtAppProcessEvents (app, XtIMAll);
---------------------------------^
will not compile, the function is XtAppProcessEvent

**********************************************************************

Example 17-4   		wm_delete.c

	/* several problems in here */

void activate (Widget w)
{
	Widget dialog, shell;
	*
	*
	Atom WM_DELETE_WINDOW;	


	*
	*
	dialog = XmCreateWarningDialog (w, "notice", args, 2);
	*
	*
	XtManageChild (dialog);

	/* Add a callback for the WM_DELETE_WINDOW protocol */
	shell = XtParent (dialog);
	WM_DELETE_WINDOW = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", 
				False);
	XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, cbfunc, dialog);
----------------------------------------------------------------^
will not compile without a (XtPointer) cast in front of dialog

The other problem is less obvious. While fixing the cast will get this
code to work, changing dialog to a XmCreateDialogShell results in the
following X-warning (at dialog creation)

Warning: must be a vendor shell

And the callback function is never called. Same situation for any
other XmCreate function except XmCreateWarningDialog and
XmCreateInformationDialog.
This despite the fact that we used an XmCreate routine. The problem is
that this example uses shell in the ProtocolCallback. Instead use

	WM_DELETE_WINDOW = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", 
				False);
	XmAddWMProtocolCallback(dialog, WM_DELETE_WINDOW, cbfunc,
						(XtPointer) dialog);

and forget about the shell. Then all works well for Motif 1.2.
However, new information from Adam (below) further muddies the water.



Steven,

I tried using the fix-its for wm_delete, based on your Heller update, in one of
my applications and they didn't work.  The primary reason for this was that
XmAddWMProtocolCallback() doesn't pass the required protocol to the protocol
manager.  This seems to be the case for motif-1.1.

To get this to work you have to add a call to XmAddWMProtocols() before you
call XmAddWMProtocolCallback(), so the corrected code should read:

    shell = XtParent(dialog);
    WM_DELETE_WINDOW = XmInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW", True);
    XmAddWMProtocols(shell, &WM_DELETE_WINDOW, 1);
    XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, cbfunc, (XtPointer) dialog);

The reason you're getting the message:

    Warning: must be a vendor shell

is because protocol interaction must be from a vendor shell (ie the top level
shell) for it to work.  So both XmAddWMProtocols() and
XmAddWMProtocolCallback() need to reference _shell_.  It seems like you can use
either _shell_ or _w_ with XmInternAtom() -- either seem to work.

There are definatly many ambiguities which give no rational as to which
permutations work and those that don't.

Please can you add the example above to your Heller updates.  Thanks for being
the custodian of the updates, I've certainly found them very useful.

Cheers,
Adam Hudd               adam@dadhb1.ti.com             __o
Texas Instruments Inc,                                -\<,
Houston, TX                                     .....O / O

	[Steve again: I make no pretense at understanding what works
	[when. Just be aware of possible version dependancies.
**********************************************************************
Example  15-8   editor.c   (page 504 in my book)

  else {
        /* make sure a newline terminates file */
        if (text[-1] != '\n')
     	      fputc(fp, '\n');
-------------------^^^^^^^

These arguments are in reverse order of what they should be.

Scott	Grosch 	   	  	        	Internet: garath@engin.umich.edu
Programmer   	          	  	        Bitnet: user7a4b@umichum
Computer Aided Engineering Network              University of Michigan

*****************************************************************************

Section: 11.1.5

	Example 11-2. The xcal.c program  Page # 366 (in my book)

In main(), local variable month_no should be initialized (to 1).

While,

% xcal                       initializes month_no
% xcal 1993                  does not.

This is a potential bug as month_no is passed to XmListSelectPos() later
in main() procedure.

		XmListSelectPos(w, month_no, True);

Problem Code: In main()

	int i, month_no ;

It should be,

	int 1, month_no = 1 ; /* or any number in the range 1 - 12 */

-Vadi
vadi@csi.com
**************************************************************************
Example 8-10       frame.c

  This one gave me real fits, and I don't have a fix for it because I 
think the bug is in the Label widget itself (Motif 1.2).

	frame = XtVaCreateManagedWidget ("frame", xmFrameWidgetClass,
			parent, XmNshadowType, XmSHADOW_IN, NULL);

	XtVaCreateManagedWidget ("SHADOW_IN", xmLabelGadgetClass, frame, NULL);
---------------------------------------------^
what follows is true for xmLabelWidgetClass as well

I adapted this fragment to put a real time clock on the bottom of my
mainWindow and the program kept core dumping. What made it difficult to track
was the dbx traceback which informed me that the blow-up occured inside

	XtAppMainLoop (DispatchEvent to be precise)

I hunted for a day for the cause, thinking that I was doing something
wrong with the XtAppAddTimeout callback which updated the clock every second.
Finally, I came back to the above and tried overiding the automatic
C to compound string conversion as in the code fragments in Section 11.1.2
I used both the
	XmStringCreateSimple and XtVaTypedArg methods.

Same result. Core dump at XtAppMainLoop. I ended up abandoning the Label
widget alltogether and replaced it with a framed DrawingArea (ala the
above example.) I then rendered the text into it manually using
	XDrawString.

This has worked beautifully. Moral? If you have similar problems,
consider a DrawingArea.
	   
*************************************************************************
-- 
Steve Langer  			       sglanger@argo.acs.oakland.edu (VMS)
Oakland University		       sglanger@vela.acs.oakland.edu (Ultrix)
---------------------------------------------------------------------------
Standard disclaimers apply. In addition, the author makes no guarantees,
concerning the grammatical accuracy of his writing. Therefore, any ^B's, ^C's, 
midword character additions/deletions and other non-sense which occurs (after 
the work leaves the author's decade old text editor via his decade old Amiga, 
struggles through a local 1200 baud Merit server to be further mauled via the 
remote VAX mail servers) is someone elses problem - namely yours.
---------------------------------------------------------------------------