appletwires.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletwires.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include <GestaltEqu.h>
00008 #include <iac.h>
00009 #include "appletinternal.h"
00010 #include "appletmain.h"
00011 #include "appletmenu.h"
00012 #include "appletscrollbar.h"
00013 #include "appletmenuops.h"
00014 #include "appletresource.h"
00015 #include "appletmsg.h"
00016 #include "appletcardops.h"
00017 #include "appletwires.h"
00018 
00019 
00020 /*
00021 IAC messages implemented by the Applet Toolkit layer.
00022 */
00023     #define alertdialogtoken    'alrt'
00024     #define confirmdialogtoken  'cnfm'
00025     #define askdialogtoken      'askd'
00026         
00027     #define enabledialogtoken   'enbd'
00028     #define geterrorstringtoken 'gers'
00029     
00030     #define gettargettoken      'gtrg'
00031     #define settargettoken      'strg'
00032     
00033     #define newwindowtoken      'nwin'
00034     #define openwindowtoken     'owin'
00035     #define editwindowtoken     'ewin'
00036     #define closewindowtoken    'cwin'
00037     #define savewindowtoken     'swin'
00038     #define revertwindowtoken   'rwin'
00039     #define movewindowtoken     'mwin'
00040     #define printwindowtoken    'pwin'
00041     #define selectwindowtoken   'xwin'
00042     #define zoomwindowtoken     'zwin'
00043     
00044     #define getfilepathtoken    'gpth'
00045     #define getwindowpostoken   'gwps'
00046     #define madechangestoken    'chgs'
00047 
00048     #define getpicttoken        'gpic'
00049     #define gettexttoken        'gtex'
00050     #define putpicttoken        'ppic'
00051     #define puttexttoken        'ptex'
00052     #define selectalltoken      'sela'
00053     #define haveselectiontoken  'hsel'
00054     
00055     #define countwindowstoken   'twin'
00056     #define nthwindowtoken      'nthw'
00057     #define quittoken           'quit'
00058     
00059     #define setfonttoken        'sfon'
00060     #define setfontsizetoken    'sfsz'
00061 
00062     #define getpagerecttoken    'gprc'
00063     #define getwindowrecttoken  'gwrc'
00064     #define getbinarytoken      'gbin'
00065     #define putbinarytoken      'pbin'
00066     #define scrollwindowtoken   'lwin'
00067     #define perftesttoken       'perf'
00068     
00069     #define runcardtoken        'runc'
00070     #define windowmessagetoken  'wmsg'
00071     
00072     #define getmemavailtoken    'mema'
00073     
00074     #define getfiletoken        'gfil'
00075 
00076     
00077 bigstring bstargetwindowname; /*title of window that IAC verbs apply to*/
00078 
00079 extern bigstring bsvisit; /*use appletmain's string for visiting windows*/
00080 
00081 
00082 
00083 static boolean settargetvisit (hdlappwindow appwindow) {
00084     
00085     bigstring bs;
00086     
00087     getappwindowtitle (appwindow, bs);
00088     
00089     if (!equalstrings (bsvisit, bs)) /*no match -- keep traversing*/
00090         return (true);
00091     
00092     /*found a match, stop the traversal*/
00093     
00094     setappwindow (appwindow);
00095     
00096     return (false); /*stop the traversal*/
00097     } /*settargetvisit*/
00098     
00099     
00100 static boolean setapptarget (bigstring bs) {
00101     
00102     /*
00103     set the globals for the window with the indicated name without bringing
00104     the window to the front.
00105     */
00106     
00107     setappwindow (nil);
00108     
00109     copystring (bs, bsvisit); /*copy into global so visit routine can access*/
00110     
00111     visitappwindows (&settargetvisit);
00112     
00113     return (app.appwindow != nil);
00114     } /*setapptarget*/  
00115     
00116 
00117 boolean settargetglobals (void) {
00118     
00119     /*
00120     get ready to do an operation on the target window.  if the name is empty,
00121     we do the operation on the frontmost window.
00122     
00123     the target window name is set using the 'sett' IAC call.
00124     
00125     return an error to the script if the target window doesn't exist.
00126     
00127     DW 11/3/93: handle case where target window was closed.
00128     */
00129     
00130     if (stringlength (bstargetwindowname) == 0) { /*no target has been established*/
00131         
00132         if (!setfrontglobals ()) /*no windows are open*/
00133             goto error;
00134             
00135         return (true);
00136         }
00137         
00138     if (!setapptarget (bstargetwindowname)) {
00139         
00140         setstringlength (bstargetwindowname, 0); /*DW 11/3/93*/
00141         
00142         if (!setfrontglobals ()) /*no windows are open*/
00143             goto error;
00144         }
00145         
00146     return (true);
00147     
00148     error:
00149     
00150     IACreturnerror (1, "\pNo window is open.");
00151     
00152     return (false); /*no window open, stop processing the message*/
00153     } /*settargetglobals*/
00154     
00155     
00156 static boolean setwindowtitleverb (void) {
00157     
00158     /*
00159     verb that sets the window title of the target window.
00160     */
00161     
00162     bigstring bs;
00163     
00164     if (!settargetglobals ()) /*this verb requires an open window*/
00165         return (false);
00166         
00167     if (!IACgetstringparam (keyDirectObject, bs))
00168         return (false);
00169         
00170     setappwindowtitle (app.appwindow, bs);
00171     
00172     copystring (bs, bstargetwindowname);
00173         
00174     return (IACreturnboolean (true));
00175     } /*setwindowtitleverb*/
00176     
00177     
00178 static boolean getwindowrectverb (void) { 
00179     
00180     hdlappwindow ha = app.appwindow;
00181     Rect r = (**app.appwindow).contentrect;
00182     
00183     OffsetRect (&r, (**ha).scrollorigin.h, (**ha).scrollorigin.v);
00184     
00185     return (IACreturnrect (&r));
00186     } /*getwindowrectverb*/
00187     
00188     
00189 static boolean closewindowverb (void) {
00190     
00191     /*
00192     verb that closes an existing window.  it takes no parameters, the
00193     current target window is closed.
00194     
00195     8/25/92 DW: if we close the target window, reset the target to the
00196     frontmost window.
00197     */
00198     
00199     boolean fl = false;
00200     hdlappwindow ha;
00201     boolean flresettarget;
00202     
00203     flresettarget = stringlength (bstargetwindowname) > 0;
00204     
00205     if (!settargetglobals ()) /*this verb requires an open window*/
00206         return (false);
00207     
00208     ha = app.appwindow;
00209     
00210     if (ha != nil) { /*a window is open*/
00211     
00212         fl = closeappwindow (ha, fldialogsenabled);
00213         
00214         if (fl && flresettarget)
00215             setstringlength (bstargetwindowname, 0); 
00216         }
00217         
00218     return (IACreturnboolean (fl));
00219     } /*closewindowverb*/
00220     
00221     
00222 static boolean revertverb (void) {
00223     
00224     if (!settargetglobals ()) /*this verb requires an open window*/
00225         return (false);
00226         
00227     return (IACreturnboolean (revertfrontwindow ()));
00228     } /*revertverb*/
00229     
00230     
00231 static boolean zoomwindowverb (void) {
00232     
00233     if (!settargetglobals ()) /*this verb requires an open window*/
00234         return (false);
00235         
00236     zoomappwindow (app.appwindow);
00237         
00238     return (IACreturnboolean (true));
00239     } /*zoomwindowverb*/
00240     
00241 
00242 static boolean scrollwindowverb (void) {
00243     
00244     short x;
00245     tydirection dir;
00246     short ct;
00247 
00248     if (!settargetglobals ()) /*this verb requires an open window*/
00249         return (false);
00250         
00251     if (!IACgetshortparam ('dire', &x))
00252         return (false);
00253     
00254     dir = (tydirection) x;
00255     
00256     if (!IACgetshortparam ('coun', &ct))
00257         return (false);
00258         
00259     scrollappwindow (dir, false, ct);
00260         
00261     return (IACreturnboolean (true));
00262     } /*scrollwindowverb*/
00263     
00264 
00265 static boolean verbmakefilespec (bigstring path, short vnum, ptrfilespec pfs) {
00266     
00267     bigstring bserror;
00268     
00269     if (filemakespec (0, 0, path, pfs))
00270         return (true);
00271         
00272     copystring ("\pCant create a filespec for ", bserror);
00273     
00274     pushstring (path, bserror);
00275     
00276     pushstring ("\p.", bserror);
00277     
00278     alertdialog (bserror);
00279     
00280     return (false);
00281     } /*verbmakefilespec*/
00282     
00283     
00284 static boolean saveasverb (void) {
00285     
00286     boolean fl = false;
00287     bigstring path;
00288     
00289     if (!settargetglobals ()) /*this verb requires an open window*/
00290         return (false);
00291         
00292     if (!IACgetstringparam (keyDirectObject, path))
00293         return (false);
00294         
00295     if (stringlength (path) == 0) {
00296     
00297         fl = savefrontwindow ();
00298         }
00299     else {
00300         tyfilespec fs;
00301         
00302         if (verbmakefilespec (path, 0, &fs))
00303             fl = saveaswindow (&fs);
00304         }
00305         
00306     return (IACreturnboolean (fl));
00307     } /*saveasverb*/
00308     
00309     
00310 static boolean openverb (void) {
00311     
00312     boolean fl = false;
00313     bigstring path;
00314     tyfilespec fs;
00315     
00316     setstringlength (bsalertstring, 0);
00317     
00318     if (!IACgetstringparam (keyDirectObject, path))
00319         return (false);
00320     
00321     if (verbmakefilespec (path, 0, &fs))
00322         fl = openappwindow (&fs);
00323         
00324     return (IACreturnboolean (fl));
00325     } /*openverb*/
00326 
00327 
00328 static boolean editverb (void) {
00329     
00330     /*
00331     4.1b1 dmb: new verb to open a new window and edit caller's data
00332     */
00333     
00334     boolean fl = false;
00335     Handle hpacked = nil;
00336     OSType binarytype;
00337     AEDesc refdesc = {typeNull, nil};
00338     bigstring bs;
00339     OSType sender;
00340     
00341     if (!IACgetbinaryparam (keyDirectObject, &hpacked, &binarytype))
00342         return (false);
00343     
00344     if (!IACgetbinaryparam ('refc', &refdesc.dataHandle, &refdesc.descriptorType))
00345         goto error;
00346     
00347     IACglobals.nextparamoptional = true;
00348     
00349     if (!IACgetstringparam ('titl', bs))
00350         setemptystring (bs);
00351     
00352     sender = IACgetsender ();
00353     
00354     if (!editappwindow (hpacked, sender, &refdesc, bs))
00355         goto error;
00356     
00357     return (IACreturnboolean (true));
00358     
00359     error:
00360     
00361         AEDisposeDesc (&refdesc);
00362         
00363         disposehandle (hpacked);
00364         
00365         return (IACreturnboolean (false));
00366     } /*editverb*/
00367 
00368 
00369 static boolean nthwindowverb (void) {
00370     
00371     bigstring bs;
00372     short n;
00373     hdlappwindow appwindow;
00374     
00375     if (!IACgetshortparam (keyDirectObject, &n))
00376         return (false);
00377         
00378     findnthwindow (n, &appwindow);
00379     
00380     getappwindowtitle (appwindow, bs);
00381     
00382     return (IACreturnstring (bs));
00383     } /*nthwindowverb*/
00384     
00385     
00386 static boolean selectwindowverb (void) {
00387     
00388     /*
00389     verb that brings a window to the front, you provide the name of the window in 
00390     a string parameter.  side effect -- it also sets the target to that window.
00391     */
00392     
00393     boolean fl = false;
00394     bigstring bs;
00395     
00396     if (!IACgetstringparam (keyDirectObject, bs))
00397         return (false);
00398         
00399     if (selectwindowbytitle (bs)) {
00400         
00401         fl = true;
00402         
00403         copystring (bs, bstargetwindowname);
00404         }
00405         
00406     return (IACreturnboolean (fl));
00407     } /*selectwindowverb*/
00408     
00409     
00410 static boolean perftestverb (void) {
00411     
00412     /*
00413     this verb supports a performance benchmark script written in Frontier.
00414     
00415     6/28/91 DW: perform rectangle subtraction on two rectangle params,
00416     return the difference.
00417     */
00418     
00419     Rect r1, r2, r;
00420     
00421     if (!IACgetrectparam ('prm1', &r1))
00422         return (false);
00423         
00424     if (!IACgetrectparam ('prm2', &r2))
00425         return (false);
00426         
00427     r.top = r1.top - r2.top;
00428     
00429     r.left = r1.left - r2.left;
00430     
00431     r.bottom = r1.bottom - r2.bottom;
00432     
00433     r.right = r1.right - r2.right;
00434     
00435     return (IACreturnrect (&r));
00436     } /*perftestverb*/
00437 
00438 
00439 static boolean windowmessageverb (void) {
00440 
00441     bigstring bs;
00442     
00443     if (!settargetglobals ()) /*this verb requires an open window*/
00444         return (false);
00445         
00446     if (!IACgetstringparam (keyDirectObject, bs))
00447         return (false);
00448         
00449     if (app.hasmessagearea)
00450         appsetmessage (app.appwindow, bs);
00451         
00452     return (IACreturnboolean (app.hasmessagearea));
00453     } /*windowmessageverb*/
00454     
00455 
00456 static void getmemavailverb (void) {
00457 
00458     IACreturnlong (FreeMem ());
00459     } /*getmemavailverb*/
00460 
00461 
00462 static boolean alertdialogverb (void) {
00463     
00464     /*
00465     opens up a modal dialog box with the string parameter displayed, wait for
00466     the user to click on OK before returning the value. 
00467 
00468     to support runtime menus, you wire your dialog boxes to IAC events if you want 
00469     script writers to be able to transparently talk to the user without Frontier 
00470     coming to the front.
00471     */
00472     
00473     bigstring bs;
00474     
00475     if (!IACgetstringparam (keyDirectObject, bs))
00476         return (false);
00477         
00478     return (IACreturnboolean (alertdialog (bs)));
00479     } /*alertdialogverb*/
00480     
00481     
00482 static boolean confirmdialogverb (void) {
00483     
00484     /*
00485     opens up a modal dialog box with the string parameter displayed, wait for
00486     the user to click on OK before returning the value. 
00487 
00488     to support runtime menus, you wire your dialog boxes to IAC events if you want 
00489     script writers to be able to transparently talk to the user without Frontier 
00490     coming to the front.
00491     */
00492     
00493     bigstring bs;
00494     
00495     if (!IACgetstringparam (keyDirectObject, bs))
00496         return (false);
00497     
00498     return (IACreturnboolean (confirmdialog (bs)));
00499     } /*confirmdialogverb*/
00500     
00501     
00502 static boolean askdialogverb (void) {
00503     
00504     /*
00505     to support runtime menus, you wire your dialog boxes to IAC events if you want 
00506     script writers to be able to transparently talk to the user without Frontier 
00507     coming to the front.
00508     */
00509     
00510     bigstring prompt, answer;
00511     boolean fl;
00512     
00513     if (!IACgetstringparam (keyDirectObject, prompt))
00514         return (false);
00515         
00516     if (!IACgetstringparam ('dflt', answer))
00517         return (false);
00518         
00519     fl = askdialog (prompt, answer);
00520         
00521     IACglobals.event = IACglobals.reply; /*push the params onto the reply record*/
00522     
00523     if (!IACpushstringparam (answer, 'ansr'))
00524         return (false);
00525         
00526     return (IACreturnboolean (fl));
00527     } /*askdialogverb*/
00528 
00529     
00530 static boolean settargetverb (void) {
00531     
00532     /*
00533     set the target of all subsequent verbs to the window named by the string
00534     parameter.  
00535     
00536     special case: set the target string to the empty string if you want verbs 
00537     to apply to the frontmost window.
00538     
00539     returns the title of the target window.
00540     */
00541     
00542     boolean fl = true;
00543     bigstring bs;
00544     
00545     if (!IACgetstringparam (keyDirectObject, bs))
00546         return (false);
00547     
00548     if (stringlength (bs) == 0) { /*special case*/
00549     
00550         if (setfrontglobals ())
00551             getappwindowtitle (app.appwindow, bs);
00552         }
00553         
00554     else {
00555         if (!setapptarget (bs)) 
00556             setstringlength (bs, 0);
00557         }
00558     
00559     copystring (bs, bstargetwindowname);
00560     
00561     return (IACreturnstring (bs));
00562     } /*settargetverb*/
00563 
00564 
00565 static boolean gettargetverb (void) {
00566     
00567     /*
00568     returns the title of the target window.
00569     */
00570     
00571     bigstring bs;
00572     
00573     if (!settargetglobals ()) /*this verb requires an open window*/
00574         return (false);
00575         
00576     getappwindowtitle (app.appwindow, bs);
00577         
00578     return (IACreturnstring (bs));
00579     } /*gettargetverb*/
00580     
00581     
00582 static boolean getfileverb (void) {
00583     
00584     /*
00585     DW 11/7/95 -- a low-level verb that gets you the file attached to
00586     the current window, useful for calling back to in Clay Basket
00587     macros.
00588     */
00589     
00590     tyfilespec fs;
00591     
00592     if (app.appwindow == nil) {
00593     
00594         IACreturnerror (1, "\pNo window is open.");
00595         
00596         return (false);
00597         }
00598 
00599     fs = (**app.appwindow).filespec;
00600         
00601     return (IACreturnfilespec (&fs));
00602     } /*getfileverb*/
00603     
00604 
00605 static boolean newwindowverb (void) {
00606     
00607     boolean fl = false;
00608     hdlappwindow appwindow;
00609     bigstring bs;
00610     
00611     setstringlength (bsalertstring, 0);
00612     
00613     if (!IACgetstringparam (keyDirectObject, bs))
00614         return (false);
00615         
00616     if (stringlength (bs) == 0)
00617         getuntitledtitle (bs);
00618         
00619     if (findbywindowtitle (bs, &appwindow)) {
00620         
00621         alertdialog ("\pA window with that name is already open.");
00622         
00623         setstringlength (bs, 0); /*return the empty string to indicate error*/
00624         }
00625     else {
00626         if (newappwindow (bs, true)) {
00627             
00628             fl = true;
00629             
00630             copystring (bs, bstargetwindowname);
00631             }
00632         }
00633         
00634     return (IACreturnstring (bs));
00635     } /*newwindowverb*/
00636     
00637     
00638 static boolean madechangesverb (void) {
00639 
00640     if (!settargetglobals ()) /*this verb requires an open window*/
00641         return (false);
00642         
00643     return (IACreturnboolean ((**app.appwindow).flmadechanges));
00644     } /*madechangesverb*/
00645 
00646 
00647 static boolean countwindowsverb (void) {
00648 
00649     return (IACreturnshort (countwindows ()));
00650     } /*countwindowsverb*/
00651 
00652 
00653 static boolean selectallverb (void) {
00654     
00655     boolean fl;
00656     
00657     if (!settargetglobals ()) /*this verb requires an open window*/
00658         return (false);
00659         
00660     fl = selectallcommand ();
00661     
00662     return (IACreturnboolean (fl));
00663     } /*selectallverb*/
00664 
00665 
00666 static boolean haveselectionverb (void) {
00667     
00668     boolean fl;
00669     
00670     if (!settargetglobals ()) /*this verb requires an open window*/
00671         return (false);
00672         
00673     fl = (*app.haveselectioncallback) ();
00674     
00675     return (IACreturnboolean (fl));
00676     } /*haveselectionverb*/
00677 
00678 
00679 static boolean setfontverb (void) {
00680     
00681     bigstring bs;
00682     
00683     if (!settargetglobals ()) /*this verb requires an open window*/
00684         return (false);
00685         
00686     if (!IACgetstringparam (keyDirectObject, bs))
00687         return (false);
00688         
00689     appsetfont (bs);
00690     
00691     return (IACreturnboolean (true));
00692     } /*setfontverb*/
00693     
00694     
00695 static boolean setfontsizeverb (void) {
00696     
00697     short fontsize;
00698     
00699     if (!settargetglobals ()) /*this verb requires an open window*/
00700         return (false);
00701         
00702     if (!IACgetshortparam (keyDirectObject, &fontsize))
00703         return (false);
00704         
00705     appsetfontsize (fontsize);
00706     
00707     return (IACreturnboolean (true));
00708     } /*setfontsizeverb*/
00709     
00710     
00711 static boolean printwindowverb (void) {
00712 
00713     if (!settargetglobals ()) /*this verb requires an open window*/
00714         return (false);
00715         
00716     return (IACreturnboolean (printappwindow (app.appwindow, false)));
00717     } /*printwindowverb*/
00718 
00719 
00720 static boolean enablealertverb (void) {
00721     
00722     boolean fl;
00723     Boolean flenabled;
00724     
00725     if (!IACgetbooleanparam (keyDirectObject, &flenabled))
00726         return (false);
00727         
00728     fl = fldialogsenabled; /*return the original value, per spec*/
00729     
00730     fldialogsenabled = flenabled;
00731     
00732     return (IACreturnboolean (fl));
00733     } /*enablealertverb*/
00734 
00735 
00736 static boolean quitverb (void) {
00737     
00738     return (IACreturnboolean (exitmainloop ()));
00739     } /*quitverb*/
00740 
00741 
00742 static boolean geterrorstringverb (void) {
00743     
00744     return (IACreturnstring (bsalertstring));
00745     } /*geterrorstringverb*/
00746     
00747     
00748 static boolean movewindowverb (void) {
00749     
00750     Rect r;
00751     WindowPtr w;
00752     Rect oldportrect;
00753     
00754     if (!settargetglobals ()) /*this verb requires an open window*/
00755         return (false);
00756         
00757     w = (**app.appwindow).macwindow;
00758 
00759     oldportrect = (*w).portRect;
00760     
00761     if (!IACgetrectparam (keyDirectObject, &r))
00762         return (false);
00763     
00764     moveappwindow (app.appwindow, r);
00765     
00766     adjustaftergrow (w, oldportrect); 
00767         
00768     return (IACreturnboolean (true));
00769     } /*movewindowverb*/
00770     
00771     
00772 static boolean getfilepathverb (void) {
00773     
00774     tyfilespec fs;
00775     
00776     if (!settargetglobals ()) /*this verb requires an open window*/
00777         return (false);
00778     
00779     fs = (**app.appwindow).filespec;
00780     
00781     return (IACreturnfilespec (&fs));
00782     } /*getfilepathverb*/
00783     
00784     
00785 static boolean getpictverb (void) {
00786 
00787     Handle hpict;
00788 
00789     if (!settargetglobals ()) /*this verb requires an open window*/
00790         return (false);
00791     
00792     hpict = nil;
00793     
00794     (*app.getpictcallback) (&hpict); /*hpict is nil if it failed*/
00795     
00796     return (IACreturnbinary (hpict, 'BINA'));
00797     } /*getpictverb*/
00798 
00799 
00800 static boolean gettextverb (void) {
00801 
00802     Handle htext;
00803 
00804     if (!settargetglobals ()) /*this verb requires an open window*/
00805         return (false);
00806     
00807     htext = nil;
00808         
00809     (*app.gettextcallback) (&htext); /*htext is nil if it failed*/
00810     
00811     return (IACreturntext (htext));
00812     } /*gettextverb*/
00813 
00814 
00815 static boolean putpictverb (void) {
00816 
00817     Handle hpict;
00818     boolean fl;
00819     OSType binarytype;
00820 
00821     if (!settargetglobals ()) /*this verb requires an open window*/
00822         return (false);
00823         
00824     if (!IACgetbinaryparam (keyDirectObject, &hpict, &binarytype))
00825         return (false);
00826         
00827     fl = (*app.putpictcallback) (hpict); 
00828     
00829     return (IACreturnboolean (fl));
00830     } /*putpictverb*/
00831 
00832 
00833 static boolean puttextverb (void) {
00834 
00835     Handle htext;
00836     boolean fl;
00837 
00838     if (!settargetglobals ()) /*this verb requires an open window*/
00839         return (false);
00840         
00841     if (!IACgettextparam (keyDirectObject, &htext))
00842         return (false);
00843         
00844     fl = (*app.puttextcallback) (htext);
00845     
00846     return (IACreturnboolean (fl));
00847     } /*puttextverb*/
00848 
00849 
00850 static boolean getbinaryverb (void) {
00851 
00852     AEDesc desc;
00853     OSErr ec;
00854 
00855     if (!settargetglobals ()) /*this verb requires an open window*/
00856         return (false);
00857     
00858     desc.dataHandle = nil;
00859     
00860     desc.descriptorType = app.filetype;
00861     
00862     (*app.packcallback) (&desc.dataHandle);
00863     
00864     ec = AEPutParamDesc (IACglobals.reply, keyDirectObject, &desc);
00865     
00866     AEDisposeDesc (&desc);
00867     
00868     return (true);
00869     } /*getbinaryverb*/
00870 
00871 
00872 static boolean putbinaryverb (void) {
00873 
00874     AEDesc result;
00875     OSErr ec;
00876     boolean fl;
00877 
00878     if (!settargetglobals ()) /*this verb requires an open window*/
00879         return (false);
00880         
00881     ec = AEGetParamDesc (IACglobals.event, keyDirectObject, app.filetype, &result);
00882     
00883     fl = (*app.unpackcallback) (result.dataHandle); 
00884     
00885     AEDisposeDesc (&result);
00886     
00887     return (IACreturnboolean (fl));
00888     } /*putbinaryverb*/
00889     
00890     
00891 static void modelessfilter (EventRecord *ev) {
00892     
00893     switch ((*ev).what) {
00894         
00895         case iowaButtonHitEvent:
00896             (*ev).what = iowaRunScriptEvent;
00897             
00898             break;
00899         } /*switch*/
00900     } /*modelessfilter*/
00901 
00902 
00903 boolean appruncard (Handle hpackedcard) { 
00904     
00905     tycardeventcallback cb;
00906     
00907     if (cardIsModal (hpackedcard))
00908         cb = &appscriptedmodalcardfilter;
00909     else
00910         cb = &modelessfilter;
00911     
00912     return (runCard (hpackedcard, true, 0, 0, cb));
00913     } /*appruncard*/
00914 
00915 
00916 #ifdef appRunsCards
00917 
00918     static boolean runcardverb (void) {
00919     
00920         Handle hpackedcard;
00921         OSType binarytype;
00922     
00923         if (!IACgetbinaryparam (keyDirectObject, &hpackedcard, &binarytype))
00924             return (false);
00925             
00926         return (IACreturnboolean (appruncard (hpackedcard)));
00927         } /*runcardverb*/
00928     
00929 #endif
00930 
00931 
00932 static boolean getpagerectverb (void) {
00933     
00934     getprintinfo ();
00935     
00936     return (IACreturnrect (&app.printinfo.paperrect));
00937     } /*getpagerectverb*/
00938     
00939 
00940 static boolean getwindowposverb (void) {
00941     
00942     Rect r;
00943     
00944     if (!settargetglobals ()) /*this verb requires an open window*/
00945         return (false);
00946         
00947     r = (**app.appwindow).windowrect;
00948     
00949     localtoglobalrect (&r);
00950         
00951     return (IACreturnrect (&r));
00952     } /*getwindowposverb*/
00953     
00954     
00955 static pascal OSErr handlecustomverb (AppleEvent *event, AppleEvent *reply, long refcon) {
00956 
00957     IACglobals.event = event; 
00958     
00959     IACglobals.reply = reply;
00960     
00961     IACglobals.refcon = refcon;
00962     
00963     appprecallback ();
00964     
00965     (*app.iacmessagecallback) ();
00966     
00967     apppostcallback ();
00968     
00969     return (noErr);
00970     } /*handlecustomverb*/
00971 
00972 
00973 static pascal OSErr handlefastverb (AppleEvent *event, AppleEvent *reply, long refcon) {
00974     
00975     IACglobals.event = event; 
00976     
00977     IACglobals.reply = reply;
00978     
00979     IACglobals.refcon = refcon;
00980     
00981     appprecallback ();
00982     
00983     app.insyseventhandler = true;
00984     
00985     (*app.iacfastmessagecallback) ();
00986     
00987     app.insyseventhandler = false;
00988         
00989     apppostcallback ();
00990     
00991     return (noErr);
00992     } /*handlefastverb*/
00993     
00994     
00995 static pascal OSErr handleapp1verb (AppleEvent *event, AppleEvent *reply, long refcon) {
00996     
00997     /*
00998     called by Apple Event Manager when an 'app1' verb arrives.
00999     
01000     we always return noErr to the Apple Event Manager -- each verb processor
01001     may set the error number and string in the reply record by calling 
01002     IACreturnerror.
01003     */
01004     
01005     OSType token;
01006     
01007     IACglobals.event = event; 
01008     
01009     IACglobals.reply = reply;
01010     
01011     IACglobals.refcon = refcon;
01012     
01013     token = IACgetverbtoken ();
01014         
01015     switch (token) {
01016     
01017         case newwindowtoken:
01018             newwindowverb (); break;
01019             
01020         case closewindowtoken:
01021             closewindowverb (); break;
01022         
01023         case savewindowtoken:
01024             saveasverb (); break;
01025             
01026         case revertwindowtoken:
01027             revertverb (); break;
01028             
01029         case openwindowtoken:
01030             openverb (); break;
01031         
01032         case editwindowtoken:
01033             editverb (); break;
01034         
01035         case gettargettoken:
01036             gettargetverb (); break;
01037                 
01038         case selectwindowtoken:
01039             selectwindowverb (); break;
01040             
01041         case zoomwindowtoken:
01042             zoomwindowverb (); break;
01043             
01044         case scrollwindowtoken:
01045             scrollwindowverb (); break;
01046             
01047         case perftesttoken:
01048             perftestverb (); break;
01049             
01050         case alertdialogtoken:
01051             alertdialogverb (); break;
01052             
01053         case askdialogtoken:
01054             askdialogverb (); break;
01055             
01056         case confirmdialogtoken:
01057             confirmdialogverb (); break;
01058             
01059         case settargettoken:
01060             settargetverb (); break;
01061             
01062         case madechangestoken:
01063             madechangesverb (); break;
01064             
01065         case enabledialogtoken:
01066             enablealertverb (); break;
01067             
01068         case geterrorstringtoken:
01069             geterrorstringverb (); break;
01070             
01071         case nthwindowtoken:
01072             nthwindowverb (); break;
01073             
01074         case getfilepathtoken:
01075             getfilepathverb (); break;
01076             
01077         case movewindowtoken:
01078             movewindowverb (); break;
01079             
01080         case printwindowtoken:
01081             printwindowverb (); break;
01082             
01083         case getpagerecttoken:
01084             getpagerectverb (); break;
01085             
01086         case quittoken:
01087             quitverb (); break;
01088             
01089         case getwindowpostoken:
01090             getwindowposverb (); break;
01091             
01092         case countwindowstoken:
01093             countwindowsverb (); break; 
01094     
01095         case getpicttoken:
01096             getpictverb (); break;
01097         
01098         case gettexttoken:
01099             gettextverb (); break;
01100             
01101         case putpicttoken:
01102             putpictverb (); break;
01103             
01104         case puttexttoken:
01105             puttextverb (); break;
01106             
01107         case selectalltoken:
01108             selectallverb (); break;
01109             
01110         case haveselectiontoken:
01111             haveselectionverb (); break;
01112             
01113         case getwindowrecttoken:
01114             getwindowrectverb (); break;
01115             
01116         case setfonttoken:
01117             setfontverb (); break;
01118             
01119         case setfontsizetoken:
01120             setfontsizeverb (); break;
01121             
01122         case getbinarytoken:
01123             getbinaryverb (); break;
01124             
01125         case putbinarytoken:
01126             putbinaryverb (); break;
01127             
01128         case windowmessagetoken:
01129             windowmessageverb (); break;
01130             
01131         case getmemavailtoken:
01132             getmemavailverb (); break;
01133             
01134         case getfiletoken:
01135             getfileverb (); break;
01136         
01137         #ifdef appRunsCards 
01138         
01139             case runcardtoken:
01140                 runcardverb (); break;
01141             
01142         #endif
01143             
01144         default:
01145             IACnothandlederror (); break;
01146         } /*switch*/
01147         
01148     return (noErr);
01149     } /*handleapp1verb*/
01150     
01151 
01152 static pascal Boolean openfilespec (ptrfilespec pfs) {
01153     
01154     if ((*app.opendoccallback) (pfs)) /*the application handled the opendoc event*/
01155         return (true);
01156         
01157     #ifdef appRunsCards
01158     
01159         if (app.filetype != 'CARD') { /*it's Card Editor! or another app that opens cards*/
01160         
01161             tyfileinfo info;
01162             
01163             filegetinfo (pfs, &info);
01164             
01165             if (info.filetype == 'CARD') {
01166                 
01167                 short fnum;
01168                 
01169                 if (fileopen (pfs, &fnum)) {
01170                     
01171                     Handle h;
01172                     
01173                     if (filereadwholefile (fnum, &h)) 
01174                         appruncard (h);
01175                     
01176                     fileclose (fnum);
01177                     }
01178                 
01179                 return (true); /*we handled the file-open*/
01180                 }
01181             }
01182     #endif
01183     
01184     /*DebugStr ((*pfs).name);*/
01185     
01186     if (!openappwindow (pfs)) {
01187         
01188         IACreturnerror (-1, bsalertstring);
01189         
01190         return (false);
01191         }
01192         
01193     return (true);
01194     } /*openfilespec*/
01195     
01196 
01197 static pascal OSErr handleopen (AppleEvent *event, AppleEvent *reply, long refcon) {
01198     
01199     IACglobals.event = event;
01200     
01201     IACglobals.reply = reply;
01202     
01203     IACglobals.refcon = refcon;
01204     
01205     return (IACdrivefilelist (&openfilespec));
01206     } /*handleopen*/
01207     
01208         
01209 static pascal Boolean printfilespec (ptrfilespec pfs) {
01210 
01211     hdlappwindow appwindow;
01212     
01213     if (findbyfile (pfs, &appwindow)) 
01214         selectappwindow (appwindow);
01215 
01216     else {  
01217         if (!openappwindow (pfs)) {
01218             
01219             IACreturnerror (-1, bsalertstring);
01220             
01221             return (false);
01222             }
01223         }
01224 
01225     setfrontglobals (); /*event applies to frontmost window*/
01226     
01227     return (printappwindow (app.appwindow, false));
01228     } /*printfilespec*/
01229     
01230 
01231 static pascal OSErr handleprint (AppleEvent *event, AppleEvent *reply, long refcon) {
01232     
01233     IACglobals.event = event;
01234     
01235     IACglobals.reply = reply;
01236     
01237     IACglobals.refcon = refcon;
01238     
01239     return (IACdrivefilelist (&printfilespec));
01240     } /*handleprint*/
01241     
01242         
01243 static pascal OSErr handlequit (AppleEvent *event, AppleEvent *reply, long refcon) {
01244     
01245     exitmainloop ();
01246     
01247     return (noErr);
01248     } /*handlequit*/
01249     
01250     
01251 static pascal OSErr handleopenapp (AppleEvent *event, AppleEvent *reply, long refcon) {
01252     
01253     (*app.openappcallback) (); /*the application handled the opendoc event*/
01254     
01255     return (noErr);
01256     } /*handleopenapp*/
01257     
01258     
01259 pascal Boolean appscriptcomplete (void) {
01260     
01261     bigstring bs;
01262     
01263     resetdirtyscrollbars ();
01264      
01265     if (IACgetstringparam ('errs', bs)) {
01266         
01267         bigstring bsalert;
01268         
01269         copystring ("\pError in shared script. ", bsalert);
01270         
01271         pushstring (bs, bsalert);
01272         
01273         alertdialog (bsalert);
01274         }
01275     
01276     return (true);
01277     } /*appscriptcomplete*/
01278     
01279     
01280 static long casereverser (long id) {
01281     
01282     /*
01283     used in setting up the system event handler for the "fast" verbs that the applet
01284     implements. we reverse the case of each of the alpha characters in the id. for
01285     example, 'DOCS' turns into 'docs'. And 'MnU' turns into 'mNu'. originally we
01286     had each applet declare its system handler in the class 'fast', but this wouldn't
01287     work if more than one applet was running at a time.
01288     */
01289 
01290     char *p = (char *) &id;
01291     short i;
01292     
01293     for (i = 1; i <= 4; i++) {
01294     
01295         char ch = *p;
01296         
01297         if ((ch >= 'a') && (ch <= 'z'))
01298             ch -= 32;
01299         else
01300             if ((ch >= 'A') && (ch <= 'Z'))
01301                 ch += 32;
01302         
01303         *p++ = ch;
01304         } /*for*/
01305         
01306     return (id);
01307     } /*casereverser*/
01308     
01309 
01310 pascal short appwaitroutine (EventRecord *ev) {
01311     
01312     /*
01313     we're called by the IAC Toolkit while it's waiting for a reply to an 
01314     Apple Event. since we may be called while getting new shared menus, we 
01315     must not call handleevent for null events here to avoid re-entrancy.
01316     
01317     DW 12/22/92: we used to call appidle on receipt of a null event. this
01318     would wreak havoc in IOWA, so instead we just handle non-null events
01319     while waiting for a reply to the Apple Event.
01320     */
01321     
01322     if ((*ev).what != nullEvent)
01323         appleteventdispatcher (ev);
01324         
01325     return (0);
01326     } /*appwaitroutine*/
01327 
01328 
01329 boolean initappletwires (void) {
01330     
01331     setstringlength (bstargetwindowname, 0); /*no target window initially*/
01332     
01333     if (!IACinstallhandler (kCoreEventClass, kAEOpenApplication, (ProcPtr) &handleopenapp))
01334         goto error;
01335     
01336     if (!IACinstallhandler (kCoreEventClass, kAEOpenDocuments, (ProcPtr) &handleopen))
01337         goto error;
01338     
01339     if (!IACinstallhandler (kCoreEventClass, kAEPrintDocuments, (ProcPtr) &handleprint))
01340         goto error;
01341     
01342     if (!IACinstallhandler (kCoreEventClass, kAEQuitApplication, (ProcPtr) &handlequit))
01343         goto error;
01344 
01345     if (!IACinstallhandler (app1class, typeWildCard, (ProcPtr) &handleapp1verb))
01346         goto error;
01347     
01348     if (!IACinstallhandler (app.creator, typeWildCard, (ProcPtr) &handlecustomverb))
01349         goto error;
01350     
01351     if (!IACinstallsystemhandler (casereverser (app.creator), typeWildCard, (ProcPtr) &handlefastverb))
01352         goto error;
01353 
01354     IACglobals.waitroutine = appwaitroutine;
01355     
01356     return (true);
01357     
01358     error:
01359     
01360     alertdialog ("\pCouldn't install all the Apple Event handlers.");
01361     
01362     return (false);
01363     } /*initappletwires*/
01364     
01365     

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