osamenus.c

Go to the documentation of this file.
00001 
00002 /*  $Id: osamenus.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 /*Forked. Carbon version at the top, "good" version at the bottom. This file should be
00032 reconciled later.*/
00033 
00034 /*
00035     2004-10-28 aradke: Menusharing won't work on Carbon.
00036     This file is only relevant for the classic Mac OS version.
00037 */
00038 
00039 #if TARGET_API_MAC_CARBON == 1
00040 
00041  
00042 /* Copyright 1992-1993 UserLand Software, Inc.  All Rights Reserved.*/
00043 
00044 #include <land.h>
00045 #include "dialogs.h"
00046 #include "ops.h"
00047 #include "kb.h"
00048 #include "memory.h"
00049 #include "langinternal.h"
00050 #include "langipc.h"
00051 #include "osacomponent.h"
00052 #include "osainternal.h"
00053 #include "osamenus.h"
00054 #include "resources.h"
00055 #include <SetUpA5.h>
00056 
00057 #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00058     #include "aeutils.h"
00059 #endif
00060 
00061 
00062 #define MSglobals ((**hcg).menusharingglobals)
00063 
00064 // 3/7/97 dmb: bumped this constant from 3 to 5
00065 // 9.24/97 dmb: changed this constant to be ticks, not requests
00066 #define tickstoignorerequests 15
00067 
00068 #define tickstocheckformulas 15
00069 
00070 
00071 
00072 static pascal Boolean ProcessInForeground () {
00073     
00074     /*
00075     return true if we're running in the foreground, false if we're in the
00076     background.
00077     */
00078     
00079     ProcessSerialNumber currentprocess, frontprocess;
00080     Boolean fl;
00081     
00082     GetCurrentProcess (&currentprocess);
00083     
00084     GetFrontProcess (&frontprocess);
00085     
00086     SameProcess (&currentprocess, &frontprocess, &fl);
00087     
00088     return (fl);
00089     } /*ProcessInForeground*/
00090 
00091 
00092 static pascal short CountMenuArray (hdlcomponentglobals hcg) {
00093     
00094     /*
00095     return the number of menus in the menu array.
00096     */
00097     
00098     register hdlmenuarray hm = MSglobals.hsharedmenus;
00099     
00100     if (hm == nil)
00101         return (0);
00102     
00103     return ((short) (GetHandleSize ((Handle) hm) / sizeof (tyruntimemenurecord)));
00104     } /*CountMenuArray*/
00105 
00106 
00107 static pascal Boolean InstallSharedMenus (hdlcomponentglobals hcg, short idmenuafter) {
00108     
00109     /*
00110     insert all of the menus in the menuarray into the menu bar.  main 
00111     menus are inserted in front of idmenuafter. if idmenuafter is zero, 
00112     main (non-hierarchic) menus will be added to the right of all others.
00113     */
00114     
00115     register hdlmenuarray hm = MSglobals.hsharedmenus;
00116     register short i, ct;
00117     tyruntimemenurecord item;
00118     
00119     if (MSglobals.installmenuscallback != nil) {
00120         
00121         long appA5 = SetUpCurA5 ();
00122         
00123         CallMSmenuscallbackProc (MSglobals.installmenuscallback, hm);
00124         
00125         RestoreA5 (appA5);
00126         }
00127     else {
00128     
00129         ct = CountMenuArray (hcg);
00130         
00131         for (i = 0; i < ct; i++) {
00132             
00133             item = (**hm) [i];
00134             
00135             if (item.flhierarchic)
00136                 InsertMenu (item.hmenu, -1);
00137             else
00138                 InsertMenu (item.hmenu, idmenuafter);
00139             
00140             (**hm) [i].flinserted = true; /*so we'll know it needs to be removed*/
00141             } /*for*/
00142         }
00143     
00144     return (true);
00145     } /*InstallSharedMenus*/
00146 
00147 
00148 static pascal Boolean GetSharedMenus (hdlcomponentglobals hglobals, short firstresource) {
00149     
00150     /*
00151     call the menu server to get a menuarray, keyed off of our application id.
00152     
00153     firstresource is the starting id to be used for the menus; if there are 
00154     n menus, their ids will range from firstresource to firstresource + n - 1.
00155     
00156     2.1b13 dmb: use new osasethome/clientzone
00157     */
00158     
00159     register hdlcomponentglobals hcg = hglobals;
00160     boolean fl;
00161     hdlmenuarray hsharedmenus = (hdlmenuarray) NewHandle (sizeof (tyruntimemenurecord));
00162     
00163     osasethomezone (hcg);
00164     
00165     fl = langipcgetmenuarray (MSglobals.clientid, firstresource, true, (Handle *) &hsharedmenus);
00166     
00167     osasetclientzone (hcg);
00168     
00169     if (!fl)
00170         return (false);
00171     
00172     MSglobals.hsharedmenus = hsharedmenus;
00173     
00174     return (true);
00175     } /*GetSharedMenus*/
00176 
00177 
00178 static pascal Boolean CheckFormulas (hdlcomponentglobals hglobals) {
00179     
00180     /*
00181     probably should maintain msglobal and do this less often
00182     
00183     2.1b13 dmb: need to use our heap when calcualting formulas. use new 
00184     osasethome/clientzone to do so.
00185     */
00186     
00187     register hdlcomponentglobals hcg = hglobals;
00188     boolean fl;
00189     
00190     ++fldisableyield;   /*dmb 4.1b2 - in case forulas send AEs*/
00191             
00192     osasethomezone (hcg);
00193     
00194     pushhashtable (nil); /*override storage table set up by callosafunction so langrunhandle will set up root*/
00195     
00196     fl = langipccheckformulas (MSglobals.clientid);
00197     
00198     pophashtable ();
00199     
00200     osasetclientzone (hcg);
00201     
00202     --fldisableyield;   /*dmb 4.1b2*/
00203     
00204     return (fl);
00205     } /*CheckFormulas*/
00206 
00207 
00208 static pascal ComponentResult osaSharedScriptRunning (hdlcomponentglobals hcg, Boolean *flrunning) {
00209     
00210     /*
00211     returns true if a shared script is currently running, false otherwise.
00212     
00213     it's provided so that an application can intelligently handle cmd-period
00214     script termination in its keystroke handling routine.
00215     */
00216     
00217     *flrunning = flscriptrunning; /*MSglobals.flscriptrunning*/
00218     
00219     return (noErr);
00220     } /*osaSharedScriptRunning*/
00221 
00222 
00223 static pascal ComponentResult osaCancelSharedScript (hdlcomponentglobals hcg) {
00224     
00225     /*
00226     call this when the user presses cmd-period or otherwise indicates to you that
00227     he or she wants the currently running script to be halted. 
00228         
00229     8/13/92 DW: if we're talking to post-2.0 Frontier or Runtime 1.0, we send a
00230     message to the server telling it to kill the script. otherwise we do it the
00231     old less elegant way, by setting a flag that gets monitored in calls to 
00232     SharedScriptCancelled.
00233     */
00234     
00235     processdisposecode ((hdltreenode) MSglobals.idscript);
00236     
00237     return (noErr);
00238     } /*osaCancelSharedScript*/
00239 
00240 
00241 static pascal ComponentResult osaDisposeSharedMenus (hdlcomponentglobals hglobals) {
00242     
00243     /*
00244     completely dispose of the menuarray and the menu handles it contains.
00245     
00246     10/10/91 DW: check for no shared menus before disposing, save code if 
00247     its ever called from more than one place. also set the global handle to
00248     nil after disposing and redraw the menu bar.
00249     
00250     2.1b13 dmb: we're now called by closesharedmenus, as part of our client's 
00251     ExitToShell procedure. to prevent Menu Manager crashes, we have to make 
00252     sure MenuList isn't nil before deleting a menu. in fact, event disposing a 
00253     menu crashes in this context, so if menulist is nil we'll assume the app 
00254     is shutting down, and just skip that part entirely.
00255     
00256     4.0b7 dmb: set fldirtysharedmenus to true;
00257     */
00258     
00259     register hdlcomponentglobals hcg = hglobals;
00260     register hdlmenuarray hm = MSglobals.hsharedmenus;
00261     register short i;
00262     register short ctmenus;
00263     tyruntimemenurecord item;
00264     //9/1/00 Timothy Paustian
00265     //got rid of nasty use of direct memory access.
00266     //not allowed in carbon
00267     #if TARGET_API_MAC_CARBON == 1
00268     MenuBarHandle MenuList = nil;
00269     MenuList = GetMenuBar();
00270     #else   
00271     #define MenuList (*(Handle *)0xA1C)
00272     #endif
00273             
00274     MSglobals.fldirtysharedmenus = true;    // 4.0b7 dmb: need this for client to have dynamic menubar
00275     
00276     if (hm == nil) /*no shared menus to toss*/
00277         return (noErr);
00278     
00279     if (MenuList != nil) {
00280         
00281         if (MSglobals.removemenuscallback != nil) {
00282         
00283             long appA5 = SetUpCurA5 ();
00284             
00285             CallMSmenuscallbackProc (MSglobals.removemenuscallback, hm);
00286             
00287             RestoreA5 (appA5);
00288             }
00289         
00290         ctmenus = CountMenuArray (hcg);
00291         
00292         for (i = 0; i < ctmenus; i++) {
00293             
00294             item = (**hm) [i];
00295             
00296             if (item.flinserted && (MSglobals.removemenuscallback == nil))
00297                 DeleteMenu (item.idmenu);
00298             
00299             DisposeMenu (item.hmenu);
00300             } /*for*/
00301         
00302         DrawMenuBar ();
00303         }
00304     
00305     langipcdisposemenuarray (MSglobals.clientid, (Handle) hm);
00306     
00307     /*
00308     DisposeHandle ((Handle) hm);
00309     */
00310     
00311     MSglobals.hsharedmenus = nil;
00312     //Code change by Timothy Paustian Tuesday, September 5, 2000 9:26:37 PM
00313     //only dispose of menubars in carbon. In OS 9 the menubar handle is 
00314     //not a copy
00315     #if TARGET_API_MAC_CARBON == 1
00316     DisposeMenuBar(MenuList);
00317     #endif
00318         
00319     return (noErr);
00320     } /*osaDisposeSharedMenus*/
00321 
00322 
00323 static pascal ComponentResult osaCheckSharedMenus (hdlcomponentglobals hglobals, short idinsertafter) {
00324     
00325     /*
00326     call this from your main event loop after receiving and processing every
00327     event. if the menus need updating, we send a message to the server asking
00328     for our shared menus.
00329     
00330     if we load menus, they are assigned resource ids starting with idinsertafter.
00331     this number must be less than 255 to allow for hierarchic menus, and must be
00332     small enough so that no menu has an id of greater than 255. 
00333     
00334     9/28/91 DW: only update menus if we're the front process. this catches the
00335     delay on re-loading a changed menu structure on the Multifinder switch. No
00336     extra burden on the script writer editing the menu bar.
00337     
00338     4.1b6 dmb: decided that the problem where Netscape Navigator, CodeWarrior and 
00339     maybe other apps pick up Frontier's icon in the system Application menu must 
00340     be timing related. Added ctmenurequests, numrequeststoignore logic to make 
00341     sure that the client has called WNE a few times before we serve any menus.
00342     
00343     5.0d19 dmb: chanced ctmenurequests to timefirstrequest, and numrequeststoignore
00344     to tickstoignorerequests, so processor speed would stop breaking the fix
00345     
00346     5.0b6 dmb: added timelastformulacheck logic
00347     */
00348     
00349     register hdlcomponentglobals hcg = hglobals;
00350     unsigned long ticksnow;
00351     
00352     if (!ProcessInForeground ()) /*only update menus if we're the front process*/
00353         return (noErr);
00354     
00355     if (flscriptrunning) /*probably re-intering from eventfilter*/
00356         return (noErr);
00357     
00358     ticksnow = gettickcount ();
00359     
00360     if (!MSglobals.fldirtysharedmenus) { /*no need for an update, return quickly*/
00361         
00362         if (ticksnow - MSglobals.timelastformulacheck > tickstocheckformulas) {
00363             
00364             CheckFormulas (hcg);
00365             
00366             MSglobals.timelastformulacheck = ticksnow;
00367             }
00368         
00369         return (noErr);
00370         }
00371     
00372     if (ticksnow - MSglobals.timefirstrequest <= tickstoignorerequests)
00373         return (noErr);
00374     
00375     osaDisposeSharedMenus (hcg);
00376     
00377     if (GetSharedMenus (hcg, idinsertafter)) {
00378         
00379         InstallSharedMenus (hcg, 0); /*install to the right of all other menus*/
00380         
00381         DrawMenuBar ();
00382         }
00383     
00384     MSglobals.fldirtysharedmenus = false;
00385     
00386     MSglobals.timelastformulacheck = ticksnow;
00387     
00388     return (noErr);
00389     } /*osaCheckSharedMenus*/
00390 
00391 
00392 static pascal ComponentResult osaIsSharedMenu (hdlcomponentglobals hcg, short idmenu, Boolean *flshared) {
00393     
00394     /*
00395     return true if the indicated menu is one of the shared menus.
00396     */
00397     
00398     register hdlmenuarray hm = MSglobals.hsharedmenus;
00399     register short ct, i;
00400     tyruntimemenurecord item;
00401     
00402     ct = CountMenuArray (hcg);
00403     
00404     *flshared = false;
00405     
00406     for (i = 0; i < ct; i++) {
00407         
00408         item = (**hm) [i];
00409         
00410         if (item.idmenu == idmenu) {
00411             
00412             *flshared = true;
00413             
00414             break;
00415             }
00416         } /*for*/
00417     
00418     return (noErr);
00419     } /*osaIsSharedMenu*/
00420 
00421 
00422 static pascal ComponentResult osaEnableSharedMenus (hdlcomponentglobals hcg, Boolean flenable) {
00423     
00424     /*
00425     Enables or disables the the menus in the specified menu array.
00426     
00427     Always returns true.
00428     */
00429     
00430     register hdlmenuarray hm = MSglobals.hsharedmenus;
00431     register short i;
00432     register short ctmenus;
00433     register MenuHandle hmenu;
00434     
00435     ctmenus = CountMenuArray (hcg);
00436     
00437     for (i = 0; i < ctmenus; i++) {
00438         
00439         hmenu = (**hm) [i].hmenu;
00440         //Code change by Timothy Paustian Monday, June 26, 2000 4:16:27 PM
00441         //Update to modern call
00442 
00443         if (flenable)
00444             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00445             EnableMenuItem (hmenu, 0);
00446             #else
00447             EnableItem (hmenu, 0);
00448             #endif
00449         else
00450             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00451             DisableMenuItem (hmenu, 0);
00452             #else
00453             DisableItem (hmenu, 0);
00454             #endif
00455         } /*for*/
00456     
00457     DrawMenuBar ();
00458     
00459     return (noErr);
00460     } /*osaEnableSharedMenus*/
00461 
00462 
00463 static pascal OSErr sharedmenueventfilter (EventRecord *event, long callback) {
00464     
00465     /*
00466     2.1b11 dmb: handle an event for the activeproc or the sendproc
00467     
00468     3.0a dmb: HiliteMenu (0) any time we see an os event so menu 
00469     manager won't get confused when client does it later and it's 
00470     not in front.
00471     
00472     4.1b13 dmb: use new iscmdperiodevent
00473     */
00474     
00475     register EventRecord *ev = event;
00476     long appA5;
00477     
00478     switch ((*ev).what) {
00479         
00480         case keyDown:
00481             if (iscmdperiodevent ((*ev).message, keyDown, (*ev).modifiers))
00482                 return (userCanceledErr);
00483             
00484             break;
00485         
00486         case mouseDown: /*don't let client see these -- can't do menu selection*/
00487             break;
00488         
00489         default:
00490             if ((*ev).what == osEvt) /*3.0a*/
00491                 HiliteMenu (0);
00492             
00493             appA5 = SetUpCurA5 ();
00494             
00495             CallMSeventcallbackProc ((MSeventcallbackUPP) callback, ev);
00496             
00497             RestoreA5 (appA5);
00498             
00499             if ((*ev).what == userCanceledErr)
00500                 return (userCanceledErr);
00501             
00502             break;
00503         }
00504     
00505     return (noErr);
00506     } /*sharedmenueventfilter*/
00507 
00508 
00509 static pascal OSErr sharedmenuactiveproc (long refcon) {
00510     
00511     /*
00512     2.1b10 dmb: the client provided an event filter, which we've stashed 
00513     in the refon.
00514     
00515     on a keypress, see if user pressed cmd-period.
00516     
00517     on system & null events, pass event to caller. if the event comes back 
00518     with the ev.what field set to userCanceledErr, abort the script.
00519     
00520     the client's context is set when we get here, so we need to set up 
00521     our A5 to call anything else
00522     
00523     2.1b13: also call the default activeproc so that we'll see cmd-. 
00524     event there are other events preempting (updates & activates)
00525     */
00526     
00527     EventRecord ev;
00528     OSErr err;
00529     
00530     long curA5 = SetUpAppA5 ();
00531     
00532     WaitNextEvent (keyDownMask | mDownMask | osMask | activMask | updateMask, &ev, 1L, nil);
00533     
00534     err = sharedmenueventfilter (&ev, refcon);
00535     
00536     if (err == noErr)
00537         err = osadefaultactiveproc (0L);
00538     
00539     RestoreA5 (curA5);
00540     
00541     return (err);
00542     } /*sharedmenuactiveproc*/
00543 
00544 
00545 static pascal Boolean sharedmenuidleproc (EventRecord *ev, long *sleep, RgnHandle *mousergn) {
00546     
00547     /*
00548     2.1b10: pass the event through to the client application so it can 
00549     respond to it.
00550     
00551     3.0b15 dmb: see comment in sharedmenusendproc below. the only way to get 
00552     the event filter is to find our globals.
00553     */
00554     
00555     #pragma unused (sleep, mousergn)
00556     
00557     OSErr err = noErr;
00558     long eventfilter;
00559     
00560     long curA5 = SetUpAppA5 ();
00561     
00562     #if TARGET_API_MAC_CARBON == 1
00563     if (osafindclienteventfilter ((long) nil, &eventfilter))
00564         err = sharedmenueventfilter (ev, eventfilter);
00565     #else   
00566     if (osafindclienteventfilter ((long) LMGetCurrentA5 (), &eventfilter))
00567         err = sharedmenueventfilter (ev, eventfilter);
00568     #endif
00569         
00570     RestoreA5 (curA5);
00571     
00572     return (err != noErr); /*false means keep waiting*/
00573     } /*sharedmenuidleproc*/
00574 
00575 
00576 static pascal OSErr sharedmenusendproc (const AppleEvent *, AppleEvent *, AESendMode, AESendPriority, long, AEIdleUPP, AEFilterUPP, long);
00577 
00578 
00579 #if !TARGET_RT_MAC_CFM
00580 
00581     #define sharedmenuactiveprocUPP sharedmenuactiveproc
00582     
00583     #define sharedmenuidleprocUPP sharedmenuidleproc
00584     
00585     #define sharedmenusendprocUPP sharedmenusendproc
00586 
00587 #else
00588 
00589     #if !TARGET_API_MAC_CARBON
00590     static RoutineDescriptor sharedmenuactiveprocDesc = BUILD_ROUTINE_DESCRIPTOR (uppOSAActiveProcInfo, sharedmenuactiveproc);
00591     
00592     static RoutineDescriptor sharedmenuidleprocDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEIdleProcInfo, sharedmenuidleproc); /*4.1b13 dmb: corrected procinfo*/
00593     
00594     static RoutineDescriptor sharedmenusendprocDesc = BUILD_ROUTINE_DESCRIPTOR (uppOSASendProcInfo, sharedmenusendproc);
00595     
00596     #define sharedmenuactiveprocUPP (&sharedmenuactiveprocDesc)
00597     
00598     #define sharedmenuidleprocUPP (&sharedmenuidleprocDesc)
00599     
00600     #define sharedmenusendprocUPP (&sharedmenusendprocDesc)
00601     #else
00602     
00603     OSAActiveUPP    sharedmenuactiveprocDesc;
00604     
00605     AEIdleUPP   sharedmenuidleprocDesc;
00606     
00607     OSASendUPP  sharedmenusendprocDesc;
00608     
00609     #define sharedmenuactiveprocUPP (sharedmenuactiveprocDesc)
00610     
00611     #define sharedmenuidleprocUPP (sharedmenuidleprocDesc)
00612     
00613     #define sharedmenusendprocUPP (sharedmenusendprocDesc)
00614     #endif
00615 
00616     
00617     
00618 #endif
00619 
00620 
00621 static pascal OSErr sharedmenusendproc (const AppleEvent *event, AppleEvent *reply,
00622         AESendMode sendmode, AESendPriority priority, long timeout,
00623         AEIdleUPP idleproc, AEFilterUPP filterproc, long refcon) {
00624     
00625     /*
00626     2.1b11 dmb: the client provided an event filter. we do the same event 
00627     filtering as we do for the activeproc.
00628     
00629     the client's context is set when we get here, so we need to set up 
00630     our A5 to call anything else
00631     
00632     3.0b14 dmb: call osadefaultactiveproc here for cmd-period detection. 
00633     not needed for Frontier scripts, but essential for AppleScript scripts.
00634     
00635     3.0b15 dmb: since the AESend idleProc doesn't get a refcon, we have no way 
00636     to directly pass along our refcon, the eventfilter. we were using a static 
00637     global here, but if one client sends an event while another is waiting for 
00638     a reply, that doesn't work. the best solution I can think of right now is 
00639     for the idleproc to the use the CurrentA5 value to look up the globals for 
00640     this client, and get the eventfilter routine from there.
00641     */
00642     
00643     OSErr err;
00644     
00645     long curA5 = SetUpAppA5 ();
00646     
00647     err = osadefaultactiveproc (0L);
00648     
00649     /*
00650     sharedmenufilterproc = refcon;
00651     */
00652     
00653     idleproc = sharedmenuidleprocUPP;
00654     
00655     RestoreA5 (curA5);
00656     
00657     if (err == noErr)
00658         err = AESend (event, reply, sendmode, priority, timeout, idleproc, filterproc);
00659     
00660     return (err);
00661     } /*sharedmenusendproc*/
00662 
00663 
00664 static boolean sharedmenuprocessevent (EventRecord *ev) {
00665     
00666     /*
00667     4.1b13 dmb: new routine, for new processevent langcallback.
00668     we're only installed if the filterproc is non-nil
00669     
00670     4.1b14 dmb: we must pre/post client callback here.
00671     */
00672     
00673     register hdlcomponentglobals hcg = osaglobals;
00674     long appA5;
00675     
00676     osapreclientcallback (hcg);
00677     
00678     appA5 = SetUpCurA5 ();
00679     //Code change by Timothy Paustian Friday, July 28, 2000 2:58:43 PM
00680     //This stuff is macros and is probably going to give me trouble.
00681     CallMSeventcallbackProc (MSglobals.eventfiltercallback, ev);
00682     
00683     RestoreA5 (appA5);
00684     
00685     osapostclientcallback (hcg);
00686     
00687     return (true);
00688     } /*sharedmenuprocessevent*/
00689 
00690 
00691 static pascal ComponentResult osaRunSharedMenuItem (hdlcomponentglobals hglobals, short idmenu, short iditem) {
00692      
00693     /*
00694     call the menu server to run the script linked to the indicated menu item.
00695     
00696     the script will execute asynchonously, after this call returns.
00697     
00698     SDK 2.0: if the server isn't running, remove the shared menus and return
00699     false. this will only happen if the server has crashed without letting us
00700     know that our menus are dirty.
00701     
00702     2.1b4 dmb: handle langtext signature (i.e. use specific component)
00703     
00704     2.1b6 dmb: if the script is UserTalk, don't go through the generalized 
00705     procedure of opening a component instance. not only is it slow, but the 
00706     initial context for the instance would be all wrong, so operations 
00707     that restore the client context, like osagetnextevent, would break.
00708     
00709     2.1b10 dmb: added support for the new eventfilter callback
00710     
00711     2.1b11 dmb: extended eventfilter support to flow through a sendproc 
00712     as well. also, realized that when the script is not in usertalk, 
00713     the client context needs to be restored in both the activeproc and 
00714     the sendproc.
00715     
00716     2.1b12 dmb: leave fldisableyield in it's original state, just to be safe.
00717     
00718     2.1b13 dmb: use new osasethome/clientzone. also, try setting our zone 
00719     while getting langtext; we seem to be having spurious heap problems, 
00720     and maybe this is it.
00721     
00722     3.0b15 dmb: when OSADoScript returns a script error, it seems that we still 
00723     need to call OSAScriptError to get the error text -- at least for AppleScript 
00724     we do.  (This is counter to my recollection of the DoScript spec, but that's 
00725     how it is.)  Also, initialize result to null, just in case.
00726     
00727     3.0b16 dmb: when the script is non-UserTalk, must set flscriptrunning true 
00728     and false manually.
00729     */
00730     
00731     register hdlcomponentglobals hcg = hglobals;
00732     Handle htext;
00733     long signature;
00734     ComponentInstance comp;
00735     MSeventcallbackUPP eventfilter;
00736     AEDesc desc;
00737     AEDesc result = {typeNull, nil};
00738     long clienta5, appA5;
00739     boolean fl;
00740     bigstring bserror;
00741     OSAError err;
00742     
00743     osasethomezone (hcg);
00744     
00745     fl = langipcgetitemlangtext ((**hcg).clientid, idmenu, iditem, &htext, &signature);
00746     
00747     osasetclientzone (hcg);
00748     
00749     if (htext == nil) /*we must have just displayed script node*/
00750         return (noErr);
00751     
00752     if (!fl)
00753         return (osageterror ());
00754     
00755     desc.descriptorType = typeChar;
00756     
00757     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00758     
00759         newdescwithhandle (&desc, typeChar, htext);
00760     
00761     #else
00762     
00763         desc.dataHandle = htext;
00764     
00765     #endif
00766     
00767     eventfilter = MSglobals.eventfiltercallback;
00768     
00769     if (signature == typeLAND) {
00770         
00771         if (eventfilter != nil) {
00772             
00773             osaSetActiveProc (hcg, sharedmenuactiveprocUPP, (long) eventfilter);
00774             
00775             osaSetSendProc (hcg, sharedmenusendprocUPP, (long) eventfilter);
00776             
00777             langcallbacks.processeventcallback = sharedmenuprocessevent;
00778             }
00779         
00780         err = osaDoScript (hcg, &desc, kOSANullScript, typeChar, kOSANullMode, &result);
00781         
00782         if (eventfilter != nil) {
00783             
00784             osaSetActiveProc (hcg, nil, 0L); /*don't leave this set for when we calc formulas*/
00785             
00786             osaSetSendProc (hcg, nil, 0L);
00787             }
00788         }
00789     else {
00790         
00791         osasethomezone (hcg);
00792         
00793         comp = getosaserver (signature);
00794         
00795         osasetclientzone (hcg);
00796         
00797         if (comp == nil) {
00798             
00799             langostypeparamerror (cantopencomponenterror, signature); /*set the error*/
00800             
00801             osaScriptError (hcg, kOSAErrorMessage, typeChar, &result); /*get the text*/
00802             
00803             err = osageterror (); /*always returns non-zero*/
00804             }
00805         else {
00806             
00807             if (eventfilter != nil) {
00808                 
00809                 OSASetActiveProc (comp, sharedmenuactiveprocUPP, (long) eventfilter);
00810                 
00811                 OSASetSendProc (comp, sharedmenusendprocUPP, (long) eventfilter);
00812                 }
00813             
00814             flscriptrunning = true; /*need to set to block checksharedmenus*/
00815             
00816             clienta5 = osapreclientcallback (hcg);
00817             
00818             #ifdef THINK_C
00819                 
00820                 asm {
00821                     move.l  a5,-(a7)
00822                     move.l  clienta5,a5
00823                     }
00824             
00825             #else
00826             
00827                 appA5 = SetUpCurA5 ();  // SetUpThisA5 (clienta5);  // 4.0b5: was: SetUpCurA5 ();
00828             
00829             #endif
00830             
00831             err = OSADoScript (comp, &desc, kOSANullScript, typeChar, kOSANullMode, &result);
00832             
00833             if ((err == errOSAScriptError) && (result.descriptorType == typeNull)) { /*need error text*/
00834                 
00835                 if (OSAScriptError (comp, kOSAErrorNumber, typeLongInteger, &result) == noErr) {
00836                     
00837                     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00838                         
00839                         {
00840                         Handle hcopy;
00841                         
00842                         copydatahandle (&result, &hcopy);
00843                         
00844                         err = **(long **) hcopy;
00845                         
00846                         disposehandle (hcopy);
00847                         }
00848                                     
00849                     #else
00850                     
00851                         err = **(long **) result.dataHandle; /*can't call numberfromhandle w/out our a5*/
00852                     
00853                     #endif
00854                     
00855                     AEDisposeDesc (&result);
00856                     }
00857                 
00858                 if (err != userCanceledErr)
00859                     OSAScriptError (comp, kOSAErrorMessage, typeChar, &result);
00860                 }
00861             
00862             RestoreA5 (appA5);
00863             
00864             osapostclientcallback (hcg);
00865             
00866             flscriptrunning = false; /*unblock checksharedmenus*/
00867             
00868             if (eventfilter != nil) {
00869                 
00870                 OSASetActiveProc (comp, nil, 0L); /*clear it out*/
00871                 
00872                 OSASetSendProc (comp, nil, 0L);
00873                 }
00874             }
00875         }
00876     
00877     osasethomezone (hcg);
00878     
00879     AEDisposeDesc (&desc);
00880     
00881     osasetclientzone (hcg);
00882     
00883     if ((err != noErr) && (err != userCanceledErr) && (result.descriptorType == typeChar)) {
00884         
00885         #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00886         
00887             datahandletostring (&result, bserror);
00888         
00889         #else
00890         
00891             texthandletostring (result.dataHandle, bserror);
00892         
00893         #endif
00894         
00895         if (MSglobals.scripterrorcallback == nil) {
00896             
00897             osainstallpatch (hcg);
00898             
00899             osasethomezone (hcg);
00900             
00901             ++fldisableyield; /*shellactivate, at least, needs this in this context*/
00902             
00903             alertdialog (bserror);
00904             
00905             --fldisableyield; /*restore*/
00906             
00907             osasetclientzone (hcg);
00908             
00909             osaremovepatch (hcg, nil);
00910             }
00911         else {
00912             clienta5 = osapreclientcallback (hcg);
00913             
00914             #ifdef THINK_C
00915             
00916             asm {
00917                 move.l  a5,-(a7)
00918                 move.l  clienta5,a5
00919                 }
00920                 
00921                 (*(tyMSstringcallback)MSglobals.scripterrorcallback) (bserror);
00922             
00923             #else
00924             
00925                 appA5 = SetUpCurA5 ();  // SetUpThisA5 (clienta5);  // 4.0b5: was: SetUpCurA5 ();
00926                 
00927                 CallMSstringcallbackProc (MSglobals.scripterrorcallback, bserror);
00928                 
00929             #endif
00930             
00931             RestoreA5 (appA5);
00932             
00933             osapostclientcallback (hcg);
00934             }
00935         }
00936     
00937     AEDisposeDesc (&result);
00938     
00939     return (err);
00940     } /*osaRunSharedMenuItem*/
00941 
00942 
00943 static pascal ComponentResult osaSetScriptErrorCallback (hdlcomponentglobals hglobals, MSstringcallbackUPP errorcallback) {
00944     
00945     register hdlcomponentglobals hcg = hglobals;
00946     
00947     MSglobals.scripterrorcallback = errorcallback;
00948     
00949     return (noErr);
00950     } /*osaSetScriptErrorCallback*/
00951 
00952 
00953 static pascal ComponentResult osaSetEventFilterCallback (hdlcomponentglobals hglobals, MSeventcallbackUPP eventcallback) {
00954     
00955     /*
00956     2.1b10 dmb: new routine to allow some background operations to go on 
00957     while a shared menu script is running
00958     */
00959     
00960     register hdlcomponentglobals hcg = hglobals;
00961     
00962     MSglobals.eventfiltercallback = eventcallback;
00963     
00964     return (noErr);
00965     } /*osaSetEventFilterCallback*/
00966 
00967 
00968 static pascal ComponentResult osaSetMenusInserterCallback (hdlcomponentglobals hglobals, MSmenuscallbackUPP callback) {
00969     
00970     /*
00971     2.1b10 dmb: new routine to allow some background operations to go on 
00972     while a shared menu script is running
00973     */
00974     
00975     register hdlcomponentglobals hcg = hglobals;
00976     
00977     MSglobals.installmenuscallback = callback;
00978     
00979     return (noErr);
00980     } /*osaSetMenusInserterCallback*/
00981 
00982 
00983 static pascal ComponentResult osaSetMenusRemoverCallback (hdlcomponentglobals hglobals, MSmenuscallbackUPP callback) {
00984     
00985     /*
00986     2.1b10 dmb: new routine to allow some background operations to go on 
00987     while a shared menu script is running
00988     */
00989     
00990     register hdlcomponentglobals hcg = hglobals;
00991     
00992     MSglobals.removemenuscallback = callback;
00993     
00994     return (noErr);
00995     } /*osaSetMenusRemoverCallback*/
00996 
00997 
00998 static pascal ComponentResult osaSharedMenuHit (hdlcomponentglobals hglobals, short idmenu, short iditem, Boolean *flhit) {
00999 
01000     register hdlcomponentglobals hcg = hglobals;
01001     OSErr err;
01002     
01003     err = osaIsSharedMenu (hcg, idmenu, flhit);
01004     
01005     if (err == noErr) {
01006         
01007         if (*flhit)
01008             err = osaRunSharedMenuItem (hcg, idmenu, iditem);
01009         }
01010     
01011     return (err);
01012     } /*osaSharedMenuHit*/
01013 
01014 
01015 static boolean removemenusharinghandlers (hdlcomponentglobals); /*forward*/
01016 
01017 
01018 static pascal ComponentResult osaDirtySharedMenus (hdlcomponentglobals hglobals) {
01019     
01020     /*
01021     2.1b8 dmb: toss dirty menus now; the component may be gone by the time 
01022     we're frontmost & try to refresh them. in order to do this, we now need 
01023     to set up a5.
01024     
01025     3.0b16 dmb: added call to closeosaservers. since Frontier may be going 
01026     away while the client sticks around, this is the only reliable place to 
01027     get rid of those instances -- 36K of memory for AppleScript
01028     
01029     4.1b2 dmb: broke this code out of HandleMenuDirty so that it can be called
01030     directly by a (4.1-aware) menusharing client
01031     
01032     4.1b12 dmb: reset MSglobals.ctmenurequests when we dirty them, so client 
01033     will have to ask a few times after switching in.
01034     */
01035     
01036     register hdlcomponentglobals hcg = hglobals;
01037     
01038 // 4.0b7 dmb: now done by osaDisposeSharedMenus --  MSglobals.fldirtysharedmenus = true;
01039     
01040     long curA5 = SetUpAppA5 ();
01041     
01042     osaDisposeSharedMenus (hcg); /*2.1b8: toss them now*/
01043     
01044     if (flosashutdown) {
01045         
01046         removemenusharinghandlers (hcg);
01047         
01048         closeosaservers ();
01049         
01050         MSglobals.clientid = 0; /*so servingsharedmenus can break out of loop*/
01051         }
01052     
01053     MSglobals.timefirstrequest = gettickcount (); /*4.1b12*/
01054     
01055     RestoreA5 (curA5);
01056     
01057     return (noErr);
01058     } /*osaDirtySharedMenus*/
01059 
01060 
01061 static pascal OSErr HandleMenuDirty (const AppleEvent *event, AppleEvent *reply, UInt32 refcon) {
01062     
01063     /*
01064     this Apple event handler is called when the application's menu bar has been 
01065     edited by the script writer in the menu server's menu editor.
01066     
01067     4.1b2 dmb: call osaDirtySharedMenus, which does what we used to do directly.
01068     */
01069     
01070     #pragma unused (event, reply)
01071 
01072     osaDirtySharedMenus ((hdlcomponentglobals) refcon);
01073     
01074     return (noErr);
01075     } /*HandleMenuDirty*/
01076 
01077 
01078 #if !TARGET_RT_MAC_CFM
01079 
01080     #define HandleMenuDirtyUPP HandleMenuDirty
01081 
01082 #else
01083 
01084     #if !TARGET_API_MAC_CARBON
01085     static RoutineDescriptor HandleMenuDirtyDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEEventHandlerProcInfo, HandleMenuDirty);
01086     #else
01087     AEEventHandlerUPP  HandleMenuDirtyDesc;
01088     #endif
01089 
01090     #define HandleMenuDirtyUPP (&HandleMenuDirtyDesc)
01091 
01092 #endif
01093 
01094 
01095 static boolean installmenusharinghandlers (hdlcomponentglobals hglobals) {
01096     
01097     register hdlcomponentglobals hcg = hglobals;
01098     OSErr err;
01099     
01100     #if TARGET_API_MAC_CARBON && TARGET_RT_MAC_CFM
01101     HandleMenuDirtyDesc = NewAEEventHandlerUPP(HandleMenuDirty);
01102     #endif
01103     err = AEInstallEventHandler (MSglobals.clientid, 'updm', HandleMenuDirtyUPP, (long) hcg, false);
01104     
01105     /*
01106     err = AEInstallEventHandler (MSglobals.clientid, 'done', (EventHandlerProcPtr) &HandleScriptComplete, (long) hglobals, false);
01107     */
01108     
01109     return (err == noErr);
01110     } /*installmenusharinghandlers*/
01111 
01112 
01113 static boolean removemenusharinghandlers (hdlcomponentglobals hglobals) {
01114     
01115     register hdlcomponentglobals hcg = hglobals;
01116     OSErr err;
01117     
01118     err = AERemoveEventHandler (MSglobals.clientid, 'updm', HandleMenuDirtyUPP, false);
01119     
01120     /*
01121     err = AERemoveEventHandler (MSglobals.clientid, 'done', (EventHandlerProcPtr) &HandleScriptComplete, false);
01122     */
01123     
01124     return (err == noErr);
01125     } /*removemenusharinghandlers*/
01126 
01127 
01128 
01129 
01130 static pascal ComponentResult menucandofunction (short selector) {
01131     
01132     switch (selector) {
01133         
01134         case kComponentOpenSelect:
01135         case kComponentCloseSelect:
01136         case kComponentCanDoSelect:
01137         case kComponentVersionSelect:
01138         
01139         case msInitSharedMenusCommand:
01140         case msSharedMenuHitCommand:
01141         case msSharedScriptRunningCommand:
01142         case msCancelSharedScriptCommand:
01143         case msCheckSharedMenusCommand:
01144         case msDisposeSharedMenusCommand:
01145         case msIsSharedMenuCommand:
01146         case msEnableSharedMenusCommand:
01147         case msRunSharedMenuItemCommand:
01148         case msSetScriptErrorCallbackCommand:
01149         case msSetEventFilterCallbackCommand:
01150         case msSetMenusInserterCallbackCommand:
01151         case msSetMenusRemoverCallbackCommand:
01152         case msDirtySharedMenusCommand:
01153             return (true);
01154         }
01155     
01156     return (false);
01157     } /*menucandofunction*/
01158 //Code change by Timothy Paustian Wednesday, July 26, 2000 9:52:26 PM
01159 //A forward declaration to satify the compiler. I had to move things
01160 //around a bit to get the carbon version to work.
01161 static pascal ComponentResult osaInitSharedMenus (hdlcomponentglobals hglobals);
01162 
01163 #if !TARGET_RT_MAC_CFM
01164     
01165     #define menucandofunctionUPP    ((ComponentFunctionUPP) menucandofunction)
01166     #define osaInitSharedMenusUPP   ((ComponentFunctionUPP) osaInitSharedMenus)
01167     #define osaSharedMenuHitUPP ((ComponentFunctionUPP) osaSharedMenuHit)
01168     #define osaSharedScriptRunningUPP   ((ComponentFunctionUPP) osaSharedScriptRunning)
01169     #define osaCancelSharedScriptUPP    ((ComponentFunctionUPP) osaCancelSharedScript)
01170     #define osaCheckSharedMenusUPP  ((ComponentFunctionUPP) osaCheckSharedMenus)
01171     #define osaDisposeSharedMenusUPP    ((ComponentFunctionUPP) osaDisposeSharedMenus)
01172     #define osaIsSharedMenuUPP  ((ComponentFunctionUPP) osaIsSharedMenu)
01173     #define osaEnableSharedMenusUPP ((ComponentFunctionUPP) osaEnableSharedMenus)
01174     #define osaRunSharedMenuItemUPP ((ComponentFunctionUPP) osaRunSharedMenuItem)
01175     #define osaSetScriptErrorCallbackUPP    ((ComponentFunctionUPP) osaSetScriptErrorCallback)
01176     #define osaSetEventFilterCallbackUPP    ((ComponentFunctionUPP) osaSetEventFilterCallback)
01177     #define osaSetMenusInserterCallbackUPP  ((ComponentFunctionUPP) osaSetMenusInserterCallback)
01178     #define osaSetMenusRemoverCallbackUPP   ((ComponentFunctionUPP) osaSetMenusRemoverCallback)
01179     #define osaDirtySharedMenusUPP  ((ComponentFunctionUPP) osaDirtySharedMenus)
01180 
01181 #else
01182 
01183     enum {
01184         menucandofunctionProcInfo = kPascalStackBased
01185              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01186              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01187              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
01188     };
01189     
01190     enum {
01191         osaInitSharedMenusProcInfo = kPascalStackBased
01192              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01193              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01194     };
01195     
01196     enum {
01197         osaSharedMenuHitProcInfo = kPascalStackBased
01198              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01199              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01200              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
01201              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
01202              | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(Boolean *)))
01203     };
01204     
01205     enum {
01206         osaSharedScriptRunningProcInfo = kPascalStackBased
01207              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01208              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01209              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
01210              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
01211     };
01212     
01213     enum {
01214         osaCancelSharedScriptProcInfo = kPascalStackBased
01215              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01216              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01217     };
01218     
01219     enum {
01220         osaCheckSharedMenusProcInfo = kPascalStackBased
01221              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01222              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01223              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
01224     };
01225     
01226     enum {
01227         osaDisposeSharedMenusProcInfo = kPascalStackBased
01228              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01229              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01230     };
01231     
01232     enum {
01233         osaIsSharedMenuProcInfo = kPascalStackBased
01234              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01235              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01236              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
01237              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean *)))
01238     };
01239     
01240     enum {
01241         osaEnableSharedMenusProcInfo = kPascalStackBased
01242              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01243              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01244              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Boolean)))
01245     };
01246     
01247     enum {
01248         osaRunSharedMenuItemProcInfo = kPascalStackBased
01249              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01250              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01251              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
01252              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
01253     };
01254     
01255     enum {
01256         osaSetScriptErrorCallbackProcInfo = kPascalStackBased
01257              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01258              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01259              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSstringcallbackUPP)))
01260     };
01261     
01262     enum {
01263         osaSetEventFilterCallbackProcInfo = kPascalStackBased
01264              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01265              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01266              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSeventcallbackUPP)))
01267     };
01268     
01269     enum {
01270         osaSetMenusInserterCallbackProcInfo = kPascalStackBased
01271              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01272              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01273              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSmenuscallbackUPP)))
01274     };
01275     
01276     enum {
01277         osaSetMenusRemoverCallbackProcInfo = kPascalStackBased
01278              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01279              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01280              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSmenuscallbackUPP)))
01281     };
01282     
01283     enum {
01284         osaDirtySharedMenusProcInfo = kPascalStackBased
01285              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
01286              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
01287     };
01288     
01289     #if !TARGET_API_MAC_CARBON
01290     static RoutineDescriptor menucandofunctionDesc = BUILD_ROUTINE_DESCRIPTOR (menucandofunctionProcInfo, menucandofunction);
01291     static RoutineDescriptor osaInitSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaInitSharedMenusProcInfo, osaInitSharedMenus);
01292     static RoutineDescriptor osaSharedMenuHitDesc = BUILD_ROUTINE_DESCRIPTOR (osaSharedMenuHitProcInfo, osaSharedMenuHit);
01293     static RoutineDescriptor osaSharedScriptRunningDesc = BUILD_ROUTINE_DESCRIPTOR (osaSharedScriptRunningProcInfo, osaSharedScriptRunning);
01294     static RoutineDescriptor osaCancelSharedScriptDesc = BUILD_ROUTINE_DESCRIPTOR (osaCancelSharedScriptProcInfo, osaCancelSharedScript);
01295     static RoutineDescriptor osaCheckSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaCheckSharedMenusProcInfo, osaCheckSharedMenus);
01296     static RoutineDescriptor osaDisposeSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaDisposeSharedMenusProcInfo, osaDisposeSharedMenus);
01297     static RoutineDescriptor osaIsSharedMenuDesc = BUILD_ROUTINE_DESCRIPTOR (osaIsSharedMenuProcInfo, osaIsSharedMenu);
01298     static RoutineDescriptor osaEnableSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaEnableSharedMenusProcInfo, osaEnableSharedMenus);
01299     static RoutineDescriptor osaRunSharedMenuItemDesc = BUILD_ROUTINE_DESCRIPTOR (osaRunSharedMenuItemProcInfo, osaRunSharedMenuItem);
01300     static RoutineDescriptor osaSetScriptErrorCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetScriptErrorCallbackProcInfo, osaSetScriptErrorCallback);
01301     static RoutineDescriptor osaSetEventFilterCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetEventFilterCallbackProcInfo, osaSetEventFilterCallback);
01302     static RoutineDescriptor osaSetMenusInserterCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetMenusInserterCallbackProcInfo, osaSetMenusInserterCallback);
01303     static RoutineDescriptor osaSetMenusRemoverCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetMenusRemoverCallbackProcInfo, osaSetMenusRemoverCallback);
01304     static RoutineDescriptor osaDirtySharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaDirtySharedMenusProcInfo, osaDirtySharedMenus);
01305     
01306     #define menucandofunctionUPP (&menucandofunctionDesc)
01307     #define osaInitSharedMenusUPP (&osaInitSharedMenusDesc)
01308     #define osaSharedMenuHitUPP (&osaSharedMenuHitDesc)
01309     #define osaSharedScriptRunningUPP (&osaSharedScriptRunningDesc)
01310     #define osaCancelSharedScriptUPP (&osaCancelSharedScriptDesc)
01311     #define osaCheckSharedMenusUPP (&osaCheckSharedMenusDesc)
01312     #define osaDisposeSharedMenusUPP (&osaDisposeSharedMenusDesc)
01313     #define osaIsSharedMenuUPP (&osaIsSharedMenuDesc)
01314     #define osaEnableSharedMenusUPP (&osaEnableSharedMenusDesc)
01315     #define osaRunSharedMenuItemUPP (&osaRunSharedMenuItemDesc)
01316     #define osaSetScriptErrorCallbackUPP (&osaSetScriptErrorCallbackDesc)
01317     #define osaSetEventFilterCallbackUPP (&osaSetEventFilterCallbackDesc)
01318     #define osaSetMenusInserterCallbackUPP (&osaSetMenusInserterCallbackDesc)
01319     #define osaSetMenusRemoverCallbackUPP (&osaSetMenusRemoverCallbackDesc)
01320     #define osaDirtySharedMenusUPP (&osaDirtySharedMenusDesc)
01321     
01322     #else //TARGET_API_MAC_CARBON
01323     ComponentRoutineUPP     menucandofunctionDesc;
01324     ComponentRoutineUPP     osaInitSharedMenusDesc;
01325     ComponentRoutineUPP     osaSharedMenuHitDesc;
01326     ComponentRoutineUPP     osaSharedScriptRunningDesc;
01327     ComponentRoutineUPP     osaCancelSharedScriptDesc;
01328     ComponentRoutineUPP     osaCheckSharedMenusDesc;
01329     ComponentRoutineUPP     osaDisposeSharedMenusDesc;
01330     ComponentRoutineUPP     osaIsSharedMenuDesc;
01331     ComponentRoutineUPP     osaEnableSharedMenusDesc;
01332     ComponentRoutineUPP     osaRunSharedMenuItemDesc;
01333     ComponentRoutineUPP     osaSetScriptErrorCallbackDesc;
01334     ComponentRoutineUPP     osaSetEventFilterCallbackDesc;
01335     ComponentRoutineUPP     osaSetMenusInserterCallbackDesc;
01336     ComponentRoutineUPP     osaSetMenusRemoverCallbackDesc;
01337     ComponentRoutineUPP     osaDirtySharedMenusDesc;
01338     
01339     #define menucandofunctionUPP (menucandofunctionDesc)
01340     #define osaInitSharedMenusUPP (osaInitSharedMenusDesc)
01341     #define osaSharedMenuHitUPP (osaSharedMenuHitDesc)
01342     #define osaSharedScriptRunningUPP (osaSharedScriptRunningDesc)
01343     #define osaCancelSharedScriptUPP (osaCancelSharedScriptDesc)
01344     #define osaCheckSharedMenusUPP (osaCheckSharedMenusDesc)
01345     #define osaDisposeSharedMenusUPP (osaDisposeSharedMenusDesc)
01346     #define osaIsSharedMenuUPP (osaIsSharedMenuDesc)
01347     #define osaEnableSharedMenusUPP (osaEnableSharedMenusDesc)
01348     #define osaRunSharedMenuItemUPP (osaRunSharedMenuItemDesc)
01349     #define osaSetScriptErrorCallbackUPP (osaSetScriptErrorCallbackDesc)
01350     #define osaSetEventFilterCallbackUPP (osaSetEventFilterCallbackDesc)
01351     #define osaSetMenusInserterCallbackUPP (osaSetMenusInserterCallbackDesc)
01352     #define osaSetMenusRemoverCallbackUPP (osaSetMenusRemoverCallbackDesc)
01353     #define osaDirtySharedMenusUPP (osaDirtySharedMenusDesc)
01354     #endif
01355 
01356 #endif
01357 
01358 static pascal ComponentResult closesharedmenus (hdlcomponentglobals hglobals) {
01359     
01360     /*
01361     2.1b8 dmb: new routine to be called by cmpclose for cleanup
01362     
01363     2.1b13 dmb: dispose shared menus here so that langipcmenus can 
01364     release the associated data structures, which would otherwise 
01365     be linked to menus in the heap that's about to disappear.
01366     
01367     3.0b16 dmb: added call to closeosaservers. osaservers are now 
01368     managed on a per-process basic, so this cleanup helps.
01369     */
01370     
01371     register hdlcomponentglobals hcg = hglobals;
01372     
01373     //Code change by Timothy Paustian Friday, July 21, 2000 11:32:00 PM
01374     //get rid of the UPPs
01375     #if TARGET_API_MAC_CARBON && TARGET_RT_MAC_CFM
01376     DisposeComponentFunctionUPP(menucandofunctionDesc);
01377     DisposeComponentFunctionUPP(osaInitSharedMenusDesc);
01378     DisposeComponentFunctionUPP(osaSharedMenuHitDesc);
01379     DisposeComponentFunctionUPP(osaSharedScriptRunningDesc);
01380     DisposeComponentFunctionUPP(osaCancelSharedScriptDesc);
01381     DisposeComponentFunctionUPP(osaCheckSharedMenusDesc);
01382     DisposeComponentFunctionUPP(osaDisposeSharedMenusDesc);
01383     DisposeComponentFunctionUPP(osaIsSharedMenuDesc);
01384     DisposeComponentFunctionUPP(osaEnableSharedMenusDesc);
01385     DisposeComponentFunctionUPP(osaRunSharedMenuItemDesc);
01386     DisposeComponentFunctionUPP(osaSetScriptErrorCallbackDesc);
01387     DisposeComponentFunctionUPP(osaSetEventFilterCallbackDesc);
01388     DisposeComponentFunctionUPP(osaSetMenusInserterCallbackDesc);
01389     DisposeComponentFunctionUPP(osaSetMenusRemoverCallbackDesc);
01390     DisposeComponentFunctionUPP(osaDirtySharedMenusDesc);
01391     
01392     DisposeOSAActiveUPP(sharedmenuactiveprocDesc);
01393     DisposeAEIdleUPP(sharedmenuidleprocDesc);
01394     DisposeOSASendUPP(sharedmenusendprocDesc);
01395     #endif
01396         if (hcg == nil)
01397         return (invalidComponentID);
01398     
01399     osaDisposeSharedMenus (hcg);
01400     
01401     removemenusharinghandlers (hcg);
01402     
01403     disposecomponentglobals (hcg);
01404     
01405     closeosaservers (); /*3.0b16*/
01406     
01407     return (noErr);
01408     } /*closesharedmenus*/
01409 
01410 
01411 static pascal ComponentResult osaInitSharedMenus (hdlcomponentglobals hglobals) {
01412     
01413     register hdlcomponentglobals hcg = hglobals;
01414     long id;
01415     
01416     #if TARGET_API_MAC_CARBON && TARGET_RT_MAC_CFM
01417     //Code change by Timothy Paustian Friday, July 21, 2000 11:28:35 PM
01418     //create the upps
01419     //I have to dispose of these at shutdown.
01420     menucandofunctionDesc = NewComponentFunctionUPP(menucandofunction, menucandofunctionProcInfo);
01421     osaInitSharedMenusDesc = NewComponentFunctionUPP(osaInitSharedMenus, osaInitSharedMenusProcInfo);
01422     osaSharedMenuHitDesc = NewComponentFunctionUPP(osaSharedMenuHit, osaSharedMenuHitProcInfo);
01423     osaSharedScriptRunningDesc = NewComponentFunctionUPP(osaSharedScriptRunning, osaSharedScriptRunningProcInfo);
01424     osaCancelSharedScriptDesc = NewComponentFunctionUPP(osaCancelSharedScript, osaCancelSharedScriptProcInfo);
01425     osaCheckSharedMenusDesc = NewComponentFunctionUPP(osaCheckSharedMenus, osaCheckSharedMenusProcInfo);
01426     osaDisposeSharedMenusDesc = NewComponentFunctionUPP(osaDisposeSharedMenus, osaDisposeSharedMenusProcInfo);
01427     osaIsSharedMenuDesc = NewComponentFunctionUPP(osaIsSharedMenu, osaIsSharedMenuProcInfo);
01428     osaEnableSharedMenusDesc = NewComponentFunctionUPP(osaEnableSharedMenus, osaEnableSharedMenusProcInfo);
01429     osaRunSharedMenuItemDesc = NewComponentFunctionUPP(osaRunSharedMenuItem, osaRunSharedMenuItemProcInfo);
01430     osaSetScriptErrorCallbackDesc = NewComponentFunctionUPP(osaSetScriptErrorCallback, osaSetScriptErrorCallbackProcInfo);
01431     osaSetEventFilterCallbackDesc = NewComponentFunctionUPP(osaSetEventFilterCallback, osaSetEventFilterCallbackProcInfo);
01432     osaSetMenusInserterCallbackDesc = NewComponentFunctionUPP(osaSetMenusInserterCallback, osaSetMenusInserterCallbackProcInfo);
01433     osaSetMenusRemoverCallbackDesc = NewComponentFunctionUPP(osaSetMenusRemoverCallback, osaSetMenusRemoverCallbackProcInfo);
01434     osaDirtySharedMenusDesc = NewComponentFunctionUPP(osaDirtySharedMenus, osaDirtySharedMenusProcInfo);
01435                 
01436     sharedmenuactiveprocDesc = NewOSAActiveUPP(sharedmenuactiveproc);
01437     
01438     sharedmenuidleprocDesc = NewAEIdleUPP(sharedmenuidleproc);
01439     
01440     sharedmenusendprocDesc = NewOSASendUPP(sharedmenusendproc);
01441     #endif
01442         
01443     if (hcg == nil)
01444         return (invalidComponentID);
01445     
01446     id = (**hcg).clientid;
01447     
01448     MSglobals.serverid = typeLAND; /*Frontier's creator id*/
01449     
01450     MSglobals.clientid = id;
01451     
01452     MSglobals.hsharedmenus = nil; /*haven't loaded shared menus yet*/
01453     
01454     MSglobals.fldirtysharedmenus = true; /*force update 1st time thru event loop*/
01455     
01456     MSglobals.flhavecomponentmanager = true;
01457     
01458     MSglobals.timefirstrequest = gettickcount (); /*5.0d19*/
01459     
01460     installmenusharinghandlers (hcg);
01461     
01462     return (noErr);
01463     } /*osaInitSharedMenus*/
01464 
01465 static pascal ComponentResult menusharingdispatch (register ComponentParameters *params, Handle storage) {
01466     
01467     /*
01468     2.1b9 dmb: new dispatcher; menu sharing component now completely 
01469     seperate from OSA
01470     */
01471     
01472     ComponentResult result = badComponentSelector;
01473     short what = (*params).what;
01474     
01475     if (what < 0) { /*negative selectors are component manager calls*/
01476         
01477         switch (what) {
01478             
01479             case kComponentOpenSelect: { /*can't call subroutine because a5 isn't ours*/
01480                 
01481                 hdlcomponentglobals hglobals;
01482                 Component self = (Component) (*params).params [0];
01483                 long selfa5;
01484                 long clienta5;
01485                 
01486                 selfa5 = GetComponentRefcon (self);
01487                 
01488                 #ifdef THINK_C
01489                     
01490                     asm {
01491                         move.l  a5,clienta5
01492                         move.l  a5,-(a7)
01493                         move.l  selfa5,a5
01494                         }
01495                     
01496                 #else
01497                 
01498                     clienta5 = SetUpAppA5 ();
01499                     
01500                     #if !TARGET_API_MAC_CARBON
01501                     assert (clienta5 == (long) LMGetCurrentA5 ());
01502                     #endif
01503 
01504                 #endif
01505                 
01506                 #if !TARGET_API_MAC_CARBON
01507                 SetComponentInstanceA5 ((ComponentInstance) self, selfa5);
01508                 #endif
01509                 
01510                 
01511                 if (newcomponentglobals (self, clienta5, &hglobals)) {
01512                     
01513                     SetComponentInstanceStorage ((ComponentInstance) self, (Handle) hglobals);
01514                     
01515                     result = noErr;
01516                     }
01517                 else
01518                     result = memFullErr;
01519                 
01520                 RestoreA5 (clienta5);
01521                 
01522                 break;
01523                 }
01524             
01525             case kComponentCloseSelect:
01526                 
01527                 result = closesharedmenus ((hdlcomponentglobals) storage);
01528                 
01529                 break;
01530             
01531             case kComponentCanDoSelect:
01532                 result = CallComponentFunction (params, menucandofunctionUPP);
01533                 break;
01534             
01535             case kComponentVersionSelect:
01536                 result = 0x04100100;
01537                 
01538                 break;
01539             }
01540         }
01541     else  { /*positive selectors are menu sharing calls*/
01542         
01543         ComponentFunctionUPP func = nil;
01544         
01545         switch (what) {
01546             
01547             case msInitSharedMenusCommand:
01548                 func = osaInitSharedMenusUPP;
01549                 
01550                 break;
01551             
01552             case msSharedMenuHitCommand:
01553                 func = osaSharedMenuHitUPP;
01554                 
01555                 break;
01556             
01557             case msSharedScriptRunningCommand:
01558                 func = osaSharedScriptRunningUPP;
01559                 
01560                 break;
01561             
01562             case msCancelSharedScriptCommand:
01563                 func = osaCancelSharedScriptUPP;
01564                 
01565                 break;
01566             
01567             case msCheckSharedMenusCommand:
01568                 func = osaCheckSharedMenusUPP;
01569                 
01570                 break;
01571             
01572             case msDisposeSharedMenusCommand:
01573                 func = osaDisposeSharedMenusUPP;
01574                 
01575                 break;
01576             
01577             case msIsSharedMenuCommand:
01578                 func = osaIsSharedMenuUPP;
01579                 
01580                 break;
01581             
01582             case msEnableSharedMenusCommand:
01583                 func = osaEnableSharedMenusUPP;
01584                 
01585                 break;
01586             
01587             case msRunSharedMenuItemCommand:
01588                 func = osaRunSharedMenuItemUPP;
01589                 
01590                 break;
01591             
01592             case msSetScriptErrorCallbackCommand:
01593                 func = osaSetScriptErrorCallbackUPP;
01594                 
01595                 break;
01596             
01597             case msSetEventFilterCallbackCommand:
01598                 func = osaSetEventFilterCallbackUPP;
01599                 
01600                 break;
01601             
01602             case msSetMenusInserterCallbackCommand:
01603                 func = osaSetMenusInserterCallbackUPP;
01604                 
01605                 break;
01606             
01607             case msSetMenusRemoverCallbackCommand:
01608                 func = osaSetMenusRemoverCallbackUPP;
01609                 
01610                 break;
01611             
01612             case msDirtySharedMenusCommand:
01613                 func = osaDirtySharedMenusUPP;
01614                 
01615                 break;
01616             
01617             } /*switch*/
01618         
01619         if (func != nil)
01620             result = callosafunction (storage, params, func);
01621         }
01622     
01623     return (result);
01624     } /*menusharingdispatch*/
01625 
01626 
01627 boolean initmenusharingcomponent (void) {
01628     
01629     /*
01630     register the menu sharing component.
01631     */
01632     
01633     Component comp;
01634     
01635     #if !TARGET_API_MAC_CARBON
01636     RememberA5 ();
01637     #endif
01638     
01639     comp = osaregistercomponent (msComponentType, 0, &menusharingdispatch, frontierstring, menusharingcomponentstring);
01640     
01641     return (comp != nil);
01642     } /*initmenusharingcomponent*/
01643 
01644 
01645 
01646 #else
01647 
01648 /* Copyright 1992-1993 UserLand Software, Inc.  All Rights Reserved.*/
01649 
01650 #include <land.h>
01651 #include "dialogs.h"
01652 #include "ops.h"
01653 #include "kb.h"
01654 #include "memory.h"
01655 #include "langinternal.h"
01656 #include "langipc.h"
01657 #include "osacomponent.h"
01658 #include "osainternal.h"
01659 #include "osamenus.h"
01660 #include "resources.h"
01661 #include <SetUpA5.h>
01662 
01663 
01664 #define MSglobals ((**hcg).menusharingglobals)
01665 
01666 // 3/7/97 dmb: bumped this constant from 3 to 5
01667 // 9.24/97 dmb: changed this constant to be ticks, not requests
01668 #define tickstoignorerequests 15
01669 
01670 #define tickstocheckformulas 15
01671 
01672 
01673 
01674 static pascal Boolean ProcessInForeground () {
01675     
01676     /*
01677     return true if we're running in the foreground, false if we're in the
01678     background.
01679     */
01680     
01681     ProcessSerialNumber currentprocess, frontprocess;
01682     Boolean fl;
01683     
01684     GetCurrentProcess (&currentprocess);
01685     
01686     GetFrontProcess (&frontprocess);
01687     
01688     SameProcess (&currentprocess, &frontprocess, &fl);
01689     
01690     return (fl);
01691     } /*ProcessInForeground*/
01692 
01693 
01694 static pascal short CountMenuArray (hdlcomponentglobals hcg) {
01695     
01696     /*
01697     return the number of menus in the menu array.
01698     */
01699     
01700     register hdlmenuarray hm = MSglobals.hsharedmenus;
01701     
01702     if (hm == nil)
01703         return (0);
01704     
01705     return ((short) (GetHandleSize ((Handle) hm) / sizeof (tyruntimemenurecord)));
01706     } /*CountMenuArray*/
01707 
01708 
01709 static pascal Boolean InstallSharedMenus (hdlcomponentglobals hcg, short idmenuafter) {
01710     
01711     /*
01712     insert all of the menus in the menuarray into the menu bar.  main 
01713     menus are inserted in front of idmenuafter. if idmenuafter is zero, 
01714     main (non-hierarchic) menus will be added to the right of all others.
01715     */
01716     
01717     register hdlmenuarray hm = MSglobals.hsharedmenus;
01718     register short i, ct;
01719     tyruntimemenurecord item;
01720     
01721     if (MSglobals.installmenuscallback != nil) {
01722         
01723         long appA5 = SetUpCurA5 ();
01724         
01725         CallMSmenuscallbackProc (MSglobals.installmenuscallback, hm);
01726         
01727         RestoreA5 (appA5);
01728         }
01729     else {
01730     
01731         ct = CountMenuArray (hcg);
01732         
01733         for (i = 0; i < ct; i++) {
01734             
01735             item = (**hm) [i];
01736             
01737             if (item.flhierarchic)
01738                 InsertMenu (item.hmenu, -1);
01739             else
01740                 InsertMenu (item.hmenu, idmenuafter);
01741             
01742             (**hm) [i].flinserted = true; /*so we'll know it needs to be removed*/
01743             } /*for*/
01744         }
01745     
01746     return (true);
01747     } /*InstallSharedMenus*/
01748 
01749 
01750 static pascal Boolean GetSharedMenus (hdlcomponentglobals hglobals, short firstresource) {
01751     
01752     /*
01753     call the menu server to get a menuarray, keyed off of our application id.
01754     
01755     firstresource is the starting id to be used for the menus; if there are 
01756     n menus, their ids will range from firstresource to firstresource + n - 1.
01757     
01758     2.1b13 dmb: use new osasethome/clientzone
01759     */
01760     
01761     register hdlcomponentglobals hcg = hglobals;
01762     boolean fl;
01763     hdlmenuarray hsharedmenus = (hdlmenuarray) NewHandle (sizeof (tyruntimemenurecord));
01764     
01765     osasethomezone (hcg);
01766     
01767     fl = langipcgetmenuarray (MSglobals.clientid, firstresource, true, (Handle *) &hsharedmenus);
01768     
01769     osasetclientzone (hcg);
01770     
01771     if (!fl)
01772         return (false);
01773     
01774     MSglobals.hsharedmenus = hsharedmenus;
01775     
01776     return (true);
01777     } /*GetSharedMenus*/
01778 
01779 
01780 static pascal Boolean CheckFormulas (hdlcomponentglobals hglobals) {
01781     
01782     /*
01783     probably should maintain msglobal and do this less often
01784     
01785     2.1b13 dmb: need to use our heap when calcualting formulas. use new 
01786     osasethome/clientzone to do so.
01787     */
01788     
01789     register hdlcomponentglobals hcg = hglobals;
01790     boolean fl;
01791     
01792     ++fldisableyield;   /*dmb 4.1b2 - in case forulas send AEs*/
01793             
01794     osasethomezone (hcg);
01795     
01796     pushhashtable (nil); /*override storage table set up by callosafunction so langrunhandle will set up root*/
01797     
01798     fl = langipccheckformulas (MSglobals.clientid);
01799     
01800     pophashtable ();
01801     
01802     osasetclientzone (hcg);
01803     
01804     --fldisableyield;   /*dmb 4.1b2*/
01805     
01806     return (fl);
01807     } /*CheckFormulas*/
01808 
01809 
01810 static pascal ComponentResult osaSharedScriptRunning (hdlcomponentglobals hcg, Boolean *flrunning) {
01811     
01812     /*
01813     returns true if a shared script is currently running, false otherwise.
01814     
01815     it's provided so that an application can intelligently handle cmd-period
01816     script termination in its keystroke handling routine.
01817     */
01818     
01819     *flrunning = flscriptrunning; /*MSglobals.flscriptrunning*/
01820     
01821     return (noErr);
01822     } /*osaSharedScriptRunning*/
01823 
01824 
01825 static pascal ComponentResult osaCancelSharedScript (hdlcomponentglobals hcg) {
01826     
01827     /*
01828     call this when the user presses cmd-period or otherwise indicates to you that
01829     he or she wants the currently running script to be halted. 
01830         
01831     8/13/92 DW: if we're talking to post-2.0 Frontier or Runtime 1.0, we send a
01832     message to the server telling it to kill the script. otherwise we do it the
01833     old less elegant way, by setting a flag that gets monitored in calls to 
01834     SharedScriptCancelled.
01835     */
01836     
01837     processdisposecode ((hdltreenode) MSglobals.idscript);
01838     
01839     return (noErr);
01840     } /*osaCancelSharedScript*/
01841 
01842 
01843 static pascal ComponentResult osaDisposeSharedMenus (hdlcomponentglobals hglobals) {
01844     
01845     /*
01846     completely dispose of the menuarray and the menu handles it contains.
01847     
01848     10/10/91 DW: check for no shared menus before disposing, save code if 
01849     its ever called from more than one place. also set the global handle to
01850     nil after disposing and redraw the menu bar.
01851     
01852     2.1b13 dmb: we're now called by closesharedmenus, as part of our client's 
01853     ExitToShell procedure. to prevent Menu Manager crashes, we have to make 
01854     sure MenuList isn't nil before deleting a menu. in fact, event disposing a 
01855     menu crashes in this context, so if menulist is nil we'll assume the app 
01856     is shutting down, and just skip that part entirely.
01857     
01858     4.0b7 dmb: set fldirtysharedmenus to true;
01859     */
01860     
01861     register hdlcomponentglobals hcg = hglobals;
01862     register hdlmenuarray hm = MSglobals.hsharedmenus;
01863     register short i;
01864     register short ctmenus;
01865     tyruntimemenurecord item;
01866     #define MenuList (*(Handle *)0xA1C)
01867     
01868     MSglobals.fldirtysharedmenus = true;    // 4.0b7 dmb: need this for client to have dynamic menubar
01869     
01870     if (hm == nil) /*no shared menus to toss*/
01871         return (noErr);
01872     
01873     if (MenuList != nil) {
01874         
01875         if (MSglobals.removemenuscallback != nil) {
01876         
01877             long appA5 = SetUpCurA5 ();
01878             
01879             CallMSmenuscallbackProc (MSglobals.removemenuscallback, hm);
01880             
01881             RestoreA5 (appA5);
01882             }
01883         
01884         ctmenus = CountMenuArray (hcg);
01885         
01886         for (i = 0; i < ctmenus; i++) {
01887             
01888             item = (**hm) [i];
01889             
01890             if (item.flinserted && (MSglobals.removemenuscallback == nil))
01891                 DeleteMenu (item.idmenu);
01892             
01893             DisposeMenu (item.hmenu);
01894             } /*for*/
01895         
01896         DrawMenuBar ();
01897         }
01898     
01899     langipcdisposemenuarray (MSglobals.clientid, (Handle) hm);
01900     
01901     /*
01902     DisposeHandle ((Handle) hm);
01903     */
01904     
01905     MSglobals.hsharedmenus = nil;
01906     
01907     return (noErr);
01908     } /*osaDisposeSharedMenus*/
01909 
01910 
01911 static pascal ComponentResult osaCheckSharedMenus (hdlcomponentglobals hglobals, short idinsertafter) {
01912     
01913     /*
01914     call this from your main event loop after receiving and processing every
01915     event. if the menus need updating, we send a message to the server asking
01916     for our shared menus.
01917     
01918     if we load menus, they are assigned resource ids starting with idinsertafter.
01919     this number must be less than 255 to allow for hierarchic menus, and must be
01920     small enough so that no menu has an id of greater than 255. 
01921     
01922     9/28/91 DW: only update menus if we're the front process. this catches the
01923     delay on re-loading a changed menu structure on the Multifinder switch. No
01924     extra burden on the script writer editing the menu bar.
01925     
01926     4.1b6 dmb: decided that the problem where Netscape Navigator, CodeWarrior and 
01927     maybe other apps pick up Frontier's icon in the system Application menu must 
01928     be timing related. Added ctmenurequests, numrequeststoignore logic to make 
01929     sure that the client has called WNE a few times before we serve any menus.
01930     
01931     5.0d19 dmb: chanced ctmenurequests to timefirstrequest, and numrequeststoignore
01932     to tickstoignorerequests, so processor speed would stop breaking the fix
01933     
01934     5.0b6 dmb: added timelastformulacheck logic
01935     */
01936     
01937     register hdlcomponentglobals hcg = hglobals;
01938     unsigned long ticksnow;
01939     
01940     if (!ProcessInForeground ()) /*only update menus if we're the front process*/
01941         return (noErr);
01942     
01943     if (flscriptrunning) /*probably re-intering from eventfilter*/
01944         return (noErr);
01945     
01946     ticksnow = gettickcount ();
01947     
01948     if (!MSglobals.fldirtysharedmenus) { /*no need for an update, return quickly*/
01949         
01950         if (ticksnow - MSglobals.timelastformulacheck > tickstocheckformulas) {
01951             
01952             CheckFormulas (hcg);
01953             
01954             MSglobals.timelastformulacheck = ticksnow;
01955             }
01956         
01957         return (noErr);
01958         }
01959     
01960     if (ticksnow - MSglobals.timefirstrequest <= tickstoignorerequests)
01961         return (noErr);
01962     
01963     osaDisposeSharedMenus (hcg);
01964     
01965     if (GetSharedMenus (hcg, idinsertafter)) {
01966         
01967         InstallSharedMenus (hcg, 0); /*install to the right of all other menus*/
01968         
01969         DrawMenuBar ();
01970         }
01971     
01972     MSglobals.fldirtysharedmenus = false;
01973     
01974     MSglobals.timelastformulacheck = ticksnow;
01975     
01976     return (noErr);
01977     } /*osaCheckSharedMenus*/
01978 
01979 
01980 static pascal ComponentResult osaIsSharedMenu (hdlcomponentglobals hcg, short idmenu, Boolean *flshared) {
01981     
01982     /*
01983     return true if the indicated menu is one of the shared menus.
01984     */
01985     
01986     register hdlmenuarray hm = MSglobals.hsharedmenus;
01987     register short ct, i;
01988     tyruntimemenurecord item;
01989     
01990     ct = CountMenuArray (hcg);
01991     
01992     *flshared = false;
01993     
01994     for (i = 0; i < ct; i++) {
01995         
01996         item = (**hm) [i];
01997         
01998         if (item.idmenu == idmenu) {
01999             
02000             *flshared = true;
02001             
02002             break;
02003             }
02004         } /*for*/
02005     
02006     return (noErr);
02007     } /*osaIsSharedMenu*/
02008 
02009 
02010 static pascal ComponentResult osaEnableSharedMenus (hdlcomponentglobals hcg, Boolean flenable) {
02011     
02012     /*
02013     Enables or disables the the menus in the specified menu array.
02014     
02015     Always returns true.
02016     */
02017     
02018     register hdlmenuarray hm = MSglobals.hsharedmenus;
02019     register short i;
02020     register short ctmenus;
02021     register MenuHandle hmenu;
02022     
02023     ctmenus = CountMenuArray (hcg);
02024     
02025     for (i = 0; i < ctmenus; i++) {
02026         
02027         hmenu = (**hm) [i].hmenu;
02028         //Code change by Timothy Paustian Monday, June 26, 2000 4:16:27 PM
02029         //Update to modern call
02030 
02031         if (flenable)
02032             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
02033             EnableMenuItem (hmenu, 0);
02034             #else
02035             EnableItem (hmenu, 0);
02036             #endif
02037         else
02038             #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
02039             DisableMenuItem (hmenu, 0);
02040             #else
02041             DisableItem (hmenu, 0);
02042             #endif
02043         } /*for*/
02044     
02045     DrawMenuBar ();
02046     
02047     return (noErr);
02048     } /*osaEnableSharedMenus*/
02049 
02050 
02051 static pascal OSErr sharedmenueventfilter (EventRecord *event, long callback) {
02052     
02053     /*
02054     2.1b11 dmb: handle an event for the activeproc or the sendproc
02055     
02056     3.0a dmb: HiliteMenu (0) any time we see an os event so menu 
02057     manager won't get confused when client does it later and it's 
02058     not in front.
02059     
02060     4.1b13 dmb: use new iscmdperiodevent
02061     */
02062     
02063     register EventRecord *ev = event;
02064     long appA5;
02065     
02066     switch ((*ev).what) {
02067         
02068         case keyDown:
02069             if (iscmdperiodevent ((*ev).message, keyDown, (*ev).modifiers))
02070                 return (userCanceledErr);
02071             
02072             break;
02073         
02074         case mouseDown: /*don't let client see these -- can't do menu selection*/
02075             break;
02076         
02077         default:
02078             if ((*ev).what == osEvt) /*3.0a*/
02079                 HiliteMenu (0);
02080             
02081             appA5 = SetUpCurA5 ();
02082             
02083             CallMSeventcallbackProc ((MSeventcallbackUPP) callback, ev);
02084             
02085             RestoreA5 (appA5);
02086             
02087             if ((*ev).what == userCanceledErr)
02088                 return (userCanceledErr);
02089             
02090             break;
02091         }
02092     
02093     return (noErr);
02094     } /*sharedmenueventfilter*/
02095 
02096 
02097 static pascal OSErr sharedmenuactiveproc (long refcon) {
02098     
02099     /*
02100     2.1b10 dmb: the client provided an event filter, which we've stashed 
02101     in the refon.
02102     
02103     on a keypress, see if user pressed cmd-period.
02104     
02105     on system & null events, pass event to caller. if the event comes back 
02106     with the ev.what field set to userCanceledErr, abort the script.
02107     
02108     the client's context is set when we get here, so we need to set up 
02109     our A5 to call anything else
02110     
02111     2.1b13: also call the default activeproc so that we'll see cmd-. 
02112     event there are other events preempting (updates & activates)
02113     */
02114     
02115     EventRecord ev;
02116     OSErr err;
02117     
02118     long curA5 = SetUpAppA5 ();
02119     
02120     WaitNextEvent (keyDownMask | mDownMask | osMask | activMask | updateMask, &ev, 1L, nil);
02121     
02122     err = sharedmenueventfilter (&ev, refcon);
02123     
02124     if (err == noErr)
02125         err = osadefaultactiveproc (0L);
02126     
02127     RestoreA5 (curA5);
02128     
02129     return (err);
02130     } /*sharedmenuactiveproc*/
02131 
02132 
02133 static pascal Boolean sharedmenuidleproc (EventRecord *ev, long *sleep, RgnHandle *mousergn) {
02134     
02135     /*
02136     2.1b10: pass the event through to the client application so it can 
02137     respond to it.
02138     
02139     3.0b15 dmb: see comment in sharedmenusendproc below. the only way to get 
02140     the event filter is to find our globals.
02141     */
02142     
02143     #pragma unused (sleep, mousergn)
02144     
02145     OSErr err = noErr;
02146     long eventfilter;
02147     
02148     long curA5 = SetUpAppA5 ();
02149     
02150     #if TARGET_API_MAC_CARBON == 1
02151     if (osafindclienteventfilter ((long) nil, &eventfilter))
02152         err = sharedmenueventfilter (ev, eventfilter);
02153     #else   
02154     if (osafindclienteventfilter ((long) LMGetCurrentA5 (), &eventfilter))
02155         err = sharedmenueventfilter (ev, eventfilter);
02156     #endif
02157         
02158     RestoreA5 (curA5);
02159     
02160     return (err != noErr); /*false means keep waiting*/
02161     } /*sharedmenuidleproc*/
02162 
02163 
02164 static pascal OSErr sharedmenusendproc (const AppleEvent *, AppleEvent *, AESendMode, AESendPriority, long, AEIdleUPP, AEFilterUPP, long);
02165 
02166 
02167 #if !TARGET_RT_MAC_CFM || TARGET_API_MAC_CARBON
02168 
02169     #define sharedmenuactiveprocUPP sharedmenuactiveproc
02170     
02171     #define sharedmenuidleprocUPP sharedmenuidleproc
02172     
02173     #define sharedmenusendprocUPP sharedmenusendproc
02174 
02175 #else
02176 
02177     static RoutineDescriptor sharedmenuactiveprocDesc = BUILD_ROUTINE_DESCRIPTOR (uppOSAActiveProcInfo, sharedmenuactiveproc);
02178     
02179     static RoutineDescriptor sharedmenuidleprocDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEIdleProcInfo, sharedmenuidleproc); /*4.1b13 dmb: corrected procinfo*/
02180     
02181     static RoutineDescriptor sharedmenusendprocDesc = BUILD_ROUTINE_DESCRIPTOR (uppOSASendProcInfo, sharedmenusendproc);
02182     
02183     #define sharedmenuactiveprocUPP (&sharedmenuactiveprocDesc)
02184     
02185     #define sharedmenuidleprocUPP (&sharedmenuidleprocDesc)
02186     
02187     #define sharedmenusendprocUPP (&sharedmenusendprocDesc)
02188     
02189 #endif
02190 
02191 
02192 static pascal OSErr sharedmenusendproc (const AppleEvent *event, AppleEvent *reply,
02193         AESendMode sendmode, AESendPriority priority, long timeout,
02194         AEIdleUPP idleproc, AEFilterUPP filterproc, long refcon) {
02195     
02196     /*
02197     2.1b11 dmb: the client provided an event filter. we do the same event 
02198     filtering as we do for the activeproc.
02199     
02200     the client's context is set when we get here, so we need to set up 
02201     our A5 to call anything else
02202     
02203     3.0b14 dmb: call osadefaultactiveproc here for cmd-period detection. 
02204     not needed for Frontier scripts, but essential for AppleScript scripts.
02205     
02206     3.0b15 dmb: since the AESend idleProc doesn't get a refcon, we have no way 
02207     to directly pass along our refcon, the eventfilter. we were using a static 
02208     global here, but if one client sends an event while another is waiting for 
02209     a reply, that doesn't work. the best solution I can think of right now is 
02210     for the idleproc to the use the CurrentA5 value to look up the globals for 
02211     this client, and get the eventfilter routine from there.
02212     */
02213     
02214     OSErr err;
02215     
02216     long curA5 = SetUpAppA5 ();
02217     
02218     err = osadefaultactiveproc (0L);
02219     
02220     /*
02221     sharedmenufilterproc = refcon;
02222     */
02223     
02224     idleproc = sharedmenuidleprocUPP;
02225     
02226     RestoreA5 (curA5);
02227     
02228     if (err == noErr)
02229         err = AESend (event, reply, sendmode, priority, timeout, idleproc, filterproc);
02230     
02231     return (err);
02232     } /*sharedmenusendproc*/
02233 
02234 
02235 static boolean sharedmenuprocessevent (EventRecord *ev) {
02236     
02237     /*
02238     4.1b13 dmb: new routine, for new processevent langcallback.
02239     we're only installed if the filterproc is non-nil
02240     
02241     4.1b14 dmb: we must pre/post client callback here.
02242     */
02243     
02244     register hdlcomponentglobals hcg = osaglobals;
02245     long appA5;
02246     
02247     osapreclientcallback (hcg);
02248     
02249     appA5 = SetUpCurA5 ();
02250             
02251     CallMSeventcallbackProc (MSglobals.eventfiltercallback, ev);
02252     
02253     RestoreA5 (appA5);
02254     
02255     osapostclientcallback (hcg);
02256     
02257     return (true);
02258     } /*sharedmenuprocessevent*/
02259 
02260 
02261 static pascal ComponentResult osaRunSharedMenuItem (hdlcomponentglobals hglobals, short idmenu, short iditem) {
02262      
02263     /*
02264     call the menu server to run the script linked to the indicated menu item.
02265     
02266     the script will execute asynchonously, after this call returns.
02267     
02268     SDK 2.0: if the server isn't running, remove the shared menus and return
02269     false. this will only happen if the server has crashed without letting us
02270     know that our menus are dirty.
02271     
02272     2.1b4 dmb: handle langtext signature (i.e. use specific component)
02273     
02274     2.1b6 dmb: if the script is UserTalk, don't go through the generalized 
02275     procedure of opening a component instance. not only is it slow, but the 
02276     initial context for the instance would be all wrong, so operations 
02277     that restore the client context, like osagetnextevent, would break.
02278     
02279     2.1b10 dmb: added support for the new eventfilter callback
02280     
02281     2.1b11 dmb: extended eventfilter support to flow through a sendproc 
02282     as well. also, realized that when the script is not in usertalk, 
02283     the client context needs to be restored in both the activeproc and 
02284     the sendproc.
02285     
02286     2.1b12 dmb: leave fldisableyield in it's original state, just to be safe.
02287     
02288     2.1b13 dmb: use new osasethome/clientzone. also, try setting our zone 
02289     while getting langtext; we seem to be having spurious heap problems, 
02290     and maybe this is it.
02291     
02292     3.0b15 dmb: when OSADoScript returns a script error, it seems that we still 
02293     need to call OSAScriptError to get the error text -- at least for AppleScript 
02294     we do.  (This is counter to my recollection of the DoScript spec, but that's 
02295     how it is.)  Also, initialize result to null, just in case.
02296     
02297     3.0b16 dmb: when the script is non-UserTalk, must set flscriptrunning true 
02298     and false manually.
02299     */
02300     
02301     register hdlcomponentglobals hcg = hglobals;
02302     Handle htext;
02303     long signature;
02304     ComponentInstance comp;
02305     MSeventcallbackUPP eventfilter;
02306     AEDesc desc;
02307     AEDesc result = {typeNull, nil};
02308     long clienta5, appA5;
02309     boolean fl;
02310     bigstring bserror;
02311     OSAError err;
02312     
02313     osasethomezone (hcg);
02314     
02315     fl = langipcgetitemlangtext ((**hcg).clientid, idmenu, iditem, &htext, &signature);
02316     
02317     osasetclientzone (hcg);
02318     
02319     if (htext == nil) /*we must have just displayed script node*/
02320         return (noErr);
02321     
02322     if (!fl)
02323         return (osageterror ());
02324     
02325     desc.descriptorType = typeChar;
02326     
02327     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
02328     
02329         newdescwithhandle (&desc, typeChar, htext);
02330     
02331     #else
02332     
02333         desc.dataHandle = htext;
02334     
02335     #endif
02336     
02337     eventfilter = MSglobals.eventfiltercallback;
02338     
02339     if (signature == typeLAND) {
02340         
02341         if (eventfilter != nil) {
02342             
02343             osaSetActiveProc (hcg, sharedmenuactiveprocUPP, (long) eventfilter);
02344             
02345             osaSetSendProc (hcg, sharedmenusendprocUPP, (long) eventfilter);
02346             
02347             langcallbacks.processeventcallback = sharedmenuprocessevent;
02348             }
02349         
02350         err = osaDoScript (hcg, &desc, kOSANullScript, typeChar, kOSANullMode, &result);
02351         
02352         if (eventfilter != nil) {
02353             
02354             osaSetActiveProc (hcg, nil, 0L); /*don't leave this set for when we calc formulas*/
02355             
02356             osaSetSendProc (hcg, nil, 0L);
02357             }
02358         }
02359     else {
02360         
02361         osasethomezone (hcg);
02362         
02363         comp = getosaserver (signature);
02364         
02365         osasetclientzone (hcg);
02366         
02367         if (comp == nil) {
02368             
02369             langostypeparamerror (cantopencomponenterror, signature); /*set the error*/
02370             
02371             osaScriptError (hcg, kOSAErrorMessage, typeChar, &result); /*get the text*/
02372             
02373             err = osageterror (); /*always returns non-zero*/
02374             }
02375         else {
02376             
02377             if (eventfilter != nil) {
02378                 
02379                 OSASetActiveProc (comp, sharedmenuactiveprocUPP, (long) eventfilter);
02380                 
02381                 OSASetSendProc (comp, sharedmenusendprocUPP, (long) eventfilter);
02382                 }
02383             
02384             flscriptrunning = true; /*need to set to block checksharedmenus*/
02385             
02386             clienta5 = osapreclientcallback (hcg);
02387             
02388             #ifdef THINK_C
02389                 
02390                 asm {
02391                     move.l  a5,-(a7)
02392                     move.l  clienta5,a5
02393                     }
02394             
02395             #else
02396             
02397                 appA5 = SetUpCurA5 ();  // SetUpThisA5 (clienta5);  // 4.0b5: was: SetUpCurA5 ();
02398             
02399             #endif
02400             
02401             err = OSADoScript (comp, &desc, kOSANullScript, typeChar, kOSANullMode, &result);
02402             
02403             if ((err == errOSAScriptError) && (result.descriptorType == typeNull)) { /*need error text*/
02404                 
02405                 if (OSAScriptError (comp, kOSAErrorNumber, typeLongInteger, &result) == noErr) {
02406                     
02407                     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
02408                     
02409                         {
02410                         Handle hcopy;
02411                         
02412                         copydatahandle (&result, &hcopy);
02413                         
02414                         err = **(long **) hcopy;
02415                         
02416                         disposehandle (hcopy);
02417                         }
02418                     
02419                     #else
02420                     
02421                         err = **(long **) result.dataHandle; /*can't call numberfromhandle w/out our a5*/
02422                     
02423                     #endif
02424                     
02425                     AEDisposeDesc (&result);
02426                     }
02427                 
02428                 if (err != userCanceledErr)
02429                     OSAScriptError (comp, kOSAErrorMessage, typeChar, &result);
02430                 }
02431             
02432             RestoreA5 (appA5);
02433             
02434             osapostclientcallback (hcg);
02435             
02436             flscriptrunning = false; /*unblock checksharedmenus*/
02437             
02438             if (eventfilter != nil) {
02439                 
02440                 OSASetActiveProc (comp, nil, 0L); /*clear it out*/
02441                 
02442                 OSASetSendProc (comp, nil, 0L);
02443                 }
02444             }
02445         }
02446     
02447     osasethomezone (hcg);
02448     
02449     AEDisposeDesc (&desc);
02450     
02451     osasetclientzone (hcg);
02452     
02453     if ((err != noErr) && (err != userCanceledErr) && (result.descriptorType == typeChar)) {
02454         
02455         #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
02456         
02457             datahandletostring (&result, bserror);
02458         
02459         #else
02460         
02461             texthandletostring (result.dataHandle, bserror);
02462         
02463         #endif
02464         
02465         if (MSglobals.scripterrorcallback == nil) {
02466             
02467             osainstallpatch (hcg);
02468             
02469             osasethomezone (hcg);
02470             
02471             ++fldisableyield; /*shellactivate, at least, needs this in this context*/
02472             
02473             alertdialog (bserror);
02474             
02475             --fldisableyield; /*restore*/
02476             
02477             osasetclientzone (hcg);
02478             
02479             osaremovepatch (hcg, nil);
02480             }
02481         else {
02482             clienta5 = osapreclientcallback (hcg);
02483             
02484             #ifdef THINK_C
02485             
02486             asm {
02487                 move.l  a5,-(a7)
02488                 move.l  clienta5,a5
02489                 }
02490                 
02491                 (*(tyMSstringcallback)MSglobals.scripterrorcallback) (bserror);
02492             
02493             #else
02494             
02495                 appA5 = SetUpCurA5 ();  // SetUpThisA5 (clienta5);  // 4.0b5: was: SetUpCurA5 ();
02496                 
02497                 CallMSstringcallbackProc (MSglobals.scripterrorcallback, bserror);
02498                 
02499             #endif
02500             
02501             RestoreA5 (appA5);
02502             
02503             osapostclientcallback (hcg);
02504             }
02505         }
02506     
02507     AEDisposeDesc (&result);
02508     
02509     return (err);
02510     } /*osaRunSharedMenuItem*/
02511 
02512 
02513 static pascal ComponentResult osaSetScriptErrorCallback (hdlcomponentglobals hglobals, MSstringcallbackUPP errorcallback) {
02514     
02515     register hdlcomponentglobals hcg = hglobals;
02516     
02517     MSglobals.scripterrorcallback = errorcallback;
02518     
02519     return (noErr);
02520     } /*osaSetScriptErrorCallback*/
02521 
02522 
02523 static pascal ComponentResult osaSetEventFilterCallback (hdlcomponentglobals hglobals, MSeventcallbackUPP eventcallback) {
02524     
02525     /*
02526     2.1b10 dmb: new routine to allow some background operations to go on 
02527     while a shared menu script is running
02528     */
02529     
02530     register hdlcomponentglobals hcg = hglobals;
02531     
02532     MSglobals.eventfiltercallback = eventcallback;
02533     
02534     return (noErr);
02535     } /*osaSetEventFilterCallback*/
02536 
02537 
02538 static pascal ComponentResult osaSetMenusInserterCallback (hdlcomponentglobals hglobals, MSmenuscallbackUPP callback) {
02539     
02540     /*
02541     2.1b10 dmb: new routine to allow some background operations to go on 
02542     while a shared menu script is running
02543     */
02544     
02545     register hdlcomponentglobals hcg = hglobals;
02546     
02547     MSglobals.installmenuscallback = callback;
02548     
02549     return (noErr);
02550     } /*osaSetMenusInserterCallback*/
02551 
02552 
02553 static pascal ComponentResult osaSetMenusRemoverCallback (hdlcomponentglobals hglobals, MSmenuscallbackUPP callback) {
02554     
02555     /*
02556     2.1b10 dmb: new routine to allow some background operations to go on 
02557     while a shared menu script is running
02558     */
02559     
02560     register hdlcomponentglobals hcg = hglobals;
02561     
02562     MSglobals.removemenuscallback = callback;
02563     
02564     return (noErr);
02565     } /*osaSetMenusRemoverCallback*/
02566 
02567 
02568 static pascal ComponentResult osaSharedMenuHit (hdlcomponentglobals hglobals, short idmenu, short iditem, Boolean *flhit) {
02569 
02570     register hdlcomponentglobals hcg = hglobals;
02571     OSErr err;
02572     
02573     err = osaIsSharedMenu (hcg, idmenu, flhit);
02574     
02575     if (err == noErr) {
02576         
02577         if (*flhit)
02578             err = osaRunSharedMenuItem (hcg, idmenu, iditem);
02579         }
02580     
02581     return (err);
02582     } /*osaSharedMenuHit*/
02583 
02584 
02585 static boolean removemenusharinghandlers (hdlcomponentglobals); /*forward*/
02586 
02587 
02588 static pascal ComponentResult osaDirtySharedMenus (hdlcomponentglobals hglobals) {
02589     
02590     /*
02591     2.1b8 dmb: toss dirty menus now; the component may be gone by the time 
02592     we're frontmost & try to refresh them. in order to do this, we now need 
02593     to set up a5.
02594     
02595     3.0b16 dmb: added call to closeosaservers. since Frontier may be going 
02596     away while the client sticks around, this is the only reliable place to 
02597     get rid of those instances -- 36K of memory for AppleScript
02598     
02599     4.1b2 dmb: broke this code out of HandleMenuDirty so that it can be called
02600     directly by a (4.1-aware) menusharing client
02601     
02602     4.1b12 dmb: reset MSglobals.ctmenurequests when we dirty them, so client 
02603     will have to ask a few times after switching in.
02604     */
02605     
02606     register hdlcomponentglobals hcg = hglobals;
02607     
02608 // 4.0b7 dmb: now done by osaDisposeSharedMenus --  MSglobals.fldirtysharedmenus = true;
02609     
02610     long curA5 = SetUpAppA5 ();
02611     
02612     osaDisposeSharedMenus (hcg); /*2.1b8: toss them now*/
02613     
02614     if (flosashutdown) {
02615         
02616         removemenusharinghandlers (hcg);
02617         
02618         closeosaservers ();
02619         
02620         MSglobals.clientid = 0; /*so servingsharedmenus can break out of loop*/
02621         }
02622     
02623     MSglobals.timefirstrequest = gettickcount (); /*4.1b12*/
02624     
02625     RestoreA5 (curA5);
02626     
02627     return (noErr);
02628     } /*osaDirtySharedMenus*/
02629 
02630 
02631 static pascal OSErr HandleMenuDirty (const AppleEvent *event, AppleEvent *reply, UInt32 refcon) {
02632     
02633     /*
02634     this Apple event handler is called when the application's menu bar has been 
02635     edited by the script writer in the menu server's menu editor.
02636     
02637     4.1b2 dmb: call osaDirtySharedMenus, which does what we used to do directly.
02638     */
02639     
02640     #pragma unused (event, reply)
02641 
02642     osaDirtySharedMenus ((hdlcomponentglobals) refcon);
02643     
02644     return (noErr);
02645     } /*HandleMenuDirty*/
02646 
02647 
02648 #if !TARGET_RT_MAC_CFM || TARGET_API_MAC_CARBON
02649 
02650     #define HandleMenuDirtyUPP HandleMenuDirty
02651 
02652 #else
02653 
02654     static RoutineDescriptor HandleMenuDirtyDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEEventHandlerProcInfo, HandleMenuDirty);
02655     
02656     #define HandleMenuDirtyUPP (&HandleMenuDirtyDesc)
02657 
02658 #endif
02659 
02660 
02661 static boolean installmenusharinghandlers (hdlcomponentglobals hglobals) {
02662     
02663     register hdlcomponentglobals hcg = hglobals;
02664     OSErr err;
02665     
02666     err = AEInstallEventHandler (MSglobals.clientid, 'updm', HandleMenuDirtyUPP, (long) hcg, false);
02667     
02668     /*
02669     err = AEInstallEventHandler (MSglobals.clientid, 'done', (EventHandlerProcPtr) &HandleScriptComplete, (long) hglobals, false);
02670     */
02671     
02672     return (err == noErr);
02673     } /*installmenusharinghandlers*/
02674 
02675 
02676 static boolean removemenusharinghandlers (hdlcomponentglobals hglobals) {
02677     
02678     register hdlcomponentglobals hcg = hglobals;
02679     OSErr err;
02680     
02681     err = AERemoveEventHandler (MSglobals.clientid, 'updm', HandleMenuDirtyUPP, false);
02682     
02683     /*
02684     err = AERemoveEventHandler (MSglobals.clientid, 'done', (EventHandlerProcPtr) &HandleScriptComplete, false);
02685     */
02686     
02687     return (err == noErr);
02688     } /*removemenusharinghandlers*/
02689 
02690 
02691 static pascal ComponentResult closesharedmenus (hdlcomponentglobals hglobals) {
02692     
02693     /*
02694     2.1b8 dmb: new routine to be called by cmpclose for cleanup
02695     
02696     2.1b13 dmb: dispose shared menus here so that langipcmenus can 
02697     release the associated data structures, which would otherwise 
02698     be linked to menus in the heap that's about to disappear.
02699     
02700     3.0b16 dmb: added call to closeosaservers. osaservers are now 
02701     managed on a per-process basic, so this cleanup helps.
02702     */
02703     
02704     register hdlcomponentglobals hcg = hglobals;
02705     
02706     if (hcg == nil)
02707         return (invalidComponentID);
02708     
02709     osaDisposeSharedMenus (hcg);
02710     
02711     removemenusharinghandlers (hcg);
02712     
02713     disposecomponentglobals (hcg);
02714     
02715     closeosaservers (); /*3.0b16*/
02716     
02717     return (noErr);
02718     } /*closesharedmenus*/
02719 
02720 
02721 static pascal ComponentResult osaInitSharedMenus (hdlcomponentglobals hglobals) {
02722     
02723     register hdlcomponentglobals hcg = hglobals;
02724     long id;
02725     
02726     if (hcg == nil)
02727         return (invalidComponentID);
02728     
02729     id = (**hcg).clientid;
02730     
02731     MSglobals.serverid = typeLAND; /*Frontier's creator id*/
02732     
02733     MSglobals.clientid = id;
02734     
02735     MSglobals.hsharedmenus = nil; /*haven't loaded shared menus yet*/
02736     
02737     MSglobals.fldirtysharedmenus = true; /*force update 1st time thru event loop*/
02738     
02739     MSglobals.flhavecomponentmanager = true;
02740     
02741     MSglobals.timefirstrequest = gettickcount (); /*5.0d19*/
02742     
02743     installmenusharinghandlers (hcg);
02744     
02745     return (noErr);
02746     } /*osaInitSharedMenus*/
02747 
02748 
02749 static pascal ComponentResult menucandofunction (short selector) {
02750     
02751     switch (selector) {
02752         
02753         case kComponentOpenSelect:
02754         case kComponentCloseSelect:
02755         case kComponentCanDoSelect:
02756         case kComponentVersionSelect:
02757         
02758         case msInitSharedMenusCommand:
02759         case msSharedMenuHitCommand:
02760         case msSharedScriptRunningCommand:
02761         case msCancelSharedScriptCommand:
02762         case msCheckSharedMenusCommand:
02763         case msDisposeSharedMenusCommand:
02764         case msIsSharedMenuCommand:
02765         case msEnableSharedMenusCommand:
02766         case msRunSharedMenuItemCommand:
02767         case msSetScriptErrorCallbackCommand:
02768         case msSetEventFilterCallbackCommand:
02769         case msSetMenusInserterCallbackCommand:
02770         case msSetMenusRemoverCallbackCommand:
02771         case msDirtySharedMenusCommand:
02772             return (true);
02773         }
02774     
02775     return (false);
02776     } /*menucandofunction*/
02777 
02778 
02779 #if !TARGET_RT_MAC_CFM || TARGET_API_MAC_CARBON
02780     
02781     #define menucandofunctionUPP    ((ComponentFunctionUPP) menucandofunction)
02782     #define osaInitSharedMenusUPP   ((ComponentFunctionUPP) osaInitSharedMenus)
02783     #define osaSharedMenuHitUPP ((ComponentFunctionUPP) osaSharedMenuHit)
02784     #define osaSharedScriptRunningUPP   ((ComponentFunctionUPP) osaSharedScriptRunning)
02785     #define osaCancelSharedScriptUPP    ((ComponentFunctionUPP) osaCancelSharedScript)
02786     #define osaCheckSharedMenusUPP  ((ComponentFunctionUPP) osaCheckSharedMenus)
02787     #define osaDisposeSharedMenusUPP    ((ComponentFunctionUPP) osaDisposeSharedMenus)
02788     #define osaIsSharedMenuUPP  ((ComponentFunctionUPP) osaIsSharedMenu)
02789     #define osaEnableSharedMenusUPP ((ComponentFunctionUPP) osaEnableSharedMenus)
02790     #define osaRunSharedMenuItemUPP ((ComponentFunctionUPP) osaRunSharedMenuItem)
02791     #define osaSetScriptErrorCallbackUPP    ((ComponentFunctionUPP) osaSetScriptErrorCallback)
02792     #define osaSetEventFilterCallbackUPP    ((ComponentFunctionUPP) osaSetEventFilterCallback)
02793     #define osaSetMenusInserterCallbackUPP  ((ComponentFunctionUPP) osaSetMenusInserterCallback)
02794     #define osaSetMenusRemoverCallbackUPP   ((ComponentFunctionUPP) osaSetMenusRemoverCallback)
02795     #define osaDirtySharedMenusUPP  ((ComponentFunctionUPP) osaDirtySharedMenus)
02796 
02797 #else
02798 
02799     enum {
02800         menucandofunctionProcInfo = kPascalStackBased
02801              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02802              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02803              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
02804     };
02805     
02806     enum {
02807         osaInitSharedMenusProcInfo = kPascalStackBased
02808              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02809              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02810     };
02811     
02812     enum {
02813         osaSharedMenuHitProcInfo = kPascalStackBased
02814              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02815              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02816              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
02817              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
02818              | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(Boolean *)))
02819     };
02820     
02821     enum {
02822         osaSharedScriptRunningProcInfo = kPascalStackBased
02823              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02824              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02825              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
02826              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
02827     };
02828     
02829     enum {
02830         osaCancelSharedScriptProcInfo = kPascalStackBased
02831              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02832              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02833     };
02834     
02835     enum {
02836         osaCheckSharedMenusProcInfo = kPascalStackBased
02837              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02838              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02839              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
02840     };
02841     
02842     enum {
02843         osaDisposeSharedMenusProcInfo = kPascalStackBased
02844              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02845              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02846     };
02847     
02848     enum {
02849         osaIsSharedMenuProcInfo = kPascalStackBased
02850              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02851              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02852              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
02853              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean *)))
02854     };
02855     
02856     enum {
02857         osaEnableSharedMenusProcInfo = kPascalStackBased
02858              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02859              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02860              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Boolean)))
02861     };
02862     
02863     enum {
02864         osaRunSharedMenuItemProcInfo = kPascalStackBased
02865              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02866              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02867              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
02868              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
02869     };
02870     
02871     enum {
02872         osaSetScriptErrorCallbackProcInfo = kPascalStackBased
02873              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02874              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02875              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSstringcallbackUPP)))
02876     };
02877     
02878     enum {
02879         osaSetEventFilterCallbackProcInfo = kPascalStackBased
02880              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02881              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02882              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSeventcallbackUPP)))
02883     };
02884     
02885     enum {
02886         osaSetMenusInserterCallbackProcInfo = kPascalStackBased
02887              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02888              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02889              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSmenuscallbackUPP)))
02890     };
02891     
02892     enum {
02893         osaSetMenusRemoverCallbackProcInfo = kPascalStackBased
02894              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02895              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02896              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MSmenuscallbackUPP)))
02897     };
02898     
02899     enum {
02900         osaDirtySharedMenusProcInfo = kPascalStackBased
02901              | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
02902              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(hdlcomponentglobals)))
02903     };
02904     
02905     static RoutineDescriptor menucandofunctionDesc = BUILD_ROUTINE_DESCRIPTOR (menucandofunctionProcInfo, menucandofunction);
02906     static RoutineDescriptor osaInitSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaInitSharedMenusProcInfo, osaInitSharedMenus);
02907     static RoutineDescriptor osaSharedMenuHitDesc = BUILD_ROUTINE_DESCRIPTOR (osaSharedMenuHitProcInfo, osaSharedMenuHit);
02908     static RoutineDescriptor osaSharedScriptRunningDesc = BUILD_ROUTINE_DESCRIPTOR (osaSharedScriptRunningProcInfo, osaSharedScriptRunning);
02909     static RoutineDescriptor osaCancelSharedScriptDesc = BUILD_ROUTINE_DESCRIPTOR (osaCancelSharedScriptProcInfo, osaCancelSharedScript);
02910     static RoutineDescriptor osaCheckSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaCheckSharedMenusProcInfo, osaCheckSharedMenus);
02911     static RoutineDescriptor osaDisposeSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaDisposeSharedMenusProcInfo, osaDisposeSharedMenus);
02912     static RoutineDescriptor osaIsSharedMenuDesc = BUILD_ROUTINE_DESCRIPTOR (osaIsSharedMenuProcInfo, osaIsSharedMenu);
02913     static RoutineDescriptor osaEnableSharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaEnableSharedMenusProcInfo, osaEnableSharedMenus);
02914     static RoutineDescriptor osaRunSharedMenuItemDesc = BUILD_ROUTINE_DESCRIPTOR (osaRunSharedMenuItemProcInfo, osaRunSharedMenuItem);
02915     static RoutineDescriptor osaSetScriptErrorCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetScriptErrorCallbackProcInfo, osaSetScriptErrorCallback);
02916     static RoutineDescriptor osaSetEventFilterCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetEventFilterCallbackProcInfo, osaSetEventFilterCallback);
02917     static RoutineDescriptor osaSetMenusInserterCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetMenusInserterCallbackProcInfo, osaSetMenusInserterCallback);
02918     static RoutineDescriptor osaSetMenusRemoverCallbackDesc = BUILD_ROUTINE_DESCRIPTOR (osaSetMenusRemoverCallbackProcInfo, osaSetMenusRemoverCallback);
02919     static RoutineDescriptor osaDirtySharedMenusDesc = BUILD_ROUTINE_DESCRIPTOR (osaDirtySharedMenusProcInfo, osaDirtySharedMenus);
02920 
02921     #define menucandofunctionUPP (&menucandofunctionDesc)
02922     #define osaInitSharedMenusUPP (&osaInitSharedMenusDesc)
02923     #define osaSharedMenuHitUPP (&osaSharedMenuHitDesc)
02924     #define osaSharedScriptRunningUPP (&osaSharedScriptRunningDesc)
02925     #define osaCancelSharedScriptUPP (&osaCancelSharedScriptDesc)
02926     #define osaCheckSharedMenusUPP (&osaCheckSharedMenusDesc)
02927     #define osaDisposeSharedMenusUPP (&osaDisposeSharedMenusDesc)
02928     #define osaIsSharedMenuUPP (&osaIsSharedMenuDesc)
02929     #define osaEnableSharedMenusUPP (&osaEnableSharedMenusDesc)
02930     #define osaRunSharedMenuItemUPP (&osaRunSharedMenuItemDesc)
02931     #define osaSetScriptErrorCallbackUPP (&osaSetScriptErrorCallbackDesc)
02932     #define osaSetEventFilterCallbackUPP (&osaSetEventFilterCallbackDesc)
02933     #define osaSetMenusInserterCallbackUPP (&osaSetMenusInserterCallbackDesc)
02934     #define osaSetMenusRemoverCallbackUPP (&osaSetMenusRemoverCallbackDesc)
02935     #define osaDirtySharedMenusUPP (&osaDirtySharedMenusDesc)
02936 
02937 #endif
02938 
02939 static pascal ComponentResult menusharingdispatch (register ComponentParameters *params, Handle storage) {
02940     
02941     /*
02942     2.1b9 dmb: new dispatcher; menu sharing component now completely 
02943     seperate from OSA
02944     */
02945     
02946     ComponentResult result = badComponentSelector;
02947     short what = (*params).what;
02948     
02949     if (what < 0) { /*negative selectors are component manager calls*/
02950         
02951         switch (what) {
02952             
02953             case kComponentOpenSelect: { /*can't call subroutine because a5 isn't ours*/
02954                 
02955                 hdlcomponentglobals hglobals;
02956                 Component self = (Component) (*params).params [0];
02957                 long selfa5;
02958                 long clienta5;
02959                 
02960                 selfa5 = GetComponentRefcon (self);
02961                 
02962                 #ifdef THINK_C
02963                     
02964                     asm {
02965                         move.l  a5,clienta5
02966                         move.l  a5,-(a7)
02967                         move.l  selfa5,a5
02968                         }
02969                     
02970                 #else
02971                 
02972                     clienta5 = SetUpAppA5 ();
02973                     
02974                     #if !TARGET_API_MAC_CARBON
02975                     assert (clienta5 == (long) LMGetCurrentA5 ());
02976                     #endif
02977 
02978                 #endif
02979                 
02980                 #if !TARGET_API_MAC_CARBON
02981                 SetComponentInstanceA5 ((ComponentInstance) self, selfa5);
02982                 #endif
02983 
02984                 if (newcomponentglobals (self, clienta5, &hglobals)) {
02985                     
02986                     SetComponentInstanceStorage ((ComponentInstance) self, (Handle) hglobals);
02987                     
02988                     result = noErr;
02989                     }
02990                 else
02991                     result = memFullErr;
02992                 
02993                 RestoreA5 (clienta5);
02994                 
02995                 break;
02996                 }
02997             
02998             case kComponentCloseSelect:
02999                 
03000                 result = closesharedmenus ((hdlcomponentglobals) storage);
03001                 
03002                 break;
03003             
03004             case kComponentCanDoSelect:
03005                 result = CallComponentFunction (params, menucandofunctionUPP);
03006                 
03007                 break;
03008             
03009             case kComponentVersionSelect:
03010                 result = 0x04100100;
03011                 
03012                 break;
03013             }
03014         }
03015     else  { /*positive selectors are menu sharing calls*/
03016         
03017         ComponentFunctionUPP func = nil;
03018         
03019         switch (what) {
03020             
03021             case msInitSharedMenusCommand:
03022                 func = osaInitSharedMenusUPP;
03023                 
03024                 break;
03025             
03026             case msSharedMenuHitCommand:
03027                 func = osaSharedMenuHitUPP;
03028                 
03029                 break;
03030             
03031             case msSharedScriptRunningCommand:
03032                 func = osaSharedScriptRunningUPP;
03033                 
03034                 break;
03035             
03036             case msCancelSharedScriptCommand:
03037                 func = osaCancelSharedScriptUPP;
03038                 
03039                 break;
03040             
03041             case msCheckSharedMenusCommand:
03042                 func = osaCheckSharedMenusUPP;
03043                 
03044                 break;
03045             
03046             case msDisposeSharedMenusCommand:
03047                 func = osaDisposeSharedMenusUPP;
03048                 
03049                 break;
03050             
03051             case msIsSharedMenuCommand:
03052                 func = osaIsSharedMenuUPP;
03053                 
03054                 break;
03055             
03056             case msEnableSharedMenusCommand:
03057                 func = osaEnableSharedMenusUPP;
03058                 
03059                 break;
03060             
03061             case msRunSharedMenuItemCommand:
03062                 func = osaRunSharedMenuItemUPP;
03063                 
03064                 break;
03065             
03066             case msSetScriptErrorCallbackCommand:
03067                 func = osaSetScriptErrorCallbackUPP;
03068                 
03069                 break;
03070             
03071             case msSetEventFilterCallbackCommand:
03072                 func = osaSetEventFilterCallbackUPP;
03073                 
03074                 break;
03075             
03076             case msSetMenusInserterCallbackCommand:
03077                 func = osaSetMenusInserterCallbackUPP;
03078                 
03079                 break;
03080             
03081             case msSetMenusRemoverCallbackCommand:
03082                 func = osaSetMenusRemoverCallbackUPP;
03083                 
03084                 break;
03085             
03086             case msDirtySharedMenusCommand:
03087                 func = osaDirtySharedMenusUPP;
03088                 
03089                 break;
03090             
03091             } /*switch*/
03092         
03093         if (func != nil)
03094             result = callosafunction (storage, params, func);
03095         }
03096     
03097     return (result);
03098     } /*menusharingdispatch*/
03099 
03100 
03101 boolean initmenusharingcomponent (void) {
03102     
03103     /*
03104     register the menu sharing component.
03105     */
03106     
03107     Component comp;
03108     
03109     #if !TARGET_API_MAC_CARBON
03110     RememberA5 ();
03111     #endif
03112     
03113     comp = osaregistercomponent (msComponentType, 0, &menusharingdispatch, frontierstring, menusharingcomponentstring);
03114     
03115     return (comp != nil);
03116     } /*initmenusharingcomponent*/
03117 
03118 #endif

Generated on Wed May 31 18:19:58 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6