iowaruntime.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iowaruntime.c 1353 2006-05-05 13:52:21Z sethdill $    */
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 "byteorder.h"
00032 
00033 #include "shelltypes.h"
00034 #include <appletdefs.h>
00035 #include <iac.h>
00036 #include <SetUpA5.h>
00037 #include <appletquickdraw.h>
00038 #include <appletmouse.h>
00039 #include <appletfrontier.h>
00040 #include <appletcursor.h>
00041 #include <appletops.h>
00042 #include <appletfiles.h>
00043 #include <appletcardops.h>
00044 #include <appletzoom.h>
00045 #include <appletcard.h>
00046 #include <appletkb.h>
00047 
00048 #include "iowaparser.h"
00049 #include "iowafrontier.h"
00050 #include "iowaattributes.h"
00051 #include "iowascript.h"
00052 
00053 #include "quickdraw.h"
00054 
00055 
00056 #ifndef cutCmd
00057 #define cutCmd      3
00058 #define copyCmd     4
00059 #define pasteCmd    5
00060 #define clearCmd    6
00061 #define selectAllCmd    8
00062 #endif
00063 
00064 
00065 #ifndef iowaRuntime /*in Card Editor, cmd-period kills a running card*/ 
00066 
00067     #define cmdPeriodKillsCard
00068     
00069 #endif
00070 
00071 hdlruntimerecord runtimedata = nil;
00072 
00073 boolean flexitcardloop = false;
00074 
00075 typedef struct cardwindow {
00076 
00077     WindowPtr w;
00078     
00079     hdlruntimerecord hw;
00080     
00081     } tycardwindow;
00082 
00083 static tycardwindow **hwindowarray = nil; /*dynamic array of WindowPtrs managed by iowa*/
00084     
00085 #define textticksrecalc 30 /*while typing text, wait this number of ticks before recalcing*/
00086 
00087 boolean flquickrecalc = true; /*set false in cardrunner.c, under special circumstances*/
00088 
00089 
00090 static short sizewindowarray (void) {
00091     
00092     if (hwindowarray == nil)
00093         return (0);
00094         
00095     return ((short) (GetHandleSize ((Handle) hwindowarray) / longsizeof (tycardwindow)));
00096     } /*sizewindowarray*/
00097     
00098     
00099 static hdlruntimerecord getwindowdata (WindowPtr w) {
00100     
00101     /*return ((hdlruntimerecord) GetWRefCon (w));*/
00102     
00103     if (w != nil)
00104     {
00105         short ct, i;
00106         
00107         ct = sizewindowarray ();
00108         
00109         for (i = 0; i < ct; i++) { /*look for the window in the window array*/
00110             
00111             if ((*hwindowarray) [i].w == w)
00112                 return ((*hwindowarray) [i].hw);
00113             }
00114     }
00115     
00116     return (nil); /*it's not in the window array*/
00117     } /*getwindowdata*/
00118     
00119     
00120 static hdlcard getwindowcardrecord (WindowPtr w) {
00121         
00122     return ((**getwindowdata (w)).hc);
00123     } /*getwindowcardrecord*/
00124     
00125 
00126 static hdlcard cardtofind;
00127 
00128 static WindowPtr windowtofind = nil;
00129 
00130 
00131 static boolean getcardrecordwindowvisit (WindowPtr w) {
00132     
00133     hdlcard hc = getwindowcardrecord (w);
00134 
00135     if (hc == cardtofind)   
00136         windowtofind = w;
00137         
00138     return (true);
00139     } /*getcardrecordwindowvisit*/
00140     
00141     
00142 WindowPtr getcardrecordwindow (hdlcard card) {
00143     
00144     /*
00145     4.1b4 dmb: I added this routine a couple of builds back for modalcardeventfilter
00146     in langcard.c. I now see that we must preserve our globals, which visitCardWindows
00147     automatically sets.
00148     */
00149     
00150     hdlruntimerecord saveruntimedata = runtimedata;
00151     hdlcard saveiowadata = iowadata;
00152     
00153     cardtofind = card;
00154     
00155     visitCardWindows (&getcardrecordwindowvisit);
00156     
00157     runtimedata = saveruntimedata;
00158     
00159     iowadata = saveiowadata;
00160     
00161     return (windowtofind);
00162     } /*getcardrecordwindow*/
00163 
00164     
00165 short countCardWindows (void) {
00166     
00167     short ctcells = sizewindowarray ();
00168     short ct = 0;
00169     short i;
00170     
00171     for (i = 0; i < ctcells; i++)
00172         if ((*hwindowarray) [i].w != nil)
00173             ct++;
00174             
00175     return (ct);
00176     } /*countCardWindows*/
00177 
00178 
00179 //#pragma global_optimizer off  //fixes CWPro2 compiler bug, hw would always be zero
00180 
00181 static boolean addtowindowarray (WindowPtr w, hdlruntimerecord hw) {
00182     
00183     short ct, i;
00184     tycardwindow cw;
00185     
00186     assert (hw != nil);
00187     
00188     cw.w = w;
00189     
00190     cw.hw = hw;
00191     
00192     ct = sizewindowarray ();
00193     
00194     for (i = 0; i < ct; i++) { /*look for an empty slot in the window array*/
00195         
00196         if ((*hwindowarray) [i].w == nil) {
00197             
00198             (*hwindowarray) [i] = cw;
00199             
00200             return (true);
00201             }
00202         } /*for*/
00203     
00204     /*no empty slots, allocate a new array or make the array bigger*/
00205     
00206     if (hwindowarray == nil)
00207         return (newfilledhandle (&cw, longsizeof (tycardwindow), (Handle *) &hwindowarray));
00208     
00209     SetHandleSize ((Handle) hwindowarray, (ct + 1) * longsizeof (tycardwindow));
00210 
00211     if (MemError () != noErr)
00212         return (false);
00213     
00214     (*hwindowarray) [ct] = cw;
00215     
00216     return (true);
00217     } /*addtowindowarray*/
00218 
00219 //#pragma global_optimizer reset
00220 
00221     
00222 static boolean inwindowarray (WindowPtr w) {
00223 
00224     return (getwindowdata (w) != nil);
00225     } /*inwindowarray*/
00226     
00227     
00228 static void removefromwindowarray (WindowPtr w) {
00229 
00230     short ct, i;
00231     
00232     ct = sizewindowarray ();
00233     
00234     for (i = 0; i < ct; i++) { /*look for an empty slot in the window array*/
00235         
00236         if ((*hwindowarray) [i].w == w) {
00237         
00238             (*hwindowarray) [i].w = nil;
00239             
00240             return;
00241             }
00242         } /*for*/
00243     } /*removefromwindowarray*/
00244     
00245     
00246 boolean isCardWindow (WindowPtr w) {
00247     
00248     return (inwindowarray (w));
00249     } /*isCardWindow*/
00250 
00251 
00252 boolean cardToFront (bigstring windowtitle) {
00253 
00254     short ct, i;
00255     
00256     ct = sizewindowarray ();
00257     
00258     for (i = 0; i < ct; i++) { 
00259         
00260         WindowPtr w = (*hwindowarray) [i].w;
00261         
00262         if (w != nil) {
00263             
00264             bigstring bs;
00265             
00266             GetWTitle (w, bs);
00267             
00268             if (equalstrings (bs, windowtitle)) {
00269                 
00270                 SelectWindow (w);
00271                 
00272                 return (true);
00273                 }
00274             }
00275         } /*for*/
00276     
00277     return (false); /*we don't have a window with that name*/
00278     } /*cardToFront*/
00279 
00280 
00281 static void runmodeactivate (boolean flactivating) {
00282     
00283     /*
00284     8/9/96 4.1b4 dmb: broke out of handleCardEvent's main switch statement
00285     
00286     1.0b19 dmb: call frontSetRuntimeCard when we switch out too.
00287     */
00288     
00289     frontSetRuntimeCard (flactivating, true);
00290     
00291     /*DW 4/6/95: hack -- activate/deactivate the active text object directly*/ {
00292         
00293         hdlobject hobj = (**iowadata).activetextobject;
00294         
00295         if (hobj != nil) {
00296         
00297             hdleditrecord heditrecord = (hdleditrecord) (**hobj).objecteditrecord;
00298         
00299             editactivate (heditrecord, flactivating);
00300             }
00301         }
00302     } /*runmodeactivate*/
00303 
00304 
00305 static void runmodeupdate (void) {
00306     
00307     hdlruntimerecord hw = runtimedata;
00308     WindowPtr w;
00309     hdlcard hc;
00310     boolean beginendupdate;
00311     
00312     if (hw == nil) // 7.3.97 dmb: can happen when multiple cards are started quickly
00313         return;
00314     
00315     w = (**hw).macwindow;
00316     hc = (**hw).hc;
00317     beginendupdate = (**hw).ownwindow;  /* || (**hc).macevent.what != updateEvt;*/
00318     
00319     assert ((**hc).drawwindow == w);
00320     //Code change by Timothy Paustian Monday, August 21, 2000 9:34:50 PM
00321     //have to use the port can't cast a window in OS X
00322     {
00323     CGrafPtr    thePort;
00324     #if TARGET_API_MAC_CARBON == 1
00325     thePort = GetWindowPort(w);
00326     #else
00327     thePort = (CGrafPtr)w;  
00328     #endif
00329     pushmacport (thePort);
00330     }
00331     if ((**hc).fullupdate) {
00332         //Code change by Timothy Paustian Friday, May 5, 2000 10:49:31 PM
00333         //Changed to Opaque call for Carbon
00334         //This may actually be useless in Carbon
00335         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00336         CGrafPtr    thePort;
00337         Rect        windBounds;
00338         thePort = GetWindowPort(w);
00339         GetPortBounds(thePort, &windBounds);
00340         InvalWindowRect (w, &windBounds);
00341         #else
00342         InvalRect (&(*w).portRect);
00343         #endif
00344         
00345         (**hc).fullupdate = false;
00346         }
00347     
00348     if (beginendupdate) 
00349         BeginUpdate (w);
00350     //Code change by Timothy Paustian Friday, May 5, 2000 10:51:00 PM
00351     //Changed to Opaque call for Carbon
00352     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00353     {
00354         CGrafPtr    thePort;
00355         RgnHandle   visRgn = NewRgn();
00356         thePort = GetWindowPort(w);
00357         visRgn = GetPortVisibleRegion(thePort, visRgn);
00358         GetRegionBounds(visRgn, &(**hc).updaterect);
00359         DisposeRgn(visRgn);
00360     }
00361     #else
00362     (**hc).updaterect = (**(*w).visRgn).rgnBBox;
00363     #endif
00364     /*preserve iowadata across an update*/ {
00365     
00366         hdlcard oldiowadata = iowadata;
00367     
00368         iowadata = hc;
00369     
00370         iowaupdate ();
00371         //Code change by Timothy Paustian Friday, September 15, 2000 9:01:04 PM
00372         //Mac OS X uses double buffered windows. If you are not calling WaitNextEvent
00373         //you have to tell the OS to flush the contents of the offscreen buffer
00374         //to the screen. Use QDFlushPortBuffer to do this.
00375         #if TARGET_API_MAC_CARBON == 1
00376         {
00377         CGrafPtr    thePort;
00378         thePort = GetWindowPort(w);
00379         QDFlushPortBuffer(thePort, nil);
00380         }
00381         #endif
00382         iowadata = oldiowadata;
00383         }
00384             
00385     if (beginendupdate)
00386         EndUpdate (w);
00387     
00388     popmacport ();
00389     } /*runmodeupdate*/
00390     
00391     
00392 static boolean runtimeeditableobject (hdlobject h) {
00393     
00394     derefclone (&h);
00395     
00396     if (!(**h).objectenabled)
00397         return (false);
00398         
00399     return (calleditableinrunmode (h));
00400     } /*runtimeeditableobject*/
00401     
00402     
00403 static boolean getfirsttextobject (hdlobject *hfirst) {
00404     
00405     /*
00406     return the first editable text object
00407     */
00408     
00409     hdlcard hc = iowadata;
00410     hdlobject nomad = (**hc).objectlist;
00411     short lowesttag = infinity;
00412     
00413     *hfirst = nil;
00414     
00415     while (nomad != nil) {
00416         
00417         if (runtimeeditableobject (nomad)) {
00418             
00419             if ((**nomad).sorttag < lowesttag) {
00420                 
00421                 lowesttag = (**nomad).sorttag;
00422                 
00423                 *hfirst = nomad;
00424                 }
00425             }
00426 
00427         nomad = (**nomad).nextinthread;
00428         } /*while*/
00429     
00430     return (*hfirst != nil);
00431     } /*getfirsttextobject*/
00432     
00433 
00434 static void getnexttextobject (hdlobject h, hdlobject *hnext) {
00435     
00436     hdlcard hc = iowadata;
00437     hdlobject nomad = (**hc).objectlist;
00438     short n = (**h).sorttag + 1;
00439     short nearesttag = infinity;
00440     hdlobject nearestnomad = nil;
00441     short lowesttag = infinity;
00442     hdlobject lowestnomad = nil;
00443 
00444     while (nomad != nil) {
00445         
00446         if (runtimeeditableobject (nomad)) {
00447             
00448             short nomadtag = (**nomad).sorttag;
00449             
00450             if (nomadtag == n) { /*found it the easy way*/
00451                 
00452                 *hnext = nomad;
00453                 
00454                 return;
00455                 }
00456             
00457             if (nomadtag < lowesttag) { /*in case we wrap around*/
00458                 
00459                 lowesttag = nomadtag;
00460                 
00461                 lowestnomad = nomad;
00462                 }
00463                 
00464             if ((nomadtag > n) && (nomadtag < nearesttag)) {
00465                 
00466                 nearestnomad = nomad;
00467                 
00468                 nearesttag = nomadtag;
00469                 }
00470             }
00471 
00472         nomad = (**nomad).nextinthread;
00473         } /*while*/
00474     
00475     if (nearestnomad == nil) /*wrap around to the first guy*/
00476         *hnext = lowestnomad;
00477     else
00478         *hnext = nearestnomad;
00479     } /*getnexttextobject*/
00480     
00481 
00482 static void getprevtextobject (hdlobject h, hdlobject *hnext) {
00483     
00484     hdlcard hc = iowadata;
00485     hdlobject nomad = (**hc).objectlist;
00486     short n = (**h).sorttag - 1;
00487     short nearesttag = 0;
00488     hdlobject nearestnomad = nil;
00489     short highesttag = 0;
00490     hdlobject highestnomad = nil;
00491 
00492     while (nomad != nil) {
00493         
00494         if (runtimeeditableobject (nomad)) {
00495             
00496             short nomadtag = (**nomad).sorttag;
00497             
00498             if (nomadtag == n) { /*found it the easy way*/
00499                 
00500                 *hnext = nomad;
00501                 
00502                 return;
00503                 }
00504             
00505             if (nomadtag > highesttag) { /*in case we wrap around*/
00506                 
00507                 highesttag = nomadtag;
00508                 
00509                 highestnomad = nomad;
00510                 }
00511                 
00512             if ((nomadtag < n) && (nomadtag > nearesttag)) {
00513                 
00514                 nearestnomad = nomad;
00515                 
00516                 nearesttag = nomadtag;
00517                 }
00518             }
00519 
00520         nomad = (**nomad).nextinthread;
00521         } /*while*/
00522     
00523     if (nearestnomad == nil) /*wrap around to the first guy*/
00524         *hnext = highestnomad;
00525     else
00526         *hnext = nearestnomad;
00527     } /*getprevtextobject*/
00528     
00529     
00530 static boolean movetextboxcursor (boolean flbackward) {
00531 
00532     hdlcard hc = iowadata;
00533     hdlobject h;
00534     
00535     h = (**hc).activetextobject;
00536     
00537     if (h == nil) /*no text objects*/
00538         return (false);
00539     
00540     if (flbackward)
00541         getprevtextobject (h, &h);
00542     else
00543         getnexttextobject (h, &h);
00544         
00545     if (h == (**hc).activetextobject) /*only one text object*/
00546         return (false);
00547     
00548     derefclone (&h);
00549     
00550     calleditobject (h, true);
00551             
00552     validobject (h); /*1.0b15 DW -- part of the flicker avoidance scheme*/
00553     
00554     return (true);
00555     } /*movetextboxcursor*/
00556     
00557     
00558 static void hotobject (boolean flpressed) {
00559     
00560     /*
00561     callback routine for the mouse tracker.
00562     */
00563     
00564     hdlcard hc = iowadata;
00565     
00566     (**hc).trackerpressed = flpressed;
00567     
00568     invalobject ((**hc).trackerobject);
00569     
00570     iowaupdatenow ();
00571     } /*hotobject*/
00572     
00573 
00574 boolean recalcCardWindow (WindowPtr w, boolean flmajorrecalc) {
00575     
00576     if (w == nil) 
00577         return (false);
00578         
00579     //Code change by Timothy Paustian Monday, August 21, 2000 9:34:50 PM
00580     //have to use the port can't cast a window in OS X
00581     {
00582     CGrafPtr    thePort;
00583     #if TARGET_API_MAC_CARBON == 1
00584     thePort = GetWindowPort(w);
00585     #else
00586     thePort = (CGrafPtr)w;  
00587     #endif
00588     pushmacport (thePort);
00589     }
00590         
00591     runtimedata = getwindowdata (w); /*set up global for runmode routines*/
00592     
00593     iowadata = getwindowcardrecord (w); /*set up global for card routines*/
00594     
00595     frontSetRuntimeCard (true, false); /*a minor switch, just make embedded objects global*/
00596     
00597     (**iowadata).recalcobject = nil;
00598     
00599     if (flmajorrecalc)
00600         visitobjects ((**iowadata).objectlist, &majorrecalcvisit);
00601     else
00602         visitobjects ((**iowadata).objectlist, &minorrecalcvisit);
00603     
00604     runmodeupdate ();
00605         
00606     popmacport ();
00607     
00608     return (true); /*keep visiting*/
00609     } /*recalcCardWindow*/
00610     
00611     
00612 static boolean sameasbuttontype (tyobjecttype type) { 
00613     
00614     return (type == buttontype);
00615     } /*sameasbuttontype*/
00616     
00617     
00618 static void filterevent (EventRecord *ev) {
00619     // 2006-04-03 - kw --- renamed callback -> lCallback
00620     tycardeventcallback lCallback = (**runtimedata).callback;
00621     
00622     if (lCallback == nil) 
00623         return;
00624         
00625     if ((*ev).what == nullEvent) /*DW 8/22/93*/
00626         (*ev).message = (long) iowadata;
00627     
00628     else { /*DW /8/26/93: no klooging to set the global over in the filter, send 2 events*/ 
00629     
00630         EventRecord x;
00631         
00632         clearbytes (&x, longsizeof (x));
00633         
00634         x.what = iowaSetHandleEvent;
00635         
00636         x.message = (long) iowadata;
00637         
00638         (*lCallback) (&x);
00639         }
00640     
00641     //Code change by Timothy Paustian Monday, August 21, 2000 9:34:50 PM
00642     //have to use the port can't cast a window in OS X
00643     {
00644     CGrafPtr    thePort;
00645     #if TARGET_API_MAC_CARBON == 1
00646     thePort = GetWindowPort((**iowadata).drawwindow);
00647     #else
00648     thePort = (CGrafPtr)(**iowadata).drawwindow;    
00649     #endif
00650     pushmacport (thePort);
00651     }
00652     
00653     (*lCallback) (ev);
00654     
00655     popmacport ();
00656     } /*filterevent*/
00657     
00658     
00659 static void sendinitmessage (void) {
00660 
00661     tycardeventcallback lcallback = (**runtimedata).callback;
00662     EventRecord ev;
00663     
00664     if (lcallback == nil) 
00665         return;
00666         
00667     ev.what = iowaInitEvent;
00668     
00669     ev.message = (long) iowadata;
00670     
00671     (*lcallback) (&ev);
00672     } /*sendinitmessage*/
00673     
00674     
00675 static boolean sendbuttonhitmessage (hdlobject h) {
00676     
00677     /*
00678     return true if the buttonhit has been fully processed
00679     */
00680 
00681     // 2006-04-03 - kw --- renamed callback -> lCallback
00682     tycardeventcallback lCallback = (**runtimedata).callback;
00683     EventRecord ev;
00684 
00685     if (lCallback == nil)
00686         return (true);
00687 
00688     ev.what = iowaButtonHitEvent;
00689 
00690     ev.message = (long) h;
00691 
00692     (*lCallback) (&ev);
00693 
00694     if (ev.what == iowaRunScriptEvent) /*pass the buttonhit thru, run the script*/
00695         return (false);
00696 
00697     if (ev.what == iowaCloseEvent) /*the client is telling us to close the window*/
00698         closeCardWindow ((**runtimedata).macwindow);
00699         
00700     return (true); /*we consumed the buttonhit*/
00701     } /*sendbuttonhitmessage*/
00702     
00703     
00704 static boolean sendclosemessage (void) {
00705     
00706     /*
00707     the user just clicked in the close box of a card window, or for some
00708     other reason the card is about to close. we call back to the client,
00709     giving him a chance to save data from the card.
00710     */
00711 
00712     // 2006-04-03 - kw --- renamed callback -> lCallback
00713     tycardeventcallback lCallback = (**runtimedata).callback;
00714     EventRecord ev;
00715 
00716     if (lCallback == nil)
00717         return (true);
00718 
00719     ev.what = iowaCloseEvent;
00720 
00721     ev.message = (long) iowadata;
00722 
00723     (*lCallback) (&ev);
00724 
00725     return (ev.what != iowaCancelEvent);
00726     } /*sendclosemessage*/
00727 
00728     
00729 static void objectclick (hdlobject listhead, hdlobject h) {
00730     
00731     /*
00732     the user just clicked on this object in run mode. 
00733     */
00734     
00735     derefclone (&h); /*click on a clone is the same as clicking on the object*/
00736     
00737     if (sameasbuttontype ((**h).objecttype)) {
00738         
00739         if (sendbuttonhitmessage (h)) {
00740         
00741             if (iowadata != nil) /*protect against a closed window*/
00742                 schedulerecalc (h, 0);
00743             
00744             return;
00745             }
00746         }
00747         
00748     if (callclick (listhead, h, mousestatus.localpt, keyboardstatus.flshiftkey, mousestatus.fldoubleclick)) {
00749     
00750         if (iowadata == nil) /*protect against closed window*/
00751             return;
00752         
00753         if (!flquickrecalc) { /*1/25/93 DW: very rarely you need to disable the quick recalc*/
00754             
00755             flquickrecalc = true; /*must be reset for every call*/
00756             
00757             return;
00758             }
00759         
00760         /*1/24/93 DW: streamlined for quick response to click and in recalc*/
00761             
00762         runmodeupdate (); /*avoid lag in display during massive recalcs*/
00763     
00764         frontSetRuntimeCard (true, false); /*make this card's table global*/
00765         
00766         (**iowadata).recalcobject = h;
00767         
00768         visitobjects ((**iowadata).objectlist, &minorrecalcvisit); /*recalc now, avoid lag*/
00769     
00770         runmodeupdate (); /*avoid lag in display, agents might need to run now*/
00771         
00772         (**iowadata).runmodechanges = true;
00773         }
00774     } /*objectclick*/
00775     
00776     
00777 static boolean returnkeyvisit (hdlobject h) {
00778 
00779     hdlcard hc = iowadata;
00780     
00781     if (!(**h).objectenabled) /*keep searching*/
00782         return (true);
00783         
00784     if (!callcatchreturn (h)) /*object doesn't want the Return key*/
00785         return (true);
00786         
00787     (**hc).tracking = true; /*this is what bold buttons do, for example*/
00788 
00789     (**hc).trackerobject = h;
00790 
00791     hotobject (true); /*display button in its hot state*/
00792     
00793     waitfornexttick (); waitfornexttick (); waitfornexttick ();
00794     
00795     while (returnkeydown ()) {};
00796     
00797     hotobject (false); /*display button in its un-hot state*/
00798 
00799     (**hc).tracking = false;
00800     
00801     objectclick ((**iowadata).objectlist, h);
00802     
00803     return (false); /*stop searching*/
00804     } /*returnkeyvisit*/
00805     
00806 
00807 static char upperchar (char ch) {
00808 
00809     if ((ch >= 'a') && (ch <= 'z'))
00810         return (ch - 32);
00811     else
00812         return (ch);
00813     } /*upperchar*/
00814 
00815 
00816 static boolean mapkeyvisit (hdlobject h) {
00817     
00818     /*
00819     dmb 1.0b20: map chescape to the cancel button
00820     */
00821     
00822     hdlcard hc = iowadata;
00823     bigstring bs;
00824     
00825     if (!(**h).objectenabled) /*keep searching*/
00826         return (true);
00827         
00828     if ((**h).objecttype != buttontype) /*keep searching*/
00829         return (true);
00830         
00831     texthandletostring ((**h).objectvalue, bs);
00832     
00833     if (stringlength (bs) == 0)
00834         return (true);
00835     
00836     if (keyboardstatus.chkb == chescape) {
00837         
00838         if (!equalstrings (bs, "\pCancel"))
00839             return (true);
00840         }
00841     else {
00842     
00843         if (upperchar (bs [1]) != upperchar (keyboardstatus.chkb))
00844             return (true);
00845         }
00846     
00847     (**hc).tracking = true; 
00848 
00849     (**hc).trackerobject = h;
00850 
00851     hotobject (true); /*display button in its hot state*/
00852     
00853     waitfornexttick (); waitfornexttick (); waitfornexttick ();
00854     
00855     hotobject (false); /*display button in its un-hot state*/
00856 
00857     (**hc).tracking = false;
00858     
00859     objectclick ((**iowadata).objectlist, h);
00860     
00861     return (false); /*stop searching*/
00862     } /*mapkeyvisit*/
00863 
00864 
00865 static boolean runmodekeystroke (void) {
00866     
00867     /*
00868     return true if the keystroke was consumed by runtime, otherwise it is 
00869     passed back to the eventhandler.
00870     
00871     dmb 1.0b20: map cmd-. and escape to the cancel button, if present
00872     and enabled. otherwise, close card as before.
00873     
00874     dmb 1.0b20: allow option-Return to type into text field
00875     
00876     dmb 1.0b21: on chescape, don't set flexitcardloop true if closeCardWindow
00877     returns false
00878     */
00879     
00880     hdlcard hc = iowadata;
00881     char ch = keyboardstatus.chkb;
00882     hdlobject activetextobject = (**hc).activetextobject;
00883     
00884     if (keyboardstatus.flcmdkey) {
00885         
00886         #ifdef cmdPeriodKillsCard /*disabled for LSE on 1/27/95 by DW*/
00887     
00888             /*
00889             if (ch == '.') {
00890                 
00891                 flexitcardloop = true;
00892                 
00893                 closeCardWindow ((**runtimedata).macwindow);
00894                 
00895                 return (true);
00896                 }
00897             */
00898             if (ch == '.')
00899                 keyboardstatus.chkb = ch = chescape;
00900             else
00901 
00902         #endif
00903             
00904         return (false); /*we pass on all other cmd-keystrokes*/
00905         }
00906         
00907     if (ch == chescape) { /*escape always kills the card*/
00908     
00909         visitobjects ((**hc).objectlist, &mapkeyvisit); /*dmb 1.0b20*/
00910         
00911         if (!flexitcardloop) { /*didn't map to enabled Cancel button. close anyway*/
00912             
00913             closeCardWindow ((**runtimedata).macwindow);
00914             }
00915         
00916         return (true);
00917         }
00918         
00919     if (ch == chtab) {
00920         
00921         movetextboxcursor (keyboardstatus.flshiftkey);
00922         
00923         return (true);
00924         }
00925         
00926     if ((ch == chreturn) || (ch == chenter)) {
00927     
00928         if (!keyboardstatus.floptionkey || activetextobject == nil) /*dmb 1.0b20*/
00929             if (!visitobjects ((**hc).objectlist, &returnkeyvisit))
00930                 return (true);
00931         }
00932         
00933     if (activetextobject == nil) { /*3/18/93 DW -- map keystroke to button*/
00934 
00935         visitobjects ((**hc).objectlist, &mapkeyvisit);
00936         
00937         return (true);
00938         }
00939         
00940     callkeyobject (activetextobject, ch);
00941     
00942     schedulerecalc (activetextobject, textticksrecalc);
00943         
00944     return (true);
00945     } /*runmodekeystroke*/
00946 
00947 
00948 static void runmodetracker (hdlobject listhead, hdlobject x) {
00949 
00950     hdlcard hc = iowadata;
00951     Rect r;
00952     boolean flclick;
00953     hdlobject htarget;
00954     
00955     htarget = x;
00956     
00957     if (!(**htarget).objectenabled)
00958         return;
00959     
00960     derefclone (&htarget);
00961     
00962     if (!(**htarget).objectenabled)
00963         return;
00964     
00965     if (callhandlesmousetrack (htarget)) { /*object handles its own mouse tracking*/
00966     
00967         objectclick (listhead, x);
00968             
00969         return;
00970         }
00971         
00972     getobjectrect (x, &r);
00973     
00974     (**hc).tracking = true;
00975     
00976     (**hc).trackerobject = x;
00977     
00978     hotobject (true); /*display object in its hot state*/
00979     
00980     flclick = false;
00981     
00982     if (mousetrack (r, &hotobject)) {
00983     
00984         hotobject (false); /*display object in its un-hot state*/
00985         
00986         flclick = true;
00987         }
00988     
00989     (**hc).tracking = false;
00990     
00991     if (flclick)
00992         objectclick (listhead, x);
00993     } /*runmodetracker*/
00994     
00995     
00996 static boolean findrunmodeobject (Point pt, hdlobject listhead, hdlobject *hparent, hdlobject *hobject) {
00997     
00998     /*
00999     special object-finder for runmode. it passes right thru clones.
01000     */
01001     
01002     hdlobject x;
01003     
01004     while (true) { 
01005         
01006         if (!findobject (pt, listhead, &x))
01007             return (false);
01008             
01009         switch ((**x).objecttype) {
01010             
01011             case grouptype:
01012                 getchildobjectlist (x, &listhead);
01013                 
01014                 break;
01015                 
01016             case clonetype:
01017                 listhead = x;
01018                 
01019                 derefclone (&listhead);
01020                 
01021                 break;
01022                 
01023             default:
01024                 *hparent = listhead;
01025             
01026                 *hobject = x;
01027             
01028                 return (true);
01029             } /*switch*/
01030         } /*while*/
01031     } /*findrunmodeobject*/
01032     
01033 
01034 static void runmodecontentclick (WindowPtr w, Point pt) {
01035             
01036     hdlobject listhead, x;
01037         
01038     if (w != FrontWindow ()) {
01039     
01040         if ((**runtimedata).ownwindow)
01041             SelectWindow (w);
01042         
01043         return;
01044         }
01045     //Code change by Timothy Paustian Wednesday, August 23, 2000 9:20:43 PM
01046     //
01047     {   
01048     #if TARGET_API_MAC_CARBON
01049     CGrafPtr    thePort = GetWindowPort(w);
01050     #else
01051     GrafPtr thePort = (GrafPtr)w;
01052     #endif
01053 
01054     SetPort (thePort);
01055     }
01056     mousestatus.localpt = pt;
01057     
01058     globaltolocalpoint (w, &mousestatus.localpt);
01059 
01060     listhead = (**iowadata).objectlist;
01061     
01062     if (findrunmodeobject (mousestatus.localpt, listhead, &listhead, &x)) 
01063         runmodetracker (listhead, x);
01064     } /*runmodecontentclick*/
01065     
01066 
01067 static void runmodemouseup (long when, Point where) {
01068     
01069     /*
01070     call this when you receive an mouse up event.  if the last mouse down was
01071     a double click, we set things up so that the next single click will not
01072     be interpreted as a double click.
01073     */
01074     
01075     if (!mousestatus.fldoubleclickdisabled) {
01076         
01077         mousestatus.mouseuptime = when;
01078         
01079         mousestatus.mouseuppoint = where;
01080         
01081         mousestatus.mousedowntime = 0L; /*hasn't happened yet*/
01082         }
01083     
01084     mousestatus.fldoubleclickdisabled = false; /*next mouse up is important*/
01085     } /*runmodemouseup*/
01086 
01087 
01088 static boolean runmodemousedown (long when, Point pt, boolean *flcloseallwindows) {
01089     
01090     /*
01091     1.0b20 dmb: made boolean, return false if we don't handle it.
01092     */
01093     
01094     WindowPtr w;
01095     short part;
01096     boolean flhandled = true;
01097     
01098     mousestatus.mousedowntime = when; 
01099     
01100     mousestatus.mousedownpoint = pt;
01101     
01102     part = FindWindow (pt, &w);
01103     
01104     switch (part) {
01105         
01106         case inDrag: {
01107             Rect r;
01108             //Code change by Timothy Paustian Monday, June 26, 2000 3:15:37 PM
01109             //
01110             #if TARGET_API_MAC_CARBON == 1
01111             BitMap screenBits;
01112             GetQDGlobalsScreenBits(&screenBits);
01113             r = screenBits.bounds;
01114             #else   
01115             r = quickdrawglobal (screenBits).bounds; 
01116             #endif
01117         
01118             r.top = r.top + GetMBarHeight (); 
01119             
01120             InsetRect (&r, 4, 4);
01121             
01122             DragWindow (w, pt, &r);
01123             
01124             break;
01125             }
01126             
01127         case inContent:
01128             runmodecontentclick (w, pt);
01129             
01130             break;
01131             
01132         case inGoAway:
01133             if (TrackGoAway (w, pt)) {
01134             
01135                 if (keyboardstatus.floptionkey) {
01136                 
01137                     closeAllCardWindows ();
01138                     
01139                     *flcloseallwindows = true;
01140                     }
01141                 else
01142                     closeCardWindow (w); 
01143                 }
01144                 
01145             break;
01146         
01147         default:
01148             flhandled = false;
01149             
01150             break;
01151         } /*switch*/
01152     
01153     return (flhandled);
01154     } /*runmodemousedown*/
01155 
01156 
01157 static void runmodecheckupdate (void) {
01158 
01159     hdlcard hc = iowadata;
01160     WindowPtr w = (**runtimedata).macwindow;
01161     Rect        portRect;
01162     
01163     if ((**hc).needsupdate && ((**hc).runmode)) {
01164         
01165         (**hc).needsupdate = false; /*consume it*/
01166                 
01167         //Code change by Timothy Paustian Monday, August 21, 2000 9:34:50 PM
01168         //have to use the port can't cast a window in OS X
01169         {
01170         CGrafPtr    thePort;
01171         #if TARGET_API_MAC_CARBON == 1
01172         thePort = GetWindowPort(w);
01173         #else
01174         thePort = (CGrafPtr)w;  
01175         #endif
01176         pushmacport (thePort);
01177         }
01178         
01179         //Code change by Timothy Paustian Friday, May 5, 2000 10:55:27 PM
01180         //Changed to Opaque call for Carbon
01181         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
01182         {
01183         CGrafPtr    thePort = GetWindowPort(w);
01184         GetPortBounds(thePort, &portRect);
01185         }
01186         #else
01187         portRect = w->portRect;
01188         #endif
01189         
01190         pushclip (portRect);
01191         
01192         iowapreupdate (); /*actually inval everything that's been logically inval'd*/
01193     
01194         runmodeupdate ();
01195         
01196         popclip ();
01197         
01198         popmacport ();
01199         }
01200     } /*runmodecheckupdate*/
01201     
01202 
01203 static boolean alwaysidlevisit (hdlobject h) {
01204     
01205     if (callalwaysidle (h))
01206         callidleobject (h);
01207         
01208     return (true);
01209     } /*alwaysidlevisit*/
01210     
01211     
01212 static void runmodeidle (void) {
01213     
01214     hdlcard hc = iowadata;
01215     boolean flcursorset = false;
01216     hdlobject hparent, h;
01217 
01218     GetMouse (&mousestatus.localpt);
01219     
01220     if (findrunmodeobject (mousestatus.localpt, (**hc).objectlist, &hparent, &h)) {
01221         
01222         if ((**h).objectenabled) 
01223             flcursorset = callsetcursor (h, mousestatus.localpt);
01224         }
01225     
01226     if (!flcursorset)
01227         setcursortype (cursorisarrow);
01228 
01229     callidleobject ((**hc).activetextobject);
01230     
01231     visitobjects ((**hc).objectlist, &alwaysidlevisit);
01232 
01233     runmodecheckupdate ();
01234     
01235     checkrecalc ();
01236     } /*runmodeidle*/
01237     
01238     
01239 boolean closeCardWindow (WindowPtr w) {
01240     
01241     Boolean ownwindow;
01242     
01243     if (!isCardWindow (w))
01244         return (false);
01245     
01246     runtimedata = getwindowdata (w); /*set up global for runmode routines*/
01247     
01248     iowadata = getwindowcardrecord (w); /*set up global for card routines*/
01249     
01250     if (!sendclosemessage ()) /*abort the close*/
01251         return (false);
01252     
01253     ownwindow = (**runtimedata).ownwindow;
01254     
01255     #ifdef iowaRuntimeInApp /*12/5/93 DW -- baling wire*/
01256         iowadata = getwindowcardrecord (w); 
01257     #endif
01258     
01259     //Code change by Timothy Paustian Monday, August 21, 2000 9:34:50 PM
01260     //have to use the port can't cast a window in OS X
01261     {
01262     CGrafPtr    thePort;
01263     #if TARGET_API_MAC_CARBON == 1
01264     thePort = GetWindowPort(w);
01265     #else
01266     thePort = (CGrafPtr)w;  
01267     #endif
01268     pushmacport (thePort);
01269     } /*8/27/94 DW -- on quit, if one modeless card is open, the port isn't properly set*/
01270     
01271     clearactivetextobject ();
01272     
01273     popmacport ();
01274     
01275     if (ownwindow)
01276         HideWindow (w); /*12/16/93 -- immediate feedback*/
01277     
01278     iowadisposerecord (); /*disposes iowadata and its contents*/
01279 
01280     iowadata = nil; /*help out EvenBetterBusError*/
01281 
01282     disposehandle ((Handle) runtimedata);
01283     
01284     runtimedata = nil; /*help out EvenBetterBusError*/
01285     
01286     removefromwindowarray (w);
01287     
01288     if (ownwindow)
01289         DisposeWindow (w);
01290     
01291     flexitcardloop = true;
01292     
01293     return (true);
01294     } /*closeCardWindow*/
01295     
01296     
01297 void closeAllCardWindows (void) {
01298 
01299     short ct, i;
01300     
01301     ct = sizewindowarray ();
01302     
01303     for (i = 0; i < ct; i++) 
01304         closeCardWindow ((*hwindowarray) [i].w);
01305     } /*closeAllCardWindows*/
01306     
01307 
01308 static void initeditabletext (void) {
01309     
01310     /*
01311     activate the first edittext object we find.
01312     */
01313     
01314     hdlobject h;
01315     
01316     if (getfirsttextobject (&h)) {
01317     
01318         derefclone (&h);
01319         
01320         calleditobject (h, true);
01321         
01322         validobject (h); 
01323         }
01324     } /*initeditabletext*/
01325     
01326 
01327 static boolean nilvaluesvisit (hdlobject h) {
01328     
01329     /*
01330     if an object is editable, and it recalcs,  we dispose of the initial value, 
01331     which helped the card designer visualize what the running card would look 
01332     like, but has no value for the card user.
01333     
01334     example: if you have a text object initialized to user.name, without
01335     this hack, you'd see the designer's name first, then the user's name.
01336     */
01337     
01338     if (!calleditableinrunmode (h))
01339         return (true);
01340         
01341     if ((**h).objectrecalcstatus == neverrecalc)
01342         return (true);
01343     
01344     disposehandle ((**h).objectvalue);
01345     
01346     (**h).objectvalue = nil;
01347     
01348     return (true);
01349     } /*nilvaluesvisit*/
01350     
01351 
01352 static void cardcheckinit (void) {
01353     
01354     /*
01355     1.0b23 dmb: call startCard script directly from here, after doing 
01356     preliminary auto-initialization. also, detect when startCard sets 
01357     the active text and don't override it.
01358     */
01359     
01360     if ((**runtimedata).initfields) {
01361         
01362         if (!(**iowadata).notscriptedcard) {
01363             
01364             hdlobject objectlist = (**iowadata).objectlist;
01365             Handle hscript;
01366             bigstring errorstring;
01367         
01368             frontSetRuntimeCard (true, false);
01369         
01370             visitobjects (objectlist, &nilvaluesvisit);
01371             
01372             visitobjects (objectlist, &initexclusiveobjectsvisit);
01373             
01374             turnonfirstexclusiveobject (objectlist);
01375             
01376             /*1.0b23 dmb: call startCard now that we've done default setup*/
01377             newtexthandle ("\pif defined (startCard) {startCard ()}", &hscript);
01378             
01379             if (!runcardscript (hscript, idfrontier, false, errorstring, nil)) {
01380                 
01381                 if ((**iowadata).runmode)
01382                     alertdialog (errorstring);
01383                 }
01384             
01385             visitobjects (objectlist, &majorrecalcvisit);
01386             }
01387         
01388         iowapreupdate ();
01389         
01390         runmodeupdate (); 
01391         
01392         if ((**iowadata).activetextobject == nil) /*startup script didn't init text*/
01393             initeditabletext ();
01394         
01395         (**runtimedata).initfields = false;
01396         }
01397     } /*cardcheckinit*/
01398 
01399 
01400 #pragma global_optimizer off
01401 
01402 Rect edittextrect;
01403 
01404 static boolean objectVisit (hdlobject h) {
01405 
01406     /*
01407     7.0b54 PBS: Visit routine.
01408     */
01409     
01410     if ((**h).objecttype == edittexttype) {
01411     
01412         edittextrect = (**h).objectrect;
01413         
01414         return (false); /*stop visit*/
01415         }
01416         
01417     return (true); /*continue visit*/
01418     } /*objectVisit*/
01419 
01420 
01421 static boolean cardContainsEditTextObject (hdlcard h) {
01422     
01423     /*
01424     7.0b54 PBS: For OS X appearance we need to know if a card contains
01425     an editable text object. If not, we we can use the Theme background.
01426     If it does, we have to use a color background.*/
01427     
01428     if (!IOAvisitobjects ((**h).objectlist, &objectVisit))
01429         return (true);
01430     
01431     return (false);
01432     } /*cardContainsEditTextObject*/
01433 
01434 
01435 static void frameedittextrect (Rect r, WindowPtr w) {
01436     
01437     /*
01438     draw a border, leaving out the right side of the rect.  makes it prettier
01439     if you're displaying a scrollbar to the right of the rect, for example.
01440 
01441     5.0a25 dmb: for Win vesion we now use this routine to frame the content
01442     areas
01443     
01444     2002-10-13 AR: Declared static to eliminate compiler warning about
01445     missing function prototype. Commented out variable declaration for depth
01446     to eliminate compiler warning about unused variable.
01447     */
01448     
01449     --r.bottom;
01450     
01451     movepento (r.right, r.top); 
01452     
01453     pendrawline (r.left, r.top); /*draw top of box*/
01454     
01455     pendrawline (r.left, r.bottom); /*draw left side of box*/
01456     
01457     pendrawline (r.right, r.bottom); /*draw bottom of box*/
01458     
01459     #if TARGET_API_MAC_CARBON == 1
01460     
01461         {
01462         Rect rwindow;
01463         Rect rbackground;
01464         //short depth;
01465         CGrafPtr thePort = GetWindowPort (w);
01466         
01467         GetPortBounds (thePort, &rwindow);
01468 
01469         //depth = maxdepth (&rwindow);
01470         
01471         rwindow = r;
01472                 
01473         pushpen ();
01474         
01475         setthemepen (kThemeBrushDialogBackgroundActive, rwindow, true);
01476         
01477         rbackground.top = 0;
01478         rbackground.left = 0;
01479         rbackground.bottom = r.top - 1;
01480         rbackground.right = rwindow.right;
01481         
01482         paintrect (rbackground);
01483         
01484         rbackground.right = r.left - 1;
01485         rbackground.bottom = rwindow.bottom;
01486         
01487         paintrect (rbackground);
01488         
01489         rbackground.left = r.right;
01490         rbackground.right = rwindow.right;
01491         
01492         paintrect (rbackground);
01493         
01494         rbackground.left = 0;
01495         rbackground.top = r.bottom + 1;
01496         rbackground.bottom = rwindow.bottom;
01497         
01498         paintrect (rbackground);
01499         
01500         poppen ();
01501         }
01502     
01503     
01504     #endif
01505     } /*frame3sides*/
01506 
01507 WindowPtr newCardWindow (Point pt, boolean notscriptedcard, Handle hpackedcard) {
01508     
01509     /*
01510     create a new window to run the packed card.
01511     
01512     dmb 6/27/96: don't disposehandle (iowadata); must iowadisposerecord.
01513                  (fixes memory leak.)
01514     */
01515     
01516     WindowPtr w = nil;
01517     hdlruntimerecord hw;
01518     hdlcard hc;
01519     
01520     iowadata = nil;
01521     
01522     if (!newclearhandle (longsizeof (tyruntimerecord), (Handle *) &runtimedata))
01523         return (false);
01524     
01525     if (!newclearhandle (longsizeof (tycard), (Handle *) &iowadata))
01526         goto error;
01527         
01528     hw = runtimedata; 
01529     
01530     hc = iowadata; 
01531         
01532     (**hw).hc = hc;
01533     
01534     (**hc).runmode = true; 
01535     
01536     if (!iowaunpack (hpackedcard))
01537         goto error;
01538 
01539     (**hc).runmode = true;
01540     
01541     (**hc).notscriptedcard = notscriptedcard;
01542     
01543     (**hc).updatecallback = &runmodeupdate;
01544     
01545     /*DW 10/17/93: transition from default window resources, to letting the card specify*/ {
01546         
01547         short resnum = (**hc).idwindow; /*first try, use the resnum specified by card editor*/
01548         
01549         if (systemhascolor ())
01550             w = GetNewCWindow (resnum, nil, (WindowPtr) -1);
01551         else
01552             w = GetNewWindow (resnum, nil, (WindowPtr) -1);
01553         
01554         if (w == nil)
01555             goto error;
01556         
01557         #if TARGET_API_MAC_CARBON == 1 /*Theme background on OS X*/
01558         
01559             if (!cardContainsEditTextObject (hc))
01560                 
01561                 SetThemeWindowBackground (w, kThemeBrushModelessDialogBackgroundActive, false);
01562 
01563             else {
01564             
01565                 SetPort (GetWindowPort (w));
01566 
01567                 frameedittextrect (edittextrect, w);
01568                 } /*else*/
01569 
01570         #endif
01571         }
01572     
01573     SizeWindow (w, (**hc).rightborder, (**hc).bottomborder, false);
01574 
01575     ShowWindow (w);
01576     //Code change by Timothy Paustian Wednesday, August 23, 2000 9:20:56 PM
01577     //
01578     {
01579     #if TARGET_API_MAC_CARBON
01580     CGrafPtr    thePort = GetWindowPort(w);
01581     #else
01582     GrafPtr thePort = (GrafPtr)w;
01583     #endif
01584 
01585     SetPort (thePort);
01586     }
01587     
01588     if ((pt.h != 0) && (pt.v != 0))
01589         MoveWindow (w, pt.h, pt.v, false);
01590     else
01591     {
01592         //Code change by Timothy Paustian Monday, June 26, 2000 3:15:51 PM
01593         //
01594         #if TARGET_API_MAC_CARBON == 1
01595         BitMap      screenBits;
01596         GetQDGlobalsScreenBits(&screenBits);
01597         centerwindow(w, screenBits.bounds);
01598         #else
01599         centerwindow (w, quickdrawglobal (screenBits).bounds);
01600         #endif
01601         
01602     }
01603     (**hw).macwindow = w;
01604     
01605     (**hw).ownwindow = true;
01606     
01607     (**hw).initfields = true;
01608     
01609     /*set the window title*/ {
01610         
01611         bigstring bs;
01612         
01613         texthandletostring ((**hc).windowtitle, bs);
01614         
01615         SetWTitle (w, bs);
01616         }
01617         
01618     (**hc).drawwindow = w; /*all drawing goes into this window*/
01619     
01620     IACglobals.waitroutine = nil; /*no callback when in runmode*/
01621     
01622     sortobjectlist (); /*sort objects based on window position*/
01623     
01624     laythread (); /*make sure flat threads are installed*/
01625     
01626     addtowindowarray (w, hw);
01627     
01628     /*SetWRefCon (w, (long) runtimedata);*/
01629     
01630     return (w);
01631     
01632     error:
01633     
01634     iowadisposerecord ();
01635     
01636     disposehandle ((Handle) runtimedata);
01637     
01638     if (w != nil)
01639         DisposeWindow (w);
01640     
01641     return (nil);
01642     } /*newCardWindow*/
01643     
01644 #pragma global_optimizer reset
01645 
01646     
01647 boolean visitCardWindows (tycardwindowvisitroutine visit) {
01648 
01649     short ct, i;
01650     
01651     ct = sizewindowarray ();
01652     
01653     for (i = 0; i < ct; i++) { /*look for an empty slot in the window array*/
01654         
01655         WindowPtr w = (*hwindowarray) [i].w;
01656         
01657         if (w != nil) {
01658             
01659             runtimedata = getwindowdata (w); /*set up global for runmode routines*/
01660     
01661             iowadata = getwindowcardrecord (w); /*set up global for card routines*/
01662             
01663             if (!(*visit) (w))
01664                 return (false);
01665             }
01666         } /*for*/
01667         
01668     return (true);
01669     } /*visitCardWindows*/
01670     
01671     
01672 void getCardData (WindowPtr w, hdlruntimerecord *hcardwindow) {
01673     
01674     /*
01675     after calling newCardWindow, you can use this entry to get the data handle
01676     linked into the window, so you can override the default settings.
01677     */
01678     
01679     *hcardwindow = getwindowdata (w); 
01680     } /*getCardData*/
01681     
01682     
01683 boolean cardEditCommand (short editcommand) {
01684     
01685     WindowPtr w = FrontWindow ();
01686     hdlcard hcard;
01687     hdlobject hobject;
01688     hdleditrecord hedit;
01689     
01690     if (!inwindowarray (w)) /*it's not one of our windows, app handles the command*/
01691         return (false);
01692     
01693     hcard = getwindowcardrecord (w); /*set up global for card routines*/
01694     
01695     hobject = (**hcard).activetextobject;
01696     
01697     if (hobject == nil) /*consume the command, but there's nothing to do*/
01698         return (true);
01699         
01700     hedit = (hdleditrecord) (**hobject).objecteditrecord;
01701         
01702     switch (editcommand) {
01703         
01704         case cutCmd:
01705             editcut (hedit);
01706             
01707             break;
01708             
01709         case copyCmd:
01710             editcopy (hedit);
01711             
01712             break;
01713             
01714         case pasteCmd:
01715             editpaste (hedit);
01716             
01717             (**hcard).runtimevaluechanged = true; /*DW 10/27/95*/
01718             
01719             break;
01720             
01721         case clearCmd:
01722             editreplace ("\p", hedit);
01723             
01724             break;
01725             
01726         case selectAllCmd:  /* 2006-05-04 smd */
01727             editselectall (hedit);
01728             
01729             break;
01730             
01731         } /*switch*/
01732         
01733     return (true);
01734     } /*cardEditCommand*/
01735 
01736 
01737 static boolean showinvisiblesvisit (hdlobject h) {
01738     
01739     derefclone (&h);
01740     
01741     if (!(**h).objectvisible) {
01742         
01743         Rect r;
01744         
01745         getobjectrect (h, &r);
01746         
01747         pushpen ();
01748         //Code change by Timothy Paustian Monday, June 26, 2000 3:15:59 PM
01749         //
01750         #if TARGET_API_MAC_CARBON == 1
01751         {
01752         Pattern gray;
01753         GetQDGlobalsGray(&gray);
01754         PenPat(&gray);
01755         }
01756         #else
01757         PenPat (&quickdrawglobal (gray)); 
01758         #endif
01759         FrameRect (&r);
01760         
01761         poppen ();
01762         //Code change by Timothy Paustian Monday, June 26, 2000 3:16:06 PM
01763         //
01764         #if TARGET_API_MAC_CARBON == 1
01765         if((**iowadata).drawwindow != nil)
01766             InvalWindowRect((**iowadata).drawwindow, &r);
01767         #else
01768         InvalRect (&r);
01769         #endif
01770         
01771         }
01772         
01773     return (true);
01774     } /*showinvisiblesvisit*/
01775     
01776 
01777 static void checkinvisibles (void) {
01778     
01779     boolean flfirstloop = true;
01780     
01781     if (iowadata == nil) /*defensive, it can happen*/
01782         return;
01783     
01784     while (cmdkeydown () && optionkeydown ()) {
01785         
01786         if (flfirstloop) {
01787         
01788             visitobjects ((**iowadata).objectlist, &showinvisiblesvisit);
01789             
01790             flfirstloop = false;
01791             }
01792         } /*while*/
01793         
01794     if (!flfirstloop) 
01795         runmodeupdate ();
01796     } /*checkinvisibles*/
01797 
01798 
01799 boolean handleCardEvent (WindowPtr w, EventRecord *ev, boolean *flcloseallwindows) {
01800     
01801     /*
01802     returns true if the event has been handled. 
01803     
01804     if false, you should handle it.
01805     
01806     dmb 1.0b21: for iowaOkeyDokeyEvent, press default button if there is one,
01807     else the cancel button. In any case, we'll end up calling closeCardWindow
01808     
01809     dmb 1.0b24: don't filter activate and update event that are ours. The client
01810     will see those events if they're not for us.
01811     */
01812     
01813     boolean flhandled;
01814     CGrafPtr    thePort;
01815     
01816     *flcloseallwindows = false; 
01817 
01818     setkeyboardstatus ((*ev).message, (*ev).what, (*ev).modifiers); /*set fields of keyboardstatus record*/
01819         
01820     if (!inwindowarray (w)) /*it's not one of our windows, you handle the event*/
01821         return (false);
01822 
01823     runtimedata = getwindowdata (w); /*set up global for runmode routines*/
01824         
01825     iowadata = getwindowcardrecord (w); /*set up global for card routines*/
01826     
01827     if ((*ev).what != activateEvt && (*ev).what != updateEvt) { /*1.0b24 dmb: don't give them our updates & activate*/
01828         filterevent (ev); /*pass the event thru the callback routine if there is one*/
01829         }
01830     
01831     iowadata = getwindowcardrecord (w); /*set up global for card routines*/
01832     
01833     (**iowadata).macevent = *ev; /*for anyone with an interest in the event record*/
01834     
01835     releasetemphandles (); /*dispose of any temps created by the previous event*/
01836     
01837     //Code change by Timothy Paustian Monday, August 21, 2000 9:34:50 PM
01838     //have to use the port can't cast a window in OS X
01839     {
01840     #if TARGET_API_MAC_CARBON == 1
01841         thePort = GetWindowPort(w);
01842     #else
01843         thePort = (CGrafPtr)w;  
01844     #endif
01845     pushmacport (thePort);
01846     }
01847     
01848     cardcheckinit ();
01849     
01850     //iowavalidate (true); 
01851     
01852     flhandled = true; /*default, we handled the event*/
01853     
01854     switch ((*ev).what) {
01855     
01856         case keyDown: case autoKey:
01857             flhandled = runmodekeystroke ();
01858             #if TARGET_API_MAC_CARBON == 1
01859                 //a key stoke was entered. We need to flush it to the screen on OS X
01860                 if (!flhandled)
01861                     QDFlushPortBuffer(thePort, nil);
01862             #endif
01863             break;
01864             
01865         case mouseUp:
01866             runmodemouseup ((*ev).when, (*ev).where);
01867             
01868             break;
01869            
01870         case mouseDown: 
01871             flhandled = runmodemousedown ((*ev).when, (*ev).where, flcloseallwindows);
01872             
01873             break;  
01874             
01875         case activateEvt:
01876             runmodeactivate ((*ev).modifiers & activeFlag);
01877             
01878             break;
01879         
01880         case updateEvt:
01881             runmodeupdate ();
01882             
01883             break;
01884         
01885         /*4.1b4 dmb: must handle own activates*/
01886         case osEvt:
01887             runmodeactivate ((*ev).modifiers & resumeFlag);
01888             
01889             break;
01890         
01891         case nullEvent:
01892 
01893             if (w == FrontWindow ())
01894                 runmodeidle ();
01895             else
01896                 runmodecheckupdate (); /*DW 9/13/93: may need update even if it's not in front*/
01897             
01898             flhandled = false; /*let the client get a shot at null events too*/
01899             
01900             break;
01901         
01902         case iowaOkeyDokeyEvent: /*dmb 1.0b21*/
01903             flhandled = !visitobjects ((**iowadata).objectlist, &returnkeyvisit);
01904             
01905             if (!flhandled) {
01906                 
01907                 keyboardstatus.chkb = chescape;
01908                 
01909                 flhandled = runmodekeystroke ();
01910                 }
01911             
01912             break;
01913         } /*switch*/
01914 
01915     checkinvisibles ();
01916     
01917     popmacport ();
01918     
01919     return (flhandled);
01920     } /*handleCardEvent*/
01921     
01922     
01923 static boolean nullsforallvisit (WindowPtr w) {
01924     
01925     hdlruntimerecord hcw = getwindowdata (w);
01926     EventRecord ev;
01927     boolean flcloseallwindows;
01928     
01929     if ((**hcw).modeless) {
01930     
01931         clearbytes (&ev, longsizeof (ev));
01932     
01933         ev.what = nullEvent;
01934     
01935         handleCardEvent (w, &ev, &flcloseallwindows);
01936         }
01937     
01938     return (true);
01939     } /*nullsforallvisit*/
01940     
01941     
01942 static boolean nullsforall (void) {
01943     
01944     /*
01945     send a null event to every modeless card that's open.
01946     */
01947     
01948     hdlruntimerecord saveruntimedata = runtimedata;
01949     hdlcard saveiowadata = iowadata;
01950     GrafPtr oldport;
01951     
01952     GetPort (&oldport);
01953 
01954     visitCardWindows (&nullsforallvisit);
01955 
01956     runtimedata = saveruntimedata;
01957     iowadata = saveiowadata;
01958     SetPort (oldport);
01959     
01960     return (true);
01961     } /*nullsforall*/
01962     
01963     
01964 boolean setObjectValue (hdlcard hcard, bigstring name, Handle hvalue) {
01965 
01966     hdlcard oldcard = iowadata;
01967     boolean fl;
01968     
01969     iowadata = hcard;
01970     
01971     fl = setCardValue (name, hvalue);
01972     
01973     iowadata = oldcard;
01974     
01975     return (fl);
01976     } /*setObjectValue*/
01977     
01978     
01979 boolean getObjectValue (hdlcard hcard, bigstring name, Handle *hvalue) {
01980     
01981     hdlcard oldcard = iowadata;
01982     boolean fl;
01983     
01984     iowadata = hcard;
01985     
01986     fl = getCardValue (name, hvalue);
01987     
01988     iowadata = oldcard;
01989     
01990     return (fl);
01991     } /*getObjectValue*/
01992 
01993 
01994 boolean getObjectHandle (hdlcard hcard, bigstring name, hdlobject *h) {
01995     
01996     hdlcard oldcard = iowadata;
01997     boolean fl;
01998     
01999     iowadata = hcard;
02000     
02001     fl = lookupname (name, h);
02002     
02003     iowadata = oldcard;
02004     
02005     return (fl);
02006     } /*getObjectHandle*/
02007     
02008     
02009 boolean recalcObject (hdlobject h) {
02010     
02011     /*
02012     Card Editor has all of its recalculation done for it thru Iowa
02013     Runtime. the object handle has a handle to the card that contains
02014     it. its objecttmpbit is set true if it's a major recalc, false
02015     if its a minor one.
02016     */
02017     
02018     hdlcard oldcard = iowadata;
02019     boolean fl;
02020     
02021     iowadata = (**h).owningcard;
02022     
02023     fl = recalcbottleneck (h, (**h).objecttmpbit);
02024     
02025     (**h).objecttmpbit = false;
02026     
02027     iowadata = oldcard;
02028     
02029     return (fl);
02030     } /*recalcObject*/
02031     
02032     
02033 boolean updateCard (hdlcard hcard) {
02034 
02035     hdlcard oldcard = iowadata;
02036     
02037     iowadata = hcard;
02038     
02039     runtimedata = getwindowdata ((**iowadata).drawwindow); 
02040     
02041     runmodecheckupdate ();
02042     
02043     runmodeupdate ();
02044     
02045     iowadata = oldcard;
02046     
02047     if (iowadata == nil)
02048         runtimedata = nil;
02049     else
02050         runtimedata = getwindowdata ((**iowadata).drawwindow); 
02051     
02052     return (true);
02053     } /*updateCard*/
02054 
02055 
02056 boolean cardIsModal (Handle hpackedcard) {
02057 
02058     tydiskheader header;
02059     
02060     moveleft (*hpackedcard, &header, longsizeof (header));
02061     
02062     disktomemlong (header.idwindow);    /* 2006-04-17 aradke: for Mac Intel */
02063     
02064     switch (header.idwindow) {
02065         
02066         case 1024: case 1025:
02067             return (true);
02068             
02069         case 1026: case 1027:
02070             return (false);
02071             
02072         } /*switch*/
02073         
02074     #ifdef fldebug
02075     
02076         DebugStr ("\punexpected window resource id");
02077         
02078     #endif
02079     
02080     return (true);
02081     } /*cardIsModal*/
02082     
02083     
02084 static boolean returnNamedValueVisit (hdlobject h) {
02085     
02086     /*
02087     a special AE that might only be useful in Card Editor's
02088     double-click dialog. but it makes it much faster.
02089     
02090     we return the values of all objects that have four-
02091     character names. only checkboxes, radio buttons and 
02092     edittexts.
02093     */
02094     
02095     Handle hname, hvalue;
02096     bigstring bs;
02097     OSType key;
02098     
02099     getobjectname (h, &hname);
02100     
02101     if (hname == nil)
02102         return (true);
02103         
02104     texthandletostring (hname, bs);
02105         
02106     if (stringlength (bs) != 4) /*keep going*/
02107         return (true);
02108     
02109     BlockMove (&bs [1], &key, 4);
02110     
02111     switch ((**h).objecttype) {
02112         
02113         case checkboxtype: case radiobuttontype:
02114             IACpushbooleanparam ((**h).objectflag, key);
02115             
02116             break;
02117             
02118         case edittexttype:
02119             getobjectvalue (h, &hvalue);
02120             
02121             copyhandle (hvalue, &hvalue);
02122             
02123             IACpushtextparam (hvalue, key);
02124             
02125             break;
02126         } /*switch*/
02127         
02128     return (true); /*keep visiting*/
02129     } /*returnNamedValueVisit*/
02130 
02131 
02132 static void getCardAttributesVerb (void) {
02133     
02134     Boolean returnedValue;
02135     
02136     returnedValue = IACgetcardattributes ();
02137     
02138     IACreturnboolean (returnedValue);
02139     } /*getCardAttributesVerb*/
02140 
02141 
02142 static void setCardAttributesVerb (void) {
02143     
02144     Boolean returnedValue;
02145     
02146     returnedValue = IACsetcardattributes ();
02147     
02148     IACreturnboolean (returnedValue);
02149     } /*setCardAttributesVerb*/
02150 
02151 
02152 static void getObjectAttributesVerb (void) {
02153     
02154     Handle param1;
02155     Boolean returnedValue;
02156     
02157     if (!IACgettextparam ('prm1', &param1))
02158         return;
02159     
02160     returnedValue = IACgetobjectattributes (param1);
02161     
02162     IACreturnboolean (returnedValue);
02163     } /*getObjectAttributesVerb*/
02164 
02165 
02166 static void setObjectAttributesVerb (void) {
02167     
02168     Handle param1;
02169     Boolean returnedValue;
02170     
02171     if (!IACgettextparam ('prm1', &param1))
02172         return;
02173     
02174     returnedValue = IACsetobjectattributes (param1);
02175     
02176     IACreturnboolean (returnedValue);
02177     } /*setObjectAttributesVerb*/
02178     
02179     
02180 static pascal OSErr appleEventHandler (const AppleEvent *event, AppleEvent *reply, long refcon) {
02181     
02182     /*
02183     4.1b14 dmb: since we're installing out handler in the client's process,
02184     we need to set up our A5 globals
02185     */
02186     
02187     #if !TARGET_API_MAC_CARBON
02188     long curA5 = SetUpAppA5 ();
02189     #endif
02190 
02191     IACglobals.event = (AppleEvent *) event; 
02192     
02193     IACglobals.reply = reply;
02194     
02195     IACglobals.refcon = refcon;
02196         
02197     switch (IACgetverbtoken ()) {
02198     
02199         case 'clos':
02200             if (runtimedata != nil)
02201                 (**runtimedata).closethiswindow = true;
02202             
02203             break;
02204             
02205         case 'gacd':
02206             getCardAttributesVerb (); 
02207             
02208             break;
02209         
02210         case 'sacd':
02211             setCardAttributesVerb (); 
02212             
02213             break;
02214         
02215         case 'gaob':
02216             getObjectAttributesVerb (); 
02217             
02218             break;
02219         
02220         case 'saob':
02221             setObjectAttributesVerb (); 
02222             
02223             break;
02224             
02225         case 'mema': {
02226             Size x;
02227     
02228             MaxMem (&x);
02229             
02230             IACreturnlong (FreeMem ());
02231             
02232             break;
02233             }
02234             
02235         case 'rnov':
02236             IACglobals.event = IACglobals.reply; /*push the values onto the reply record*/
02237             
02238             visitobjects ((**iowadata).objectlist, &returnNamedValueVisit); 
02239             
02240             break;
02241         } /*switch*/
02242 
02243     #if !TARGET_API_MAC_CARBON
02244     RestoreA5 (curA5);
02245     #endif
02246         
02247     return (noErr);
02248     } /*appleEventHandler*/
02249 
02250 //Code change by Timothy Paustian Monday, June 26, 2000 3:11:06 PM
02251 //switched to new conditional.
02252 #if !TARGET_RT_MAC_CFM
02253 
02254     #define appleEventHandlerUPP (&appleEventHandler)
02255     
02256 #else
02257 
02258     #if TARGET_API_MAC_CARBON == 1
02259     
02260     AEEventHandlerUPP appleEventHandlerDesc = nil;
02261     #define appleEventHandlerUPP (appleEventHandlerDesc)
02262     
02263     #else
02264         
02265     static RoutineDescriptor appleEventHandlerDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEEventHandlerProcInfo, appleEventHandler);
02266 
02267     #define appleEventHandlerUPP (&appleEventHandlerDesc)
02268     #endif
02269         
02270 
02271 #endif
02272 
02273 
02274 
02275 void installRuntimeEventHandlers (void) {
02276     
02277     /*
02278     1.0b19 dmb: reinstall handlers every time we're called. It could be 
02279     the we're competing with handlers installed by other cards being 
02280     run from OSA scripts. along with this, we must be sure to create 
02281     the UPP just once, so we can't use IACinstallhandler.
02282     */
02283     
02284     static boolean flinstalled = false;
02285     
02286     if (!flinstalled) {
02287         //Code change by Timothy Paustian Friday, July 21, 2000 10:36:08 PM
02288         //create the UPP for the apple event handler
02289         #if TARGET_API_MAC_CARBON && TARGET_RT_MAC_CFM
02290         if (appleEventHandlerDesc == nil)
02291             appleEventHandlerDesc = NewAEEventHandlerUPP(appleEventHandler);
02292         #endif
02293         AEInstallEventHandler ('card', typeWildCard, appleEventHandlerUPP, 0, false);
02294         
02295         /*
02296         IACinstallhandler ('card', typeWildCard, (ProcPtr) &appleEventHandler);
02297         
02298         flinstalled = true; // 1.0b19 dmb: commented out
02299         */
02300         }
02301     } /*installRuntimeEventHandlers*/
02302     
02303     
02304 static boolean passthruevent (short what) {
02305     
02306     return ((what == updateEvt) || (what == activateEvt) || (what == osEvt)  || (what == diskEvt));
02307     } /*passthruevent*/
02308 
02309 
02310 boolean runModalCard (Handle hpackedcard, boolean flscriptedcard, short top, short pLeft, tycardeventcallback pCallback) {
02311     // 2006-04-03 - kw --- renamed params left -pLeft, callback -> pCallback
02312     /*
02313     dmb 1.0b24: changed flcallback logic. we no longer call back on activate
02314     and update events that we just handled
02315     */
02316     
02317     hdlcard oldiowadata = iowadata; 
02318     hdlruntimerecord oldruntimedata = runtimedata;
02319     GrafPtr oldport;
02320     WindowPtr modalwindow;
02321     Point winpos;
02322     boolean flreturn;
02323     
02324     GetPort (&oldport);
02325     
02326     installRuntimeEventHandlers ();
02327     
02328     winpos.v = top;
02329     
02330     winpos.h = pLeft;
02331     
02332     modalwindow = newCardWindow (winpos, !flscriptedcard, hpackedcard);
02333     
02334     flreturn = true;
02335         
02336     if (modalwindow == nil) {
02337         
02338         flreturn = false;
02339         
02340         goto exit;
02341         }
02342         
02343     (**runtimedata).callback = pCallback;
02344         
02345     (**runtimedata).modeless = false;
02346     
02347     if (flscriptedcard) {
02348 
02349         if (!frontStartCard (nil)) {
02350             
02351             flreturn = false;
02352             
02353             goto exit;
02354             }
02355         }
02356     //Code change by Timothy Paustian Wednesday, August 23, 2000 9:21:06 PM
02357     //
02358     {
02359     #if TARGET_API_MAC_CARBON
02360     CGrafPtr    thePort = GetWindowPort(modalwindow);
02361     #else
02362     GrafPtr thePort = (GrafPtr)modalwindow;
02363     #endif
02364 
02365     SetPort (thePort);
02366     }
02367 
02368     sendinitmessage ();
02369         
02370     cardcheckinit (); /*1.0b23 dmb: init field before showing the card. more responsive*/
02371     
02372     flexitcardloop = false;
02373     
02374     ShowWindow (modalwindow);
02375     
02376     while (true) {
02377         
02378         EventRecord ev;
02379         WindowPtr eventwindow;
02380         boolean flcloseallwindows;
02381         boolean flcallback = false;
02382         
02383         WaitNextEvent (everyEvent, &ev, 1, nil);
02384         
02385         if (ev.what == nullEvent) /*send a null event to every modeless card*/
02386             nullsforall ();
02387             
02388         geteventwindow (&ev, &eventwindow);
02389         
02390         if (eventwindow == modalwindow)
02391             flcallback = !handleCardEvent (eventwindow, &ev, &flcloseallwindows);
02392         else
02393             flcallback = passthruevent (ev.what) || (eventwindow == nil);
02394         
02395         /*
02396         if (eventwindow == modalwindow) {
02397         
02398             flcallback = !handleCardEvent (eventwindow, &ev, &flcloseallwindows);
02399             }
02400         else {
02401             if ((passthruevent (ev.what)) || (eventwindow == nil)) {
02402                 
02403                 if (!handleCardEvent (eventwindow, &ev, &flcloseallwindows)) {
02404                     
02405                     flcallback = true;
02406                     }
02407                 }
02408             }
02409         */
02410             
02411         if ((flcallback) && (pCallback != nil)) {
02412             
02413             hdlcard loldiowadata = iowadata;
02414             hdlruntimerecord loldruntimedata = runtimedata;
02415             
02416             (*pCallback) (&ev);
02417             
02418             iowadata = loldiowadata;
02419         
02420             runtimedata = loldruntimedata;
02421             //Code change by Timothy Paustian Wednesday, August 23, 2000 9:21:26 PM
02422             //
02423             {   
02424             #if TARGET_API_MAC_CARBON
02425             CGrafPtr    thePort = GetWindowPort(modalwindow);
02426             #else
02427             GrafPtr thePort = (GrafPtr)modalwindow;
02428             #endif
02429         
02430             SetPort (thePort);
02431             }
02432             }
02433             
02434         if (flexitcardloop)
02435             break;
02436         
02437         if ((**runtimedata).closethiswindow) /*set true by an Apple Event*/
02438             closeCardWindow (modalwindow); 
02439         
02440         if (flexitcardloop) /*can be set by closeCardWindow*/
02441             break;
02442         } /*while*/
02443         
02444     exit:
02445         
02446     flexitcardloop = false; /*we consume it, modal cards can be nested*/
02447     
02448     /*restore saved globals*/ {
02449     
02450         iowadata = oldiowadata;
02451         
02452         runtimedata = oldruntimedata;
02453     
02454         SetPort (oldport);
02455         }
02456     
02457     return (flreturn);
02458     } /*runModalCard*/
02459     
02460 
02461 boolean isModelessCardEvent (EventRecord *ev, boolean *flcloseallwindows) {
02462     
02463     hdlcard oldiowadata = iowadata; 
02464     hdlruntimerecord oldruntimedata = runtimedata;
02465     //Code change by Timothy Paustian Monday, June 26, 2000 3:16:19 PM
02466     //
02467     #if TARGET_API_MAC_CARBON == 1
02468     CGrafPtr oldport = GetQDGlobalsThePort();
02469     #else   
02470     GrafPtr oldport = quickdrawglobal (thePort);
02471     #endif
02472         boolean flreturn = false;
02473     WindowPtr w;
02474     
02475     if ((*ev).what == nullEvent) {
02476     
02477         nullsforall ();
02478         
02479         goto exit; /*return false -- let the main event loop process it too*/
02480         }
02481         
02482     geteventwindow (ev, &w);
02483 
02484     if (isCardWindow (w)) 
02485         flreturn = handleCardEvent (w, ev, flcloseallwindows);
02486     
02487     exit:
02488     
02489     /*restore saved globals*/ {
02490     
02491         iowadata = oldiowadata;
02492         
02493         runtimedata = oldruntimedata;
02494     
02495         SetPort (oldport);
02496         }
02497     
02498     return (flreturn);
02499     } /*isModelessCardEvent*/
02500     
02501     
02502 boolean runModelessCard (Handle hpackedcard, boolean flscriptedcard, short top, short pLeft, tycardeventcallback pCallback) {
02503     
02504     /*
02505     dmb 1.024: call cardcheckinit here, before showing window. 
02506     this accomplishes three things:
02507     
02508     1. It ensures that all fields are before the card is shown.
02509     
02510     2. Invoking a card is crisper; we don't need to wait for a null
02511        event before running startup scripts.
02512        
02513     3. It allows the calling script's context to be in force as our 
02514        initial recalc scripts and starupScript run.
02515     */
02516     
02517     hdlcard oldiowadata = iowadata; 
02518     hdlruntimerecord oldruntimedata = runtimedata;
02519     //Code change by Timothy Paustian Monday, June 26, 2000 3:15:15 PM
02520     //
02521     #if TARGET_API_MAC_CARBON == 1
02522     CGrafPtr oldport = GetQDGlobalsThePort();
02523     #else
02524     GrafPtr oldport = quickdrawglobal (thePort);
02525     #endif
02526         Point winpos;
02527     WindowPtr modelesswindow;
02528     boolean flreturn;
02529     
02530     installRuntimeEventHandlers ();
02531     
02532     winpos.v = top;
02533     
02534     winpos.h = pLeft;
02535     
02536     modelesswindow = newCardWindow (winpos, !flscriptedcard, hpackedcard);
02537     
02538     flreturn = true;
02539     
02540     if (modelesswindow == nil) {
02541         
02542         flreturn = false;
02543         
02544         goto exit;
02545         }
02546         
02547     (**runtimedata).callback = pCallback;
02548         
02549     (**runtimedata).modeless = true;
02550     
02551     if (flscriptedcard) {
02552     
02553         if (!frontStartCard (nil)) {
02554         
02555             flreturn = false;
02556         
02557             goto exit;
02558             }
02559         }
02560     
02561     //Code change by Timothy Paustian Wednesday, August 23, 2000 9:21:06 PM
02562     //
02563     {
02564     #if TARGET_API_MAC_CARBON
02565     CGrafPtr    thePort = GetWindowPort(modelesswindow);
02566     #else
02567     GrafPtr thePort = (GrafPtr)modelesswindow;
02568     #endif
02569 
02570     SetPort (thePort);
02571     }
02572     
02573     sendinitmessage ();
02574     
02575     cardcheckinit (); /*1.0b24 dmb: see comment above*/
02576     
02577     ShowWindow (modelesswindow);
02578 
02579     exit:
02580     
02581     /*restore saved globals*/ {
02582     
02583         iowadata = oldiowadata;
02584         
02585         runtimedata = oldruntimedata;
02586     
02587         SetPort (oldport);
02588         }
02589         
02590     return (flreturn);
02591     } /*runModelessCard*/
02592      
02593 
02594 boolean runCard (Handle hpackedcard, boolean flscriptedcard, short top, short pleft, tycardeventcallback pcallback) {
02595     
02596     boolean fl;
02597     
02598     if (cardIsModal (hpackedcard)) 
02599         fl = runModalCard (hpackedcard, flscriptedcard, top, pleft, pcallback);
02600     else
02601         fl = runModelessCard (hpackedcard, flscriptedcard, top, pleft, pcallback);
02602         
02603     return (fl);
02604     } /*runCard*/
02605 
02606 
02607 #pragma global_optimizer off
02608     
02609 static WindowPtr moveIntoCardWindow (WindowPtr hostwindow, boolean notscriptedcard, Handle hpackedcard) {
02610     
02611     /*
02612     use existing window to run the packed card.
02613     
02614     dmb 2.1.96: this could share plenty of code with newCardWindow
02615     */
02616     
02617     WindowPtr w = hostwindow;
02618     hdlruntimerecord hw;
02619     hdlcard hc;
02620     
02621     iowadata = nil;
02622     
02623     if (!newclearhandle (longsizeof (tyruntimerecord), (Handle *) &runtimedata))
02624         return (false);
02625     
02626     if (!newclearhandle (longsizeof (tycard), (Handle *) &iowadata))
02627         goto error;
02628         
02629     hw = runtimedata; 
02630     
02631     hc = iowadata; 
02632     
02633     (**hw).hc = hc;
02634     
02635     (**hc).runmode = true; 
02636     
02637     if (!iowaunpack (hpackedcard))
02638         goto error;
02639 
02640     (**hc).runmode = true;
02641     
02642     (**hc).notscriptedcard = notscriptedcard;
02643     
02644     (**hc).updatecallback = &runmodeupdate;
02645     
02646     (**hw).macwindow = w;
02647     
02648     (**hw).ownwindow = false;
02649     
02650     (**hw).initfields = true;
02651     
02652     (**hc).drawwindow = w; /*all drawing goes into this window*/
02653     
02654     IACglobals.waitroutine = nil; /*no callback when in runmode*/
02655     
02656     sortobjectlist (); /*sort objects based on window position*/
02657     
02658     laythread (); /*make sure flat threads are installed*/
02659     
02660     addtowindowarray (w, hw);
02661     
02662     return (w);
02663     
02664     error:
02665     
02666     disposehandle ((Handle) iowadata);
02667     
02668     disposehandle ((Handle) runtimedata);
02669     
02670     iowadata = nil;
02671     
02672     runtimedata = nil;
02673     
02674     return (nil);
02675     } /*moveIntoCardWindow*/
02676 
02677 #pragma global_optimizer reset
02678     
02679     
02680 boolean runHostedCard (WindowPtr hostwindow, Handle hpackedcard, boolean flscriptedcard, tycardeventcallback pCallback) {
02681     
02682     hdlcard oldiowadata = iowadata; 
02683     hdlruntimerecord oldruntimedata = runtimedata;
02684     GrafPtr oldport;
02685     WindowPtr modelesswindow;
02686     boolean flreturn;
02687     
02688     GetPort (&oldport);
02689     
02690     installRuntimeEventHandlers ();
02691     
02692     modelesswindow = moveIntoCardWindow (hostwindow, !flscriptedcard, hpackedcard);
02693     
02694     flreturn = true;
02695     
02696     (**runtimedata).callback = pCallback;
02697     
02698     (**runtimedata).modeless = true;
02699     
02700     if (flscriptedcard) {
02701     
02702         if (!frontStartCard (nil)) {
02703         
02704             flreturn = false;
02705         
02706             goto exit;
02707             }
02708         }
02709     //Code change by Timothy Paustian Wednesday, August 23, 2000 9:21:06 PM
02710     //
02711     {
02712     #if TARGET_API_MAC_CARBON
02713     CGrafPtr    thePort = GetWindowPort(modelesswindow);
02714     #else
02715     GrafPtr thePort = (GrafPtr)modelesswindow;
02716     #endif
02717 
02718     SetPort (thePort);
02719     }
02720     
02721     sendinitmessage ();
02722 
02723     exit:
02724     
02725     /*restore saved globals*/ {
02726     
02727         iowadata = oldiowadata;
02728         
02729         runtimedata = oldruntimedata;
02730     
02731         SetPort (oldport);
02732         }
02733         
02734     return (flreturn);
02735     } /*runHostedCard*/
02736     
02737     
02738 boolean initIowaRuntime (void) {
02739     
02740     /*
02741     4.1b14 dmb: remember A5 for AE handler
02742     */
02743     //Code change by Timothy Paustian Monday, June 26, 2000 3:16:32 PM
02744     //
02745     #if !TARGET_API_MAC_CARBON
02746     RememberA5 ();
02747     #endif
02748         
02749     return (true);
02750     } /*initIowaRuntime*/   
02751     
02752     
02753     

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