[comp.sys.mac.programmer] Calling WDefProcs Manually

rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) (03/22/89)

    Here's an interesting problem. Suppose you are calling FindWindow to
determine the window and part of a window that was clicked after getting
a mouseDown event. One would call (in LSC):

    WindowPart = FindWindow(TheEvent->where, &TheWindow);

    You may then determine if the title bar of a window was clicked upon
by simply:

    if (WindowPart == inDrag) ...
    Unless the window that was clicked on is a DA window, then the above
statement is false, because (WindowPart == inSysWindow).
    The problem is that I need to determine if the title bar of a window
was clicked regardless if it is an application's window, or a system
window (DA).
    I devised the following solution, but it does not work. Consider:

    if (WindowPart == inSysWindow) {
        VarCode = GetWVariant(TheWindow);
        Result = CallPascalL(VarCode, TheWindow, wHit, TheEvent->where,
            *((WindowPeek) TheWindow)->windowDefProc);
        ...
        }

    Result is defined as a long, and VarCode is an int.
    The theory behind this statement is that I will call the windowDefProc
myself, passing all of the neccessary information to it, and it will tell
me if the title bar (dragRgn) was hit.
    Problem: Result is always zero (0). This is especially confusing to
me because the reason that this statement is called is because the event
detected a mouseDown in a window, and then the windowDefProc turns around
and says that the window was NOT hit.
    Anybody have any idea why this is not working?
    Thank you.

    Rob Johnston.

jackiw@cs.swarthmore.edu (Nick Jackiw) (03/23/89)

In article <AY9iCNy00VE10-dWJ3@andrew.cmu.edu> rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) writes:
>     I devised the following solution, but it does not work. Consider:
[Source code deleted; attempting to determine how to detect in-title-bar
hits on a DA window (and therefore a window for which FindWindow always
returns inSysWindow).]
>     Anybody have any idea why this is not working?
>     Rob Johnston.

Not offhand. But you might want to try instead checking whether the pt
lies within the windows strucRgn but not in its contentRgn. This'll tell
you if the hit is in the frame or "inside" the window. (Note: Although
structure-content includes the WHOLE frame, i. e. title bar+rectangular
outline+optional dropshadow, I don't think FindWindow reports any hits
in the non-titlebar frame.)








-- 
+-------------------+-jackiw@cs.swarthmore.edu / !rutgers!bpa!swatsun!jackiw-+
|  nicholas jackiw  | jackiw%campus.swarthmore.edu@swarthmr.bitnet           |
+-------------------+-VGP/MathDept/Swarthmore College, Swarthmore, PA 19081--+
"Ah...I've got this CHRONIC pain."                             _True Believer_

tecot@Apple.COM (Ed Tecot) (03/30/89)

In article <AY9iCNy00VE10-dWJ3@andrew.cmu.edu> rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) writes:
>    The problem is that I need to determine if the title bar of a window
>was clicked regardless if it is an application's window, or a system
>window (DA).
>    I devised the following solution, but it does not work. Consider:
>
>    if (WindowPart == inSysWindow) {
>        VarCode = GetWVariant(TheWindow);
>        Result = CallPascalL(VarCode, TheWindow, wHit, TheEvent->where,
>            *((WindowPeek) TheWindow)->windowDefProc);
>        ...
>        }
>
>    Result is defined as a long, and VarCode is an int.
>    The theory behind this statement is that I will call the windowDefProc
>myself, passing all of the neccessary information to it, and it will tell
>me if the title bar (dragRgn) was hit.
>    Problem: Result is always zero (0). This is especially confusing to
>me because the reason that this statement is called is because the event
>detected a mouseDown in a window, and then the windowDefProc turns around
>and says that the window was NOT hit.
>    Anybody have any idea why this is not working?

Not any specific ideas, as I'm not familiar with the syntax of CallPascal.
However, you should be locking the definition function before calling it
and restoring the bits afterwards:

	saveHBits := HGetState(defProc);
	HLock(defProc);
	CallPascal...
	HSetState(defProc, saveHBits);

You might want to make sure that CallPascal is passing the parameters to
the definition function correctly.  A little tracing with MacsBug or TMON
should tell you what is going on.

						_emt