osadroplet.c

Go to the documentation of this file.
00001 
00002 /*  $Id: osadroplet.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 #include <uisharing.h>
00032 #include <land.h>
00033 #include "dialogs.h"
00034 #include "strings.h"
00035 #include "osainternal.h"
00036 #include "osadroplet.h"
00037 
00038 #ifdef dropletcomponent /*entire file from here*/
00039 
00040 #include <SetUpA5.h>
00041 
00042 
00043 pascal OSErr PlotIconID (Rect *r, short align, short transform, short resid) = {0x303C,0x0500,0xABC9};
00044 
00045 
00046 #define kDropletRunAppSelect 1
00047 
00048 
00049 #define iddropletstring 3000
00050 #define iddropletdescriptionstring 3001
00051 
00052 
00053 #define mainwindowid 3000
00054 #define runitem 1
00055 #define cancelitem 2
00056 #define msgitem 3
00057 #define edititem 4
00058 #define iconitem 5
00059 #define titleitem 6
00060 
00061 #define aboutalertid 3001
00062 
00063 #define erroralertid 3002
00064 
00065 #define applemenu 3000
00066 #define aboutitem 1
00067 
00068 #define filemenu 3001
00069 #define quititem 1
00070 
00071 
00072 #define dropletglobals ((**hcg).dropletglobals)
00073 
00074 
00075 
00076 
00077 static Handle getResourceAndDetach (OSType restype, short resid) { /*new in Frontier SDK 2.1*/
00078 
00079     Handle h;
00080     
00081     h = GetResource (restype, resid);
00082     
00083     if (h != nil)
00084         DetachResource (h);
00085         
00086     return (h);
00087     } /*getResourceAndDetach*/
00088 
00089 
00090 static OSErr OSAnewverb (OSType receiver, OSType vclass, OSType vtoken, AppleEvent *event) {
00091     
00092     /*
00093     events we create will not be sent via the AE Manager; they'll be 
00094     passed to OSAExecuteEvent. So we use a null address & other dummy parameters
00095     */
00096     
00097     AEDesc adr;
00098     OSErr ec;
00099     
00100     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00101         
00102         newdescnull (&adr, typeNull);
00103     
00104     #else
00105     
00106         adr.dataHandle = nil;
00107     
00108         adr.descriptorType = typeNull;
00109     
00110     #endif
00111     
00112     if (receiver != 0)
00113         ec = AECreateDesc (typeApplSignature, (Ptr) &receiver, sizeof (receiver), &adr);
00114     
00115     if (ec != noErr)
00116         return (ec);
00117     
00118     ec = AECreateAppleEvent (vclass, vtoken, &adr, kAutoGenerateReturnID, kAnyTransactionID, event);
00119     
00120     AEDisposeDesc (&adr);
00121     
00122     return (ec);
00123     } /*OSAnewverb*/
00124 
00125 
00126 static Boolean frontmostapp () {
00127     
00128     ProcessSerialNumber currentprocess, frontprocess;
00129     Boolean fl;
00130     
00131     GetCurrentProcess (&currentprocess);
00132     
00133     GetFrontProcess (&frontprocess);
00134     
00135     SameProcess (&currentprocess, &frontprocess, &fl);
00136     
00137     return (fl);
00138     } /*frontmostapp*/
00139     
00140     
00141 static void cometofront (void) {
00142 
00143     if (!frontmostapp ()) {
00144         
00145         register short i;
00146         ProcessSerialNumber psn;
00147         EventRecord ev;
00148         
00149         GetCurrentProcess (&psn);
00150         
00151         SetFrontProcess (&psn);
00152         
00153         for (i = 1; i <= 3; i++)
00154             WaitNextEvent (nullEvent, &ev, 1, nil); 
00155         }
00156     } /*cometofront*/
00157 
00158 
00159 static pascal Boolean alertuser (Str255 s) {
00160     
00161     cometofront ();
00162     
00163     ParamText (s, nil, nil, nil); 
00164     
00165     Alert (erroralertid, nil);
00166     
00167     return (true);
00168     } /*alertuser*/
00169 
00170 
00171 static void doclosedown (void) {
00172     
00173     AppleEvent event, reply;
00174     
00175     if (OSAnewverb (0, 'aevt', 'quit', &event) == noErr)
00176         ;
00177     } /*doclosedown*/
00178 
00179 
00180 /*
00181 static Boolean doinstall (void) {
00182     
00183     AEDesc desc;
00184     OSErr ec;
00185     Boolean flhavereply = false;
00186     AppleEvent event, reply;
00187     Str255 bserror;
00188     
00189     IACglobals.event = &event;
00190     
00191     desc.descriptorType = 'scpt';
00192     
00193     desc.dataHandle = getResourceAndDetach ('scpt', 128);
00194     
00195     if (ec != noErr)
00196         return (false);
00197     
00198     desc.descriptorType = 'mbar';
00199     
00200     desc.dataHandle = getResourceAndDetach ('mbar', 128);
00201     
00202     ec = AEPutParamDesc (&event, (AEKeyword) 'prm2', &desc);
00203     
00204     AEDisposeDesc (&desc);
00205     
00206     return (true);
00207     
00208     return (false);
00209     } /%doinstall%/
00210 */
00211     
00212 
00213 static boolean getprocessfilespec (ProcessSerialNumber psn, FSSpec *fs) {
00214     
00215     ProcessInfoRec info;
00216     
00217     info.processInfoLength = (long) sizeof (info);
00218     
00219     info.processName = nil;
00220     
00221     info.processAppSpec = fs;
00222     
00223     return (GetProcessInformation (&psn, &info) == noErr);
00224     } /*getprocessfilespec*/
00225 
00226 
00227 static Boolean dropletedit (void) {
00228     
00229     AEDesc desc;
00230     AppleEvent event, reply;
00231     ProcessSerialNumber psn;
00232     FSSpec fs;
00233     AliasHandle halias;
00234     OSErr ec;
00235     
00236     ec = OSAnewverb ('LAND', kCoreEventClass, kAEOpenDocuments, &event);
00237     
00238     if (ec != noErr)
00239         return (false); 
00240     
00241     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00242     
00243         newdescnull (&reply, typeNull);
00244     
00245     #else
00246         
00247         reply.descriptorType = typeNull;
00248 
00249         reply.dataHandle = nil;
00250     
00251     #endif
00252     
00253     psn.highLongOfPSN = 0;
00254     
00255     psn.lowLongOfPSN = kCurrentProcess;
00256     
00257     getprocessfilespec (psn, &fs);
00258     
00259     ec = NewAliasMinimal (&fs, &halias);
00260     
00261     if (ec != noErr)
00262         goto exit;  
00263     
00264     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00265     
00266         newdescwithhandle (&desc, typeAlias, (Handle) halias);
00267     
00268     #else
00269         
00270         desc.descriptorType = typeAlias;
00271 
00272         desc.dataHandle = (Handle) halias;
00273     
00274     #endif
00275     
00276     ec = AEPutParamDesc (&event, keyDirectObject, &desc); /*put alias on the event*/
00277     
00278     if (ec == noErr)
00279         ec = AESend (&event, &reply, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer, kAENormalPriority, (long) kNoTimeOut, nil, nil);
00280     
00281     exit:
00282     
00283     AEDisposeDesc (&event); 
00284     
00285     AEDisposeDesc (&reply);
00286     
00287     return (ec == noErr);
00288     } /*dropletedit*/
00289 
00290 
00291 static Boolean dropletrun (hdlcomponentglobals hcg) {
00292     
00293     AppleEvent event, reply;
00294     AEDesc scriptdesc;
00295     ComponentInstance comp;
00296     OSAID idscript;
00297     OSAError err;
00298     
00299     scriptdesc.descriptorType = 'scpt';
00300     
00301     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00302     
00303         {
00304         Handle h;
00305         
00306         h = getResourceAndDetach ('scpt', 128);
00307         
00308         newdescwithhandle (h, 'scpt', &scriptdesc);
00309         
00310         disposehandle (h);
00311         
00312         if (AEGetDescDataSize (&scriptdesc) < 1)
00313         }
00314     
00315     #else
00316     
00317         scriptdesc.dataHandle = getResourceAndDetach ('scpt', 128);
00318     
00319         if (scriptdesc.dataHandle == nil) {
00320     
00321     #endif
00322         
00323         alertuser ("\pScript resource not found.");
00324         
00325         return (false);
00326         }
00327     
00328     comp = OpenDefaultComponent (kOSAComponentType, kOSAGenericScriptingComponentSubtype);
00329     
00330     if (comp == nil) {
00331         
00332         alertuser ("\pCouldnÕt open the scripting component");
00333         
00334         return (false);
00335         }
00336     
00337     err = OSALoad (comp, &scriptdesc, kOSANullMode, &idscript);
00338     
00339     AEDisposeDesc (&scriptdesc);
00340     
00341     if (err != noErr) {
00342         
00343         alertuser ("\pError opening the script");
00344         
00345         return (false);
00346         }
00347     
00348     event = dropletglobals.initialevent;
00349     
00350     err = OSADoEvent (comp, &event, idscript, kOSANullMode, &reply);
00351     
00352     doclosedown ();
00353     
00354     return (true);
00355     } /*dropletrun*/
00356 
00357 
00358 #if 0
00359 
00360 static Boolean appRunning (OSType appid) {
00361     
00362     /*
00363     return true if the server application is running. 
00364     */
00365     
00366     ProcessInfoRec info;
00367     ProcessSerialNumber psn;
00368     Str255 bsname;
00369     FSSpec fss;
00370     
00371     info.processInfoLength = sizeof (info);
00372     
00373     info.processName = bsname; /*place to store process name*/
00374     
00375     info.processAppSpec = &fss; /*place to store process filespec*/
00376     
00377     psn.highLongOfPSN = kNoProcess;
00378     
00379     psn.lowLongOfPSN = kNoProcess;
00380     
00381     while (GetNextProcess (&psn) == noErr) {
00382         
00383         info.processInfoLength = sizeof (ProcessInfoRec);
00384         
00385         if (GetProcessInformation (&psn, &info) != noErr)
00386             continue; /*keep going -- ignore error*/
00387         
00388         if (info.processSignature == appid)
00389             return (true);
00390         } /*while*/
00391     
00392     return (false); /*loop completed, no server*/
00393     } /*appRunning*/
00394 
00395 static Boolean launchApp (FSSpec *fs) {
00396     
00397     LaunchParamBlockRec pb;
00398     OSErr errcode;
00399     
00400     clearbytes (&pb, (long) sizeof (pb));
00401     
00402     pb.launchAppSpec = fs;
00403     
00404     pb.launchBlockID = extendedBlock;
00405     
00406     pb.launchEPBLength = extendedBlockLen;
00407     
00408     pb.launchControlFlags = launchContinue | launchNoFileFlags;
00409     
00410     return (LaunchApplication (&pb) == noErr);
00411     } /*launchApp*/
00412 
00413 
00414 static Boolean launchServer (OSType serverid) {
00415     
00416     /*
00417     if the application whose creator id is serverid is running, return true.
00418     
00419     if not, we look for the application and try to launch it. we wait until it's 
00420     actually running and ready to receive Apple Events.
00421     */
00422     
00423     FSSpec fs;
00424     
00425     if (appRunning (serverid))
00426         return (true);
00427         
00428     if (!findapplication (serverid, &fs))
00429         return (false);
00430         
00431     if (!launchApp (&fs))
00432         return (false);
00433         
00434     while (!appRunning (serverid)) {
00435         
00436         EventRecord ev;
00437         
00438         EventAvail (everyEvent, &ev);
00439         } /*while*/
00440         
00441     return (true);
00442     } /*launchServer*/
00443     
00444 #endif
00445 
00446 static pascal void drawmessageitem (DialogPtr pdialog, short itemnumber) {
00447 
00448     short itemtype;
00449     Handle itemhandle;
00450     Rect itemrect;
00451     short savedfont, savedsize;
00452     Rect r;
00453     PenState savedpen;
00454     short fnum;
00455     Handle htext;
00456     
00457     long curA5 = SetUpAppA5 ();
00458     
00459     htext = getResourceAndDetach ('TEXT', 128);
00460     
00461     RestoreA5 (curA5);
00462     
00463     savedfont = (*thePort).txFont;
00464     
00465     savedsize = (*thePort).txSize;
00466     
00467     GetFNum ("\pPalatino", &fnum);
00468     
00469     TextFont (fnum);
00470     
00471     TextSize (12);
00472     
00473     GetDItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect); /*get the itemÕs rect*/
00474     
00475     r = itemrect;
00476     
00477     InsetRect (&r, 3, 3);
00478     
00479     TextBox (*htext, GetHandleSize (htext), &r, 0);
00480     
00481     TextFont (savedfont);
00482     
00483     TextSize (savedsize);
00484     
00485     GetPenState (&savedpen); /*save the old pen state*/
00486     
00487     PenPat (gray);
00488     
00489     FrameRect (&itemrect);
00490     
00491     SetPenState (&savedpen);
00492     } /*drawmessageitem*/
00493     
00494 
00495 static void drawitemstring (DialogPtr pdialog, short itemnumber, Str255 s) {
00496 
00497     short itemtype;
00498     Handle itemhandle;
00499     Rect itemrect;
00500     short savedfont, savedsize, savedstyle;
00501     Rect r;
00502     PenState savedpen;
00503     FontInfo info;
00504     RgnHandle rgn;
00505     
00506     savedfont = (*thePort).txFont;
00507     
00508     savedsize = (*thePort).txSize;
00509     
00510     savedstyle = (*thePort).txFace;
00511     
00512     TextFont (helvetica);
00513     
00514     TextSize (18);
00515     
00516     TextFace (bold);
00517     
00518     GetDItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect); /*get the itemÕs rect*/
00519     
00520     r = itemrect;
00521     
00522     GetFontInfo (&info);
00523     
00524     MoveTo (r.left, r.bottom - info.descent);
00525     
00526     GetClip (rgn = NewRgn ());
00527     
00528     ClipRect (&r);
00529     
00530     DrawString (s);
00531     
00532     SetClip (rgn);
00533     
00534     DisposeRgn (rgn);
00535     
00536     TextFont (savedfont);
00537     
00538     TextSize (savedsize);
00539     
00540     TextFace (savedstyle);
00541     } /*drawitemstring*/
00542 
00543 
00544 static pascal void drawtitleitem (DialogPtr pdialog, short itemnumber) {
00545     
00546     Str255 titlestring;
00547     long appA5;
00548     
00549     GetWTitle (pdialog, titlestring);
00550     
00551     curA5 = SetUpAppA5 ();
00552     
00553     insertstring ("\pThe Ō", titlestring);
00554     
00555     pushstring ("\pĶ Droplet", titlestring);
00556     
00557     drawitemstring (pdialog, itemnumber, titlestring);
00558     
00559     RestoreA5 (curA5);
00560     } /*drawtitleitem*/
00561 
00562 
00563 static pascal void drawiconitem (DialogPtr pdialog, short itemnumber) {
00564     
00565     short itemtype;
00566     Handle itemhandle;
00567     Rect itemrect;
00568     
00569     GetDItem (pdialog, itemnumber, &itemtype, &itemhandle, &itemrect); /*get the itemÕs rect*/
00570     
00571     PlotIconID (&itemrect, 0, 0, 128);
00572     } /*drawiconitem*/
00573 
00574 
00575 static void handledrag (EventRecord *ev, WindowPtr w) {
00576     
00577     Rect r;
00578 
00579     r = qd.screenBits.bounds; 
00580     
00581     r.top = r.top + GetMBarHeight (); 
00582     
00583     InsetRect (&r, 4, 4);
00584     
00585     DragWindow (w, (*ev).where, &r);
00586     } /*handledrag*/
00587 
00588 
00589 static void handlemenu (hdlcomponentglobals hcg, long codeword) {
00590     
00591     register short idmenu, iditem;
00592     
00593     iditem = LoWord (codeword);
00594     
00595     idmenu = HiWord (codeword);
00596     
00597     if (uisSharedMenuHit (idmenu, iditem)) /*See Step #3*/  
00598         goto exit;
00599     
00600     switch (idmenu) {
00601     
00602         case applemenu: 
00603             switch (iditem) {
00604                 
00605                 case aboutitem:
00606                     Alert (aboutalertid, nil);
00607                     
00608                     break;
00609                 
00610                 default: {
00611                 
00612                     Str255 s;
00613                     
00614                     GetItem (dropletglobals.happlemenu, iditem, s);
00615                     
00616                     OpenDeskAcc (s);
00617                     
00618                     break;
00619                     }
00620                 } /*switch*/
00621             
00622             break; /*apple menu*/
00623 
00624         case filemenu: 
00625             switch (iditem) {
00626                 
00627                 case quititem:
00628                 
00629                     dropletglobals.flexitmainloop = true;
00630                     
00631                     break;
00632                 } /*switch*/
00633             
00634             break; /*file menu*/
00635             
00636         } /*switching on which menu was invoked*/
00637         
00638     exit:
00639     
00640     HiliteMenu (0);
00641     } /*handlemenu*/
00642 
00643 
00644 static void handlemouse (hdlcomponentglobals hcg, EventRecord *ev) {
00645 
00646     register short part;
00647     WindowPtr w;
00648     
00649     part = FindWindow ((*ev).where, &w);
00650     
00651     if (w != nil) 
00652     
00653         if (w != FrontWindow ()) { /*just like all other Mac programs*/
00654             
00655             SelectWindow (w);
00656                             
00657             return; /*the mouse click is consumed by the bringtofront operation*/
00658             }
00659     
00660     switch (part) {
00661     
00662         case inMenuBar: 
00663             handlemenu (hcg, MenuSelect ((*ev).where)); 
00664             
00665             break;
00666         
00667         case inSysWindow:
00668             SystemClick (ev, w); 
00669             
00670             break;
00671         
00672         case inDrag:
00673             handledrag (ev, w);
00674             
00675             break;
00676             
00677         } /*switch*/
00678     } /*handlemouse*/
00679 
00680 #if 0
00681     
00682 static void highlightbutton (short itemnumber, Boolean flon) {
00683     
00684     short x;
00685     short itemtype;
00686     Handle itemhandle;
00687     Rect itembox;
00688     
00689     GetDItem (w, itemnumber, &itemtype, &itemhandle, &itembox);
00690     
00691     if (flon)
00692         x = inButton;
00693     else
00694         x = 0;
00695     
00696     HiliteControl ((ControlHandle) itemhandle, x); 
00697     } /*highlightbutton*/
00698 
00699     
00700 static void simulatehit (short item) {
00701     
00702     highlightbutton (item, true);
00703     
00704     delayticks (8);
00705     
00706     highlightbutton (item, false);
00707     } /*simulatehit*/
00708 
00709 #endif
00710 
00711 static Boolean handlekeystroke (hdlcomponentglobals hcg, EventRecord *ev) { 
00712 
00713     char ch = (*ev).message & charCodeMask;
00714     Boolean flcmdperiod = false;
00715     
00716     #if 0
00717     
00718     if (SharedScriptRunning ()) { /*cmd-period terminates the script*/
00719     
00720         if (((*ev).modifiers & cmdKey) && (ch == '.')) { 
00721             
00722             flcmdperiod = true;
00723             
00724             CancelSharedScript (); /*cancel the shared menu script, if one is running*/
00725             
00726             return (true);
00727             }
00728         }
00729     
00730     if ((ch == (char) 13) || (ch == (char) 3) || (ch == 'r') || (ch == 'R')) { 
00731         
00732         /*user hit Return, Enter, r or R*/
00733         
00734         if (false /*fl2click****/) /*Run button not enabled*/
00735             return (true);
00736         
00737         simulatehit (runitem);
00738     
00739         DisposDialog (w);
00740     
00741         w = nil;
00742         
00743         dropletrun ();
00744         
00745         return (false);
00746         }
00747         
00748     if ((flcmdperiod) || ((ch == 'q') || (ch == 'Q'))) { /*close the window and exit*/
00749     
00750         simulatehit (cancelitem);
00751         
00752         return (false);
00753         }
00754         
00755     if ((ch == 'e') || (ch == 'E')) {
00756         
00757         simulatehit (edititem);
00758         
00759         if (dropletedit ();
00760         
00761         return (true);
00762         }
00763     
00764     #endif
00765     
00766     if ((*ev).modifiers & cmdKey)
00767         handlemenu (hcg, MenuKey (ch)); 
00768     
00769     return (true);
00770     } /*handlekeystroke*/
00771 
00772 
00773 static void initdropletmenus (hdlcomponentglobals hcg) {
00774     
00775     /*
00776     set up our apple and file menus.  nothing fancy.
00777     */
00778     
00779     register MenuHandle hmenu;
00780     
00781     long appA5 = SetUpCurA5 ();
00782     
00783     hmenu = GetMenu (applemenu);
00784     
00785     if (hmenu != nil) {
00786         
00787         dropletglobals.happlemenu = hmenu;
00788         
00789         AddResMenu (hmenu, 'DRVR'); 
00790         
00791         InsertMenu (hmenu, 0); 
00792         }
00793     
00794     hmenu = GetMenu (filemenu);
00795     
00796     if (hmenu != nil) {
00797         
00798         dropletglobals.hfilemenu = hmenu;
00799         
00800         InsertMenu (hmenu, 0);
00801         }
00802     
00803     DrawMenuBar ();
00804     
00805     RestoreA5 (appA5);
00806     } /*initdropletmenus*/
00807 
00808 
00809 static boolean initdropletwindow (hdlcomponentglobals hcg, boolean fl2click) {
00810     
00811     ProcessSerialNumber psn;
00812     Str255 appname;
00813     DialogPtr w;
00814     boolean flignore;
00815     long appA5;
00816     
00817     psn.highLongOfPSN = 0;
00818     
00819     psn.lowLongOfPSN = kCurrentProcess;
00820     
00821     getprocessname (psn, appname, &flignore);
00822     
00823     appA5 = SetUpCurA5 ();
00824     
00825     w = GetNewDialog (mainwindowid, nil, (WindowPtr) -1);
00826     
00827     RestoreA5 (appA5);
00828     
00829     dropletglobals.pmainwindow = w;
00830     
00831     //Code change by Timothy Paustian Wednesday, August 23, 2000 9:21:06 PM
00832     //
00833     {
00834     #if TARGET_API_MAC_CARBON
00835     CGrafPtr    thePort = GetWindowPort(w);
00836     #else
00837     GrafPtr thePort = (GrafPtr)w;
00838     #endif
00839 
00840     SetPort (thePort);
00841     }
00842     
00843     SetWTitle (w, appname);
00844     
00845     if (fl2click)                   
00846         disabledialogitem (w, runitem);
00847     else
00848         setdefaultitem (w, runitem);
00849     
00850     #if flruntime
00851     
00852     disabledialogitem (w, edititem); /*disable Edit button if we're Runtime*/
00853     
00854     #endif
00855     
00856     setuseritemdrawroutine (w, iconitem, &drawiconitem);
00857     
00858     setuseritemdrawroutine (w, titleitem, &drawtitleitem);
00859     
00860     setuseritemdrawroutine (w, msgitem, &drawmessageitem);
00861     
00862     ShowWindow (w);
00863     
00864     return (true);
00865     } /*initdropletwindow*/
00866 
00867 
00868 static pascal OSErr droplethandleopendoc (AppleEvent *event, AppleEvent *reply, long refcon) {
00869     
00870     register hdlcomponentglobals hcg = (hdlcomponentglobals) refcon;
00871     AEDesc desc;
00872     OSErr ec;
00873     
00874     ec = AEDuplicateDesc (event, &desc);
00875     
00876     dropletglobals.initialevent = desc;
00877     
00878     initdropletwindow (hcg, false); /*it was a drag-and-drop*/
00879     
00880     return (ec);
00881     } /*droplethandleopendoc*/
00882 
00883 
00884 static pascal OSErr droplethandleopenapp (AppleEvent *event, AppleEvent *reply, long refcon) {
00885     
00886     register hdlcomponentglobals hcg = (hdlcomponentglobals) refcon;
00887     AEDesc desc;
00888     OSErr ec;
00889     
00890     ec = AEDuplicateDesc (event, &desc);
00891     
00892     dropletglobals.initialevent = desc;
00893     
00894     initdropletwindow (hcg, true); /*launched by 2clicking*/
00895     
00896     return (ec);
00897     } /*droplethandleopenapp*/
00898 
00899 
00900 static pascal OSErr droplethandlewildcard (AppleEvent *event, AppleEvent *reply, long refcon) {
00901     
00902     register hdlcomponentglobals hcg = (hdlcomponentglobals) refcon;
00903     
00904     initdropletwindow (hcg, true); /*launched by 2clicking*/
00905     
00906     return (noErr);
00907     } /*droplethandleopenapp*/
00908 
00909 
00910 static OSErr dropletmaineventloop (hdlcomponentglobals hglobals) {
00911     
00912     register hdlcomponentglobals hcg = hglobals;
00913     DialogPtr w = dropletglobals.pmainwindow;
00914     EventRecord ev;
00915     short itemhit;
00916     boolean fl;
00917     boolean flinstalled = false;
00918     Boolean fltoss;
00919     long appA5;
00920     
00921     while (!dropletglobals.flexitmainloop) {
00922         
00923         SetCursor (&arrow);
00924         
00925 //      osapreclientcallback (hcg);
00926         
00927         appA5 = SetUpCurA5 ();
00928         
00929         fl = WaitNextEvent (everyEvent, &ev, 30, nil);
00930         
00931         RestoreA5 (appA5z);
00932         
00933 //      osapostclientcallback (hcg);
00934         
00935         if (fl) {
00936             
00937             if (dialogevent (&ev, w, &itemhit)) {
00938                 
00939                 switch (itemhit) {
00940                     
00941                     case runitem:
00942                         DisposDialog (w);
00943                         
00944                         w = nil;
00945                         
00946                         dropletrun (hcg);
00947                         
00948                         goto endloop;
00949                     
00950                     case cancelitem:
00951                         goto endloop;
00952                     
00953                     case edititem:
00954                         if (dropletedit ())
00955                             goto endloop;
00956                         
00957                         break;
00958                     } /*switch*/
00959                 } /*dialog event*/
00960             
00961             else { /*not a dialog event*/
00962                 
00963                 switch (ev.what) {  
00964 
00965                     case mouseDown:
00966                         handlemouse (hcg, &ev);
00967                         
00968                         break;
00969                     
00970                     case kHighLevelEvent:
00971                         AEProcessAppleEvent (&ev);
00972                         
00973                         break;
00974                     } /*switch*/
00975                 }
00976             } /*WNE returned true*/
00977         else {
00978             /*      
00979             if (!flinstalled) {
00980                 
00981                 flinstalled = true;
00982                 
00983                 doinstall ();
00984                 }
00985             */
00986             
00987             uisHandleEvent (&ev, &fltoss);
00988             }
00989         } /*while*/
00990     
00991     endloop:
00992     
00993     if (w != nil)
00994         DisposDialog (w);
00995     
00996     return (noErr);
00997     } /*dropletmaineventloop*/
00998 
00999 
01000 static pascal ComponentResult rundropletcommand (hdlcomponentglobals hglobals) {
01001     
01002     OSErr err;
01003     
01004     long appA5 = SetUpCurA5 ();
01005     
01006     err = AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, (ProcPtr) &droplethandleopenapp, (long) hglobals, false);
01007     
01008     if (err == noErr)
01009         err = AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, (ProcPtr) &droplethandleopendoc, (long) hglobals, false);
01010     
01011     if (err == noErr)
01012         err = AEInstallEventHandler (typeWildCard, typeWildCard, (ProcPtr) &droplethandlewildcard, (long) hglobals, false);
01013     
01014     RestoreA5 (appA5);
01015     
01016     if (err != noErr)
01017         return (err);
01018     
01019     initdropletmenus (hglobals);
01020     
01021     uisInit (&alertuser, 140, 0, noWindowSharing);
01022     
01023     err = dropletmaineventloop (hglobals);
01024     
01025     uisClose ();
01026     
01027     return (err);
01028     } /*rundropletcommand*/
01029 
01030 
01031 static pascal ComponentResult dropletcandofunction (short selector) {
01032     
01033     switch (selector) {
01034         
01035         case kComponentOpenSelect:
01036         case kComponentCloseSelect:
01037         case kComponentCanDoSelect:
01038         case kComponentVersionSelect:
01039         
01040         case kDropletRunAppSelect:
01041             return (true);
01042         }
01043     
01044     return (false);
01045     } /*dropletcandofunction*/
01046 
01047 
01048 static pascal ComponentResult dropletdispatch (register ComponentParameters *params, Handle storage) {
01049     
01050     ComponentResult result = noErr;
01051     short what = (*params).what;
01052     
01053     long curA5 = SetUpAppA5 ();
01054     
01055     switch (what) {
01056         
01057         case kComponentOpenSelect: { /*can't call subroutine because a5 isn't ours*/
01058             
01059             hdlcomponentglobals hglobals;
01060             Component self = (Component) (*params).params [0];
01061             long selfa5;
01062             long clienta5;
01063             
01064             /*
01065             selfa5 = GetComponentRefcon (self);
01066             
01067             asm {
01068                 move.l  a5,clienta5
01069                 move.l  a5,-(a7)
01070                 move.l  selfa5,a5
01071                 }
01072             
01073             SetComponentInstanceA5 ((ComponentInstance) self, selfa5);
01074             */
01075             
01076             if (newcomponentglobals (self, clienta5, &hglobals))
01077                 SetComponentInstanceStorage ((ComponentInstance) self, (Handle) hglobals);
01078             else
01079                 result = memFullErr;
01080             
01081             /*
01082             asm {
01083                 move.l  (a7)+,a5
01084                 }
01085             */
01086             
01087             break;
01088             }
01089         
01090         case kComponentCloseSelect:
01091             disposecomponentglobals ((hdlcomponentglobals) storage);
01092             
01093             result = noErr;
01094             
01095             break;
01096         
01097         case kComponentCanDoSelect:
01098             result = CallComponentFunction (params, &dropletcandofunction))
01099             break;
01100         
01101         case kComponentVersionSelect:
01102             result = 0x04100100;
01103             
01104             break;
01105         
01106         case kDropletRunAppSelect:
01107             result = callosafunction (storage, params, &rundropletcommand);
01108             
01109             break;
01110         
01111         default:
01112             result = badComponentSelector;
01113             
01114             break;
01115         }
01116     
01117     RestoreA5 (curA5);
01118     
01119     return (result);
01120     } /*dropletdispatch*/
01121 
01122 
01123 boolean initdropletcomponent (void) {
01124     
01125     /*
01126     register the window sharing component.
01127     */
01128     
01129     long result;
01130     ComponentDescription desc;
01131     bigstring bs;
01132     Handle hname, hdescription, hicon;
01133     Component comp;
01134     
01135     #if !TARGET_API_MAC_CARBON
01136     RememberA5 ();
01137     #endif
01138     
01139     desc.componentType = 'aplt';
01140     
01141     desc.componentSubType = 'LAND';
01142     
01143     desc.componentManufacturer = 'LAND';
01144     
01145     desc.componentFlags = 0;
01146     
01147     desc.componentFlagsMask = 0;
01148     
01149     hname = (Handle) GetString (iddropletstring);
01150     
01151     hdescription = (Handle) GetString (iddropletdescriptionstring);
01152     
01153     hicon = GetIcon (129); /****should be droplet icon*/
01154     
01155     comp = RegisterComponent (&desc, NewComponentRoutineProc (dropletdispatch), true, hname, hdescription, hicon);
01156     
01157     if (comp == nil)
01158         return (false);
01159     
01160     SetComponentRefcon (comp, (long) CurrentA5);
01161     
01162     return (true);
01163     } /*initdropletcomponent*/
01164 
01165 #endif
01166 

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