home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************
- "help.c"
-
- by John A. Love, III [ Washington Apple Pi Users' Group]
-
- using Symantec's "THINK C", v 5.00
- *********************************************************/
-
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #include "protos"
-
- #include "globals.h"
- #include "extern.h"
-
- #include "about.h"
- #include "floatingWindow.h"
-
-
- // Local prototypes:
-
- OSErr ShowMyNewBalloon (Rect *altRect,
- Ptr tipProc,
- short strID,
- short strIndex,
- short theProc,
- short variant,
- short method);
-
-
- Point mouse;
- short notMine = -1;
- extern DialogPtr helpPtr;
- extern WindowPeek frontToolWindow,
- backToolWindow,
- frontDocWindow;
-
-
-
-
- Boolean HelpManagerActive (void) {
- /* Do we have a machine on which the Help Manager exists ??? */
-
- short _Gestalt = 0xA1AD;
- long myFeature;
- Boolean result;
-
-
- result = false;
- ;
- if (TrapAvailable(_Gestalt)) {
- if (Gestalt(gestaltHelpMgrAttr, &myFeature) == noErr) {
- if (BitTst(&myFeature, 31 - gestaltHelpMgrPresent)) result = true;
- }
- }
-
- return(result);
-
- } /* HelpManagerActive */
-
-
-
- Boolean BalloonsOn (void) {
- /* Has the user selected "Show Balloons" ??? */
-
- return(HelpManagerActive() && HMGetBalloons());
-
- } /* BalloonsOn */
-
-
-
- Boolean BalloonShowing (void) {
- /* Is a Balloon currently showing ??? */
-
- return(HelpManagerActive() && HMIsBalloon());
-
- } /* BalloonShowing */
-
-
-
- void HideBalloons (Boolean balloonsUp) {
-
- OSErr soWhat;
-
-
- if (balloonsUp) {
- /* Get the daggum monster out of the way !! */
- /* Used "hmSaveBitsNoWindow option" so bits */
- /* are restored withOUT an update Event. */
- if (BalloonShowing()) soWhat = HMRemoveBalloon();
-
- /* Okay, I've restored the bits. However, now */
- /* I've got to temporarily disable Balloon Help */
- /* until I leave with a Mouse Up Event or finish */
- /* with whatever: */
- soWhat = HMSetBalloons(false);
- ;
- gLastBalloon = -1;
- } /* "Show Balloons" active */
-
- } /* HideBalloons */
-
-
- void ShowBalloons (Boolean balloonsUp) {
- /* NOW !!! I can safely re-enable Balloon Help: */
-
- OSErr soWhat;
-
-
- if (balloonsUp) soWhat = HMSetBalloons(true);
-
- } /* ShowBalloons */
-
-
-
- void ResetBalloons (Boolean balloonsUp) {
-
- if (balloonsUp) ShowBalloons(true);
- else HideBalloons(HelpManagerActive());
-
- } /* ResetBalloons */
-
-
-
- OSErr ShowMyNewBalloon (Rect *altRect,
- Ptr tipProc,
- short strID,
- short strIndex,
- short theProc,
- short variant,
- short method) {
-
- HMMessageRecord helpMsg;
- Point tip;
- Rect cyAltRect;
-
-
- /* See comment besides "nil" passed to HMShowBalloon below:
-
- // ... so we don't change the input Rect:
- cyAltRect = *altRect;
- LocalGlobal(&cyAltRect);
-
- // If we centered the tip and the window is partially
- // hidden by, say, a Floating Window, the tip may end
- // up pointing to the Floating Window:
-
- /*
- // Center the tip:
- SetPt(&tip,
- (cyAltRect.right + cyAltRect.left)/2,
- (cyAltRect.bottom + cyAltRect.top )/2);
- */
- GetMouse(&tip);
- LocalToGlobal(&tip);
-
- // Fill in HMMessageRecord:
- helpMsg.hmmHelpType = khmmStringRes;
- helpMsg.u.hmmStringRes.hmmResID = strID;
- helpMsg.u.hmmStringRes.hmmIndex = strIndex;
- ;
- return ( HMShowBalloon(&helpMsg, tip,
- nil, /* If I pass &cyAltRect, the Help Manager
- ** will attempt to re-calculate the tip.
- ** This is exactly what I do NOT want
- ** because of the possibility that a
- ** Floating Window may be covering part
- ** of a DLOG item in which case the
- ** re-calculated tip may end up pointing
- ** to the Floating Window. */
- tipProc, theProc, variant, method) );
-
- } /* ShowMyNewBalloon */
-
-
-
- void FindAndShowDynamicBalloons (Boolean balloonsUp) {
-
- short stdWDEF = 0, defVar = 0;
- short activeOtherWindow = 1000;
-
- GrafPtr savePort;
- WindowPtr inWindow;
- short i, iType, part;
- Handle iHandle;
- Rect iBox, inactiveBox;
- ControlHandle iCtl;
- Boolean inHelpRect = false;
- extern ViewMode Last_Type;
- extern short Current_Topic;
-
-
- if ( !balloonsUp ||
- EventAvail(updateMask, &gEvent) /* "Switch-A_Roo" problem */ ) {
- gLastBalloon = notMine;
- return;
- }
-
- mouse = gEvent.where;
- part = FindWindow(mouse, &inWindow);
-
- if (part != inContent) return;
-
- else { /* mouse is in a window somewhere */
-
- GetPort(&savePort);
- SetPort(inWindow);
-
- GlobalToLocal(&mouse);
-
- if ( ((WindowPeek)inWindow)->hilited ) {
- /* mouse in front, or active window */
- if (inWindow != helpPtr) {
- if (gLastBalloon != activeOtherWindow) {
-
- /* ... any active NON-Help Window stuff goes here.
- ** Remember, ALL Tool Windows are active. Because
- ** of the nature of these beasts, however, it's
- ** probably best to let 'hrct' resources
- ** "do their thing". */
-
-
-
- gLastBalloon = activeOtherWindow;
- }
- } /* mouse in some other active window */
-
- else /* mouse in active Help Window */ {
-
- for (i = OK_Button; i <= Message_Area*2; i++)
- { /* Use the appropriate strings for disabled items: */
-
- if ( (i == OK_Button*2) || (i == Topics_Area*2) )
- // NO Balloons for disabled case:
- continue;
-
- else if ( (i == (Display_Area-1)*2 + 1) &&
- (Current_Topic != Initial_Picture) )
- continue;
-
- else if ( i == (Next_Button-1)*2 + 1 ) {
- GetDItem(helpPtr, Next_Button, &iType, &iHandle, &iBox);
- iCtl = (ControlHandle)iHandle;
- /* If hidden, skip BOTH strings.
- ** If de-activated, skip just one: */
- if ( ((**iCtl).contrlVis == 0) ) {
- // Skips both because continue does another i++:
- i++;
- continue;
- }
- else if ( ((**iCtl).contrlHilite == OFF) )
- continue;
- }
-
- else if ( i == (Prev_Button-1)*2 + 1 ) {
- GetDItem(helpPtr, Prev_Button, &iType, &iHandle, &iBox);
- iCtl = (ControlHandle)iHandle;
- if ( ((**iCtl).contrlVis == 0) ) {
- i++;
- continue;
- }
- else if ( ((**iCtl).contrlHilite == OFF) )
- continue;
- }
-
- else if (i == (Mast_Head-1)*2 + 1)
- // NO Balloon for enabled case:
- continue;
-
- else if (i == (Message_Area-1)*2 + 1) {
- if (Last_Type == text)
- continue;
- else /* a pict */ if (Current_Topic == Initial_Picture)
- /* Since the Message_Area is last in the DITL,
- ** i += 2 would take i beyond its maximum value
- ** BEFORE being tested by for(...). */
- break;
- }
-
- inHelpRect = PtInRect(mouse, &gDynamicBalloons[i].dynamicR);
- if (inHelpRect) {
- if (i != gLastBalloon) {
-
- if (ShowMyNewBalloon
- (
- &gDynamicBalloons[i].dynamicR,
- nil,
- gDynamicBalloons[i].dynamicStrID,
- gDynamicBalloons[i].dynamicStrIndex,
- stdWDEF,
- defVar,
- kHMRegularWindow
- ) == noErr) gLastBalloon = i;
- else gLastBalloon = notMine;
-
- }
- break /* out of for-loop */ ;
- } /* inHelpRect */
-
- } /* for */
-
- if (!inHelpRect /* NOT in any of them */ ) {
- /* I pass "nil" to HMShowBalloon -- see IM6: */
- (void) HMRemoveBalloon();
- gLastBalloon = notMine;
- }
-
- } /* else: mouse in active Help Window */
-
- } /* Cursor in SOME active window */
-
- else /* Cursor in an inactive window */ {
-
- /* The 'hovr' resource handles this case. */
-
- } /* Cursor in SOME inactive window */
-
- SetPort(savePort);
-
- } /* Mouse is somewhere in a window */
-
- } /* FindAndShowDynamicBalloons */
-
-
-
-
- /* { end file "help.c" } */
-