appletcardops.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletcardops.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include <iowacore.h>
00008 #include "applet.h"
00009 #include "appletmenu.h"
00010 #include "appletmenuops.h"
00011 #include "appletdate.h"
00012 #include "appletasm.h"
00013 #include "appletcardops.h"
00014 #include "appletmain.h"
00015 #include "appletfolder.h"
00016 #include <ioapopup.h>
00017 #include <ioacolorpopup.h>
00018 #include <ioaedittext.h>
00019 
00020 
00021 
00022 hdlcard currentcard = nil;
00023 
00024 tydialoginfo appdialoginfo [ctdialogs];
00025 
00026 static boolean flglobal; /*for general use*/
00027 
00028 static short fontsizemap [] = {9, 10, 12, 14, 18, 24, 36, 48, 72};
00029     
00030 
00031 
00032 boolean cardobjectexists (bigstring name) {
00033     
00034     hdlobject hobj;
00035     
00036     return (getObjectHandle ((hdlcard) currentcard, name, &hobj));
00037     } /*cardobjectexists*/
00038     
00039     
00040 short getcardpopup (bigstring name) {
00041     
00042     hdlobject hobj;
00043     hdlpopupdata hp;
00044     
00045     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00046         return (0);
00047             
00048     hp = (hdlpopupdata) (**hobj).objectdata;
00049         
00050     return ((**hp).checkeditem);
00051     } /*getcardpopup*/
00052     
00053     
00054 boolean getcardcolorpopup (bigstring name, RGBColor *rgb) {
00055     
00056     hdlobject hobj;
00057     hdlcolordata hdata;
00058     
00059     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00060         return (false);
00061             
00062     hdata = (hdlcolordata) (**hobj).objectdata;
00063     
00064     *rgb = (**hdata).rgb;
00065     
00066     return (true);
00067     } /*getcardpopup*/
00068     
00069     
00070 boolean getcardstring (bigstring name, void *pstring) {
00071     
00072     char *bs = (char *) pstring;
00073     Handle hvalue;
00074     
00075     setstringlength (bs, 0);
00076     
00077     if (!getObjectValue (currentcard, name, &hvalue))
00078         return (false);
00079     
00080     texthandletostring (hvalue, bs);
00081     
00082     return (true);
00083     } /*getcardstring*/
00084 
00085 
00086 boolean getcardpassword (bigstring name, void *pstring) {
00087     
00088     bigstring bs;
00089     hdlobject hobj;
00090     
00091     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00092         return (false);
00093     
00094     if (!gettextbehindbullets (hobj, bs))
00095         return (false);
00096     
00097     copystring (bs, pstring);
00098     
00099     return (true);
00100     } /*getcardpassword*/
00101     
00102 
00103 boolean getcardflag (bigstring name, boolean *fl) {
00104     
00105     hdlobject hobj;
00106     
00107     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00108         return (false);
00109         
00110     *fl = (**hobj).objectflag;
00111     
00112     return (true);
00113     } /*getcardflag*/
00114     
00115         
00116 boolean getcardbit (bigstring name) {
00117     
00118     /*
00119     a special entrypoint that makes it easy to work with booleans that 
00120     are stored as bits
00121     */
00122     
00123     hdlobject hobj;
00124     
00125     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00126         return (false);
00127         
00128     return ((**hobj).objectflag);
00129     } /*getcardbit*/
00130     
00131     
00132 static void invalobjecthandle (hdlobject hobj) {
00133     
00134     hdlcard hc = (hdlcard) (**hobj).owningcard;
00135     
00136     (**hobj).objectinval = true;
00137         
00138     (**hc).needsupdate = true;
00139     } /*invalobjecthandle*/
00140     
00141     
00142 static boolean invalcardobject (bigstring name, boolean fl) {
00143     
00144     hdlobject hobj;
00145     
00146     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00147         return (false);
00148         
00149     invalobjecthandle (hobj);
00150         
00151     return (true);
00152     } /*invalcardobject*/
00153     
00154     
00155 boolean setradiotext (bigstring name, Handle htext) {
00156     
00157     /*
00158     radio buttons and checkboxes set their values differently, so we
00159     need to hack to change the text that's displayed next to them.
00160     
00161     works for checkboxes too.
00162     */
00163     
00164     hdlobject hobj;
00165     
00166     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00167         return (false);
00168     
00169     disposehandle ((**hobj).objectvalue);
00170     
00171     (**hobj).objectvalue = htext;
00172     
00173     invalobjecthandle (hobj);
00174     
00175     return (true);
00176     } /*setradiotext*/
00177     
00178 
00179 boolean setcardstring (bigstring name, void *pstring) {
00180     
00181     char *value = (char *) pstring;
00182     bigstring currentvalue;
00183     Handle htext;
00184     
00185     getcardstring (name, currentvalue);
00186     
00187     if (equalstrings (value, currentvalue)) /*nothing to do*/
00188         return (true);
00189     
00190     if (!newtexthandle (value, &htext))
00191         return (false);
00192         
00193     return (setObjectValue (currentcard, name, htext));
00194     } /*setcardstring*/
00195     
00196     
00197 boolean emptycardpassword (bigstring name) {
00198     
00199     hdlobject hobj;
00200     
00201     if (!setcardstring (name, "\p"))
00202         return (false);
00203     
00204     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00205         return (false);
00206     
00207     return (emptytextbehindbullets (hobj));
00208     } /*emptycardpassword*/
00209     
00210 
00211 boolean setcardpassword (bigstring name, void *pstring) {
00212     
00213     char *value = (char *) pstring;
00214     bigstring currentvalue;
00215     hdlobject hobj;
00216     bigstring bsbullets;
00217     
00218     getcardpassword (name, currentvalue);
00219     
00220     if (equalstrings (value, currentvalue)) /*nothing to do*/
00221         return (true);
00222         
00223     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00224         return (false);
00225         
00226     if (!settextbehindbullets (hobj, value))
00227         return (false);
00228     
00229     filledstring ('', stringlength (value), bsbullets);
00230     
00231     return (setcardstring (name, bsbullets));
00232     } /*setcardpassword*/
00233     
00234     
00235 boolean setcardflag (bigstring name, boolean fl) {
00236     
00237     hdlobject hobj;
00238     
00239     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00240         return (false);
00241         
00242     if (fl) /*limit the possible values to 1 and 0*/
00243         fl = 1;
00244     else
00245         fl = 0;
00246     
00247     if ((**hobj).objectflag != fl) {
00248     
00249         (**hobj).objectflag = fl;
00250     
00251         invalobjecthandle (hobj);
00252         }
00253     
00254     return (true);
00255     } /*setcardflag*/
00256     
00257     
00258 boolean setcardtmpbit (bigstring name, boolean fl) {
00259     
00260     hdlobject hobj;
00261     
00262     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00263         return (false);
00264     
00265     (**hobj).objecttmpbit = fl;
00266     
00267     return (true);
00268     } /*setcardflag*/
00269     
00270     
00271 boolean setcardappbit (bigstring name, short bitnum, boolean fl) {
00272     
00273     /*
00274     there are 4 appbits in each object. they can be used by the app
00275     to communicate between disparate modules.
00276     
00277     for example, when clayinfowindow.c sets up the comment editor,
00278     it sets appbit1, which edittext.c watches for. when it's set
00279     it doesn't select all the text when activating the object.
00280     */
00281     
00282     hdlobject hobj;
00283     
00284     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00285         return (false);
00286     
00287     switch (bitnum) {
00288         
00289         case 1:
00290             (**hobj).appbit1 = fl; 
00291             
00292             break;
00293             
00294         case 2:
00295             (**hobj).appbit2 = fl; 
00296             
00297             break;
00298             
00299         case 3:
00300             (**hobj).appbit3 = fl; 
00301             
00302             break;
00303             
00304         case 4:
00305             (**hobj).appbit4 = fl; 
00306             
00307             break;
00308         } /*switch*/
00309     
00310     return (true);
00311     } /*setcardflag*/
00312     
00313     
00314 boolean setcardtextcolor (bigstring name, RGBColor *rgb) {
00315     
00316     hdlobject hobj;
00317     
00318     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00319         return (false);
00320         
00321     if (!equalcolors (&(**hobj).objecttextcolor, rgb)) {
00322     
00323         (**hobj).objecttextcolor = *rgb;
00324     
00325         invalobjecthandle (hobj);
00326         }
00327     
00328     return (true);
00329     } /*setcardtextcolor*/
00330     
00331     
00332 boolean setcardenable (bigstring name, boolean flenable) {
00333     
00334     /*
00335     DW 8/22/93: return true only if the enabled state changed.
00336     
00337     DW 2/15/95: if we're disabling the active text object, we no longer have
00338     an active text object. if we're enabling a text object, and we have no
00339     active text object, make it the active text object.
00340     */
00341     
00342     hdlobject hobj;
00343     
00344     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00345         return (false);
00346     
00347     if ((**hobj).objectenabled != flenable) {
00348     
00349         (**hobj).objectenabled = flenable;
00350     
00351         (**hobj).objectinval = true;
00352         
00353         (**currentcard).needsupdate = true;
00354         
00355         if ((hobj == (**currentcard).activetextobject) && (!flenable)) { /*DW 2/15/95*/
00356             
00357             hdlcard oldiowadata = iowadata;
00358             
00359             iowadata = currentcard;
00360             
00361             clearactivetextobject ();
00362             
00363             iowadata = oldiowadata;
00364             }
00365             
00366         if ((flenable) && ((**currentcard).activetextobject == nil)) { /*DW 2/15/95*/
00367             
00368             if ((**hobj).objecttype == edittexttype) {
00369             
00370                 hdlcard oldiowadata = iowadata;
00371             
00372                 iowadata = currentcard;
00373             
00374                 setactivetextobject (hobj);
00375             
00376                 iowadata = oldiowadata;
00377                 }
00378             }
00379         
00380         return (true);
00381         }
00382     
00383     return (false);
00384     } /*setcardenable*/
00385     
00386     
00387 static boolean disablevisit (hdlobject h) {
00388     
00389     if ((**h).objectenabled != flglobal) {
00390     
00391         (**h).objectenabled = flglobal;
00392     
00393         (**h).objectinval = true;
00394         }
00395         
00396     return (true);
00397     } /*disablevisit*/
00398     
00399     
00400 boolean enableallcardobjects (boolean flenabled) {
00401     
00402     /*
00403     should go thru the component interface. DW 9/12/93
00404     */
00405     
00406     flglobal = flenabled;
00407     
00408     visitobjects ((**currentcard).objectlist, &disablevisit);
00409     
00410     (**currentcard).needsupdate = true;
00411     
00412     return (true);
00413     } /*enableallcardobjects*/
00414     
00415     
00416 boolean setcardpopup (bigstring name, bigstring displaystring, Handle semicolonstring, short checkeditem) {
00417     
00418     hdlobject hobj;
00419     hdlpopupdata hp;
00420     
00421     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00422         return (false);
00423             
00424     hp = (hdlpopupdata) (**hobj).objectdata;
00425         
00426     disposehandle ((**hp).hmenuitems);
00427     
00428     (**hp).hmenuitems = semicolonstring;
00429     
00430     copystring (displaystring, (**hp).bspopup);
00431     
00432     (**hp).checkeditem = checkeditem;
00433     
00434     return (true);
00435     } /*setcardpopup*/
00436     
00437     
00438 static boolean getnthpopupitem (hdlobject h, short n, bigstring bs) {
00439     
00440     /*
00441     get the nth string from the popup menu object. it's a bit slower to load
00442     up the menu using calls to this guy, but it's simpler, and it's nice to
00443     have this mess confined to one routine.
00444     
00445     n is 1-based.
00446     */
00447     
00448     hdlpopupdata hdata = (hdlpopupdata) (**h).objectdata;
00449     Handle htext = (**hdata).hmenuitems;
00450     short i;
00451     short ctchars;
00452     short itemnum = 1;
00453     
00454     ctchars = GetHandleSize (htext);
00455     
00456     setstringlength (bs, 0);
00457         
00458     for (i = 0; i < ctchars; i++) {
00459         
00460         char ch = (*htext) [i];
00461         
00462         if (ch == ';') {
00463             
00464             if (itemnum == n)
00465                 return (true);
00466                 
00467             itemnum++;
00468             
00469             setstringlength (bs, 0);
00470             }
00471         else
00472             pushchar (ch, bs);
00473         } /*for*/
00474     
00475     return ((itemnum == n) && (stringlength (bs) > 0));
00476     } /*getnthpopupitem*/
00477     
00478         
00479 boolean setcardpopupcheckeditem (bigstring name, short checkeditem) {
00480 
00481     hdlobject hobj;
00482     hdlpopupdata hp;
00483 
00484     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00485         return (false);
00486             
00487     hp = (hdlpopupdata) (**hobj).objectdata;
00488     
00489     (**hp).checkeditem = checkeditem;
00490     
00491     getnthpopupitem (hobj, checkeditem, (**hp).bspopup);
00492     
00493     invalobjecthandle (hobj);
00494     
00495     return (true);
00496     } /*setcardpopupcheckeditem*/
00497     
00498     
00499 boolean getcardpopupstring (bigstring name, bigstring popupstring) {
00500 
00501     hdlobject hobj;
00502     hdlpopupdata hp;
00503 
00504     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00505         return (false);
00506             
00507     hp = (hdlpopupdata) (**hobj).objectdata;
00508     
00509     copystring ((**hp).bspopup, popupstring);
00510     
00511     return (true);
00512     } /*getcardpopupstring*/
00513     
00514     
00515 boolean setcardpopupfrommenu (bigstring name, MenuHandle hmenu, short checkeditem) {
00516     
00517     short ct = countmenuitems (hmenu), i;
00518     Handle semicolonstring;
00519     bigstring bsdisplay;
00520     
00521     setstringlength (bsdisplay, 0);
00522     
00523     newclearhandle (0, &semicolonstring);
00524     
00525     for (i = 1; i <= ct; i++) {
00526         
00527         bigstring bs;
00528         
00529         getmenuitem (hmenu, i, bs);
00530         
00531         if (i == checkeditem)
00532             copystring (bs, bsdisplay);
00533             
00534         pushchar (';', bs);
00535         
00536         pushtexthandle (bs, semicolonstring);
00537         } /*for*/
00538         
00539     return (setcardpopup (name, bsdisplay, semicolonstring, checkeditem));
00540     } /*setcardpopupfrommenu*/
00541     
00542     
00543 typedef struct tysetcardpopupfromfolderrecord {
00544     
00545     Handle hsemistring;
00546     
00547     short checkeditem;
00548     
00549     bigstring bsdisplay;
00550     
00551     bigstring fnamechecked;
00552     
00553     short ix;
00554     } tysetcardpopupfromfolderrecord;
00555     
00556     
00557 static boolean setpopupfoldervisit (bigstring fname, tyfileinfo *info, long refcon) {
00558     
00559     tysetcardpopupfromfolderrecord *rec = (tysetcardpopupfromfolderrecord *) refcon;
00560     
00561     if (!pushtexthandle (fname, (*rec).hsemistring))
00562         return (false);
00563         
00564     if (!pushtexthandle ("\p;", (*rec).hsemistring))
00565         return (false);
00566     
00567     if (unicaseequalstrings (fname, (*rec).fnamechecked)) {
00568         
00569         copystring (fname, (*rec).bsdisplay);
00570         
00571         (*rec).checkeditem = (*rec).ix;
00572         }
00573         
00574     (*rec).ix++;
00575         
00576     return (true);
00577     } /*setpopupfoldervisit*/
00578 
00579 
00580 boolean setcardpopupfromfolder (bigstring name, ptrfilespec pfsfolder, bigstring fnamechecked) {
00581 
00582     tysetcardpopupfromfolderrecord rec; 
00583     
00584     if (!newtexthandle ("\p", &rec.hsemistring))
00585         return (false);
00586         
00587     copystring (fnamechecked, rec.fnamechecked);
00588     
00589     rec.checkeditem = 1; /*default, in case there's no match*/
00590     
00591     if (!folderloop (pfsfolder, false, &setpopupfoldervisit, (long) &rec)) {
00592         
00593         disposehandle (rec.hsemistring);
00594         
00595         return (false);
00596         }
00597         
00598     return (setcardpopup (name, rec.bsdisplay, rec.hsemistring, rec.checkeditem));
00599     } /*setcardpopupfromfolder*/
00600     
00601     
00602 boolean setcardicon (bigstring name, short align, short ixlabel, Handle iconsuite, tyiconclickcallback iconclick) {
00603     
00604     /*
00605     allows you to set the customizable features of an IOA icon object. if iconsuite
00606     is nil, no problem, then the component uses the resnum to get the icon.
00607     */
00608     
00609     hdlobject hobj;
00610     hdlicondata hdata;
00611     
00612     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00613         return (false);
00614             
00615     hdata = (hdlicondata) (**hobj).objectdata;
00616     
00617     (**hdata).align = align;
00618     
00619     (**hdata).ixlabel = ixlabel;
00620     
00621     (**hdata).iconsuite = iconsuite;
00622     
00623     (**hdata).iconclick = iconclick;
00624     
00625     invalobjecthandle (hobj);
00626     
00627     return (true);
00628     } /*setcardicon*/
00629     
00630     
00631 boolean setcardcolorpopup (bigstring name, RGBColor *rgb) {
00632     
00633     hdlobject hobj;
00634     hdlcolordata hdata;
00635     
00636     if (!getObjectHandle ((hdlcard) currentcard, name, &hobj))
00637         return (false);
00638             
00639     hdata = (hdlcolordata) (**hobj).objectdata;
00640     
00641     (**hdata).rgb = *rgb;
00642     
00643     invalobjecthandle (hobj);
00644     
00645     return (true);
00646     } /*setcardcolorpopup*/
00647     
00648     
00649 short getfontsizepopup (bigstring name) {
00650     
00651     return (fontsizemap [getcardpopup (name) - 1]);
00652     } /*getfontsizepopup*/
00653     
00654     
00655 void setfontsizepopup (bigstring name, short size) {
00656     
00657     short ix = 1, i;
00658     
00659     for (i = 0; i < sizeof (fontsizemap); i++) {
00660     
00661         if (size == fontsizemap [i]) {
00662             
00663             ix = i;
00664             
00665             break;
00666             }
00667         } /*for*/
00668         
00669     setcardpopupcheckeditem (name, ix + 1);
00670     } /*setfontsizepopup*/
00671     
00672     
00673 void setfontpopup (bigstring name, diskfontstring fontname) {
00674     
00675     short ct = countmenuitems (hdlfontmenu), i;
00676     bigstring bsfontname;
00677     
00678     copystring (fontname, bsfontname);
00679     
00680     for (i = 1; i <= ct; i++) {
00681         
00682         bigstring bs;
00683         
00684         getmenuitem (hdlfontmenu, i, bs);
00685         
00686         if (fastunicaseequalstrings (bsfontname, bs)) {
00687         
00688             setcardpopupcheckeditem (name, i);
00689             
00690             return;
00691             }
00692         } /*for*/
00693     } /*setfontpopup*/
00694     
00695     
00696 void getfontpopup (bigstring name, diskfontstring fontname) {
00697     
00698     bigstring bs;
00699     
00700     getmenuitem (hdlfontmenu, getcardpopup (name), bs);
00701     
00702     copystring (bs, fontname);
00703     } /*getfontpopup*/
00704     
00705     
00706 void updatecard (void) {
00707     
00708     /*
00709     the filter routine has changed the value of some object, but isn't ready
00710     to return yet (for example, th progress message in the find command).
00711     */
00712     
00713     updateCard (currentcard);
00714     } /*updatecard*/
00715     
00716     
00717 boolean getcardnumber (bigstring name, long *num) {
00718     
00719     bigstring bs;
00720     boolean flerror;
00721     
00722     if (!getcardstring (name, bs))
00723         return (false);
00724     
00725     stringtonumber (bs, num, &flerror);
00726     
00727     return (!flerror);
00728     } /*getcardnumber*/
00729     
00730 
00731 boolean getcardshort (bigstring name, short *num) {
00732     
00733     long x;
00734     
00735     if (!getcardnumber (name, &x))
00736         return (false);
00737         
00738     *num = (short) x;
00739     
00740     return (true);
00741     } /*getcardshort*/
00742     
00743     
00744 boolean setcardnumber (bigstring name, long num) {
00745     
00746     bigstring bs;
00747     
00748     NumToString (num, bs);
00749     
00750     return (setcardstring (name, bs));
00751     } /*setcardnumber*/
00752     
00753         
00754 boolean setcardtexthandle (bigstring name, Handle hvalue) {
00755     
00756     Handle h;
00757     
00758     if (!copyhandle (hvalue, &h))
00759         return (false);
00760         
00761     return (setObjectValue (currentcard, name, h));
00762     } /*setcardtexthandle*/
00763     
00764 
00765 boolean replacecardtexthandle (bigstring name, Handle *hvalue) {
00766     
00767     /*
00768     a special entrypoint for Card Editor -- hvalue already contains
00769     a value, we replace it only if the value changed.
00770     */
00771     
00772     Handle hnewvalue;
00773     
00774     if (!getObjectValue (currentcard, name, &hnewvalue))
00775         return (false);
00776         
00777     if (equalhandles (hnewvalue, *hvalue)) 
00778         return (true);
00779     
00780     disposehandle (*hvalue);
00781     
00782     return (copyhandle (hnewvalue, hvalue));
00783     } /*replacecardtexthandle*/
00784     
00785     
00786 boolean getcardtexthandle (bigstring name, Handle *hvalue) {
00787     
00788     Handle hnewvalue;
00789     
00790     disposehandle (*hvalue); /*DW 9/20/95, does nothing if it's nil, assume all handles are init'd to nil*/
00791     
00792     *hvalue = nil;
00793     
00794     if (!getObjectValue (currentcard, name, &hnewvalue))
00795         return (false);
00796         
00797     return (copyhandle (hnewvalue, hvalue));
00798     } /*getcardtexthandle*/
00799     
00800     
00801 boolean setcardrect (bigstring name, Rect r) {
00802     
00803     bigstring bs;
00804     
00805     setstringlength (bs, 0);
00806     
00807     pushlong (r.top, bs); pushchar (',', bs);
00808     
00809     pushlong (r.left, bs); pushchar (',', bs);
00810     
00811     pushlong (r.bottom, bs); pushchar (',', bs);
00812     
00813     pushlong (r.right, bs); 
00814     
00815     return (setcardstring (name, bs));
00816     } /*setcardrect*/
00817     
00818     
00819 boolean getcardrect (bigstring name, Rect *r) {
00820     
00821     bigstring bs;
00822     long nums [4];
00823     short ixnums = 0;
00824     short i;
00825     
00826     if (!getcardstring (name, bs))
00827         return (false);
00828         
00829     for (i = 1; i <= 4; i++) {
00830         
00831         bigstring bsnum;
00832         
00833         setstringlength (bsnum, 0);
00834         
00835         while (true) {
00836             
00837             char ch;
00838             
00839             if (stringlength (bs) == 0)
00840                 break;
00841                 
00842             ch = bs [1];
00843                 
00844             deletestring (bs, 1, 1);
00845             
00846             if (ch == ',')
00847                 break;
00848                 
00849             pushchar (ch, bsnum);
00850             } /*while*/
00851             
00852         StringToNum (bsnum, &nums [ixnums++]);
00853         } /*for*/
00854         
00855     if (ixnums != 4)
00856         return (false);
00857     
00858     (*r).top = nums [0];
00859     
00860     (*r).left = nums [1];
00861     
00862     (*r).bottom = nums [2];
00863     
00864     (*r).right = nums [3];
00865     
00866     return (true);
00867     } /*getcardrect*/
00868     
00869     
00870 boolean setcarddate (bigstring name, tydaterecord date) {
00871     
00872     bigstring bs;
00873     
00874     appletdatetostring (date, bs);
00875     
00876     return (setcardstring (name, bs));
00877     } /*setcarddate*/
00878     
00879     
00880 boolean getcarddate (bigstring name, tydaterecord *date) {
00881     
00882     bigstring bs;
00883     
00884     if (!getcardstring (name, bs))
00885         return (false);
00886     
00887     return (stringtoappletdate (bs, date));
00888     } /*getcarddate*/
00889     
00890     
00891 static short getindex (short resnum) {
00892     
00893     short ix = resnum - 128;
00894     
00895     assert (ix < ctdialogs); /*need to increase array size or bad resnum*/
00896         
00897     return (ix);
00898     } /*getindex*/
00899     
00900     
00901 static void getdialoginfo (short resnum, tydialoginfo *info) {
00902     
00903     *info = appdialoginfo [getindex (resnum)];
00904     } /*getdialoginfo*/
00905     
00906     
00907 static void setdialoginfo (short resnum, tydialoginfo *info) {
00908     
00909     appdialoginfo [getindex (resnum)] = *info;
00910     } /*setdialoginfo*/
00911     
00912     
00913 void appcarddefaulteventhandler (EventRecord *ev) {
00914     
00915     /*
00916     a basic event handler for modal cards, scripted or otherwise.
00917     
00918     only pass back events to the Applet Toolkit main event loop
00919     that it has a right to be interested in when a modal card is
00920     in front of all its windows.
00921     */
00922     
00923     switch ((*ev).what) {
00924         
00925         case updateEvt: case activateEvt: case osEvt: case diskEvt:
00926             appleteventhandler (ev);
00927             
00928             break;
00929         } /*switch*/
00930     } /*appcarddefaulteventhandler*/
00931     
00932 
00933 void appscriptedmodalcardfilter (EventRecord *ev) {
00934     
00935     /*
00936     a basic filter routine for a scripted modal card.
00937     
00938     at least a couple of place need exactly this filter,
00939     so it made sense to put it here so they don't have
00940     to re-invent the wheel.
00941     */
00942     
00943     switch ((*ev).what) {
00944         
00945         case iowaButtonHitEvent:
00946             (*ev).what = iowaRunScriptEvent;
00947             
00948             break;
00949             
00950         default:
00951             appcarddefaulteventhandler (ev);
00952             
00953             break;
00954         } /*switch*/
00955     } /*appscriptedmodalcardfilter*/
00956     
00957 
00958 static boolean getcardresource (short id, Handle *hpackedcard) {
00959     
00960     Handle h;
00961     
00962     h = GetResource ('CARD', id);
00963     
00964     if (h == nil)
00965         return (false);
00966     
00967     DetachResource (h);
00968     
00969     *hpackedcard = h;
00970     
00971     return (true);
00972     } /*getcardresource*/
00973     
00974     
00975 void appopencardresource (short id, tycardeventcallback filter) {
00976     
00977     Handle hpackedcard;
00978     tydialoginfo info;
00979     
00980     apppostcallback (); 
00981     
00982     getdialoginfo (id, &info);
00983     
00984     if (getcardresource (id, &hpackedcard)) 
00985         runModelessCard (hpackedcard, false, info.top, info.left, filter);
00986 
00987     appprecallback ();
00988     } /*appopencardresource*/
00989     
00990 
00991 void apprunmodalresource (short id, tycardeventcallback filter) {
00992     
00993     Handle hpackedcard;
00994     tydialoginfo info;
00995     
00996     dialogmenuenabler (true); /*disable all menus but the Edit menu*/
00997     
00998     getdialoginfo (id, &info);
00999     
01000     if (getcardresource (id, &hpackedcard)) 
01001         runModalCard (hpackedcard, false, info.top, info.left, filter);
01002     
01003     dialogmenuenabler (false);
01004     } /*apprunmodalresource*/
01005     
01006     
01007 void appsavedialoginfo (short id) {
01008 
01009     WindowPtr w = (**currentcard).drawwindow;
01010     Rect r = (*w).portRect;
01011     tydialoginfo info;
01012     
01013     pushmacport (w);
01014     
01015     localtoglobalrect (&r);
01016     
01017     popmacport ();
01018     
01019     info.top = r.top;
01020     
01021     info.left = r.left;
01022     
01023     setdialoginfo (id, &info);
01024     } /*appsavedialoginfo*/
01025     
01026 
01027 void appcardtofront (hdlcard hcard) {
01028     
01029     SelectWindow ((**hcard).drawwindow);
01030     } /*appcardtofront*/
01031     
01032     
01033     

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