appletcard.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletcard.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 "appletmain.h"
00010 #include "appletwires.h"
00011 #include "appletcardops.h"
00012 #include "appletcard.h"
00013 
00014 
00015 #define infocardid 157
00016 #define twowaycardid 158
00017 #define threewaycardid 159
00018 #define alertcardid 160
00019 #define askcardid 161
00020 #define passwordcardid 173
00021 
00022 
00023 static boolean alertshowing = false;
00024 
00025 static Handle dialogstring1, dialogstring2, dialogstring3, dialogstring4;
00026 
00027 static boolean flconfirmed; /*for confirm dialog*/
00028 
00029 static short threewayvalue; /*for threeway dialog*/
00030 
00031 
00032 /*
00033 flag to control whether the user is interacting, or we're responding to an
00034 interapplication message. the error string is saved -- to be accessed by the
00035 GetErrorString verb.
00036 */
00037     boolean fldialogsenabled = true;
00038     bigstring bsalertstring;
00039     
00040 
00041 
00042 
00043 static void alertfilter (EventRecord *ev) {
00044     
00045     switch ((*ev).what) {
00046         
00047         case iowaInitEvent: 
00048             setObjectValue ((hdlcard) (*ev).message, "\pmessage", dialogstring1);
00049             
00050             break;
00051             
00052         case iowaButtonHitEvent: {
00053             hdlobject h = (hdlobject) (*ev).message;
00054         
00055             currentcard = (hdlcard) (**h).owningcard;
00056                 
00057             appsavedialoginfo (alertcardid); /*remember window position*/
00058             
00059             (*ev).what = iowaCloseEvent;
00060             
00061             break;
00062             }
00063             
00064         default:
00065             appcarddefaulteventhandler (ev);
00066             
00067             break;
00068         } /*switch*/
00069     } /*alertfilter*/
00070      
00071 
00072 boolean alertdialog (bigstring bs) {
00073     
00074     if (alertshowing) /*don't allow alerts to nest, only the first error displays*/
00075         return (false);
00076         
00077     copystring (bs, bsalertstring);
00078     
00079     if (!fldialogsenabled)
00080         return (true);
00081         
00082     newtexthandle (bs, &dialogstring1);
00083     
00084     alertshowing = true;
00085             
00086     sysbeep;
00087     
00088     apprunmodalresource (alertcardid, &alertfilter);
00089     
00090     #ifdef fldebug
00091     
00092         if (optionkeydown ())
00093             DebugStr ("\pHello!");
00094             
00095     #endif
00096     
00097     alertshowing = false;
00098     
00099     return (true);
00100     } /*alertdialog*/
00101     
00102 
00103 boolean infodialog (bigstring bs) {
00104     
00105     copystring (bs, bsalertstring);
00106     
00107     if (!fldialogsenabled)
00108         return (true);
00109         
00110     newtexthandle (bs, &dialogstring1);
00111     
00112     apprunmodalresource (infocardid, &alertfilter);
00113     
00114     return (true);
00115     } /*infodialog*/
00116     
00117 
00118 static void twowayfilter (EventRecord *ev) {
00119     
00120     switch ((*ev).what) {
00121         
00122         case iowaInitEvent: 
00123             setObjectValue ((hdlcard) (*ev).message, "\pmessage", dialogstring1);
00124             
00125             setObjectValue ((hdlcard) (*ev).message, "\pdefaultButton", dialogstring2);
00126             
00127             setObjectValue ((hdlcard) (*ev).message, "\potherButton", dialogstring3);
00128             
00129             break;
00130             
00131         case iowaButtonHitEvent: {
00132             hdlobject h = (hdlobject) (*ev).message;
00133             bigstring bs;
00134             
00135             getobjectnamestring (h, bs);
00136             
00137             flconfirmed = equalstrings (bs, "\pdefaultButton");
00138             
00139             currentcard = (hdlcard) (**h).owningcard;
00140                 
00141             appsavedialoginfo (twowaycardid); /*remember window position*/
00142             
00143             (*ev).what = iowaCloseEvent; /*either button closes the dialog*/
00144             
00145             break;
00146             }
00147             
00148         default:
00149             appcarddefaulteventhandler (ev);
00150             
00151             break;
00152         } /*switch*/
00153     } /*twowayfilter*/
00154     
00155     
00156 boolean twowaydialog (bigstring bsprompt, bigstring defaultbutton, bigstring otherbutton) {
00157     
00158     copystring (bsprompt, bsalertstring);
00159     
00160     if (!fldialogsenabled)
00161         return (true);
00162         
00163     newtexthandle (bsprompt, &dialogstring1);
00164             
00165     newtexthandle (defaultbutton, &dialogstring2);
00166             
00167     newtexthandle (otherbutton, &dialogstring3);
00168             
00169     apprunmodalresource (twowaycardid, &twowayfilter);
00170     
00171     return (flconfirmed);
00172     } /*twowaydialog*/
00173     
00174     
00175 boolean confirmdialog (bigstring bs) {
00176     
00177     return (twowaydialog (bs, "\pOK", "\pCancel"));
00178     } /*confirmdialog*/
00179     
00180     
00181 boolean yesnodialog (bigstring bs) {
00182     
00183     return (twowaydialog (bs, "\pYes", "\pNo"));
00184     } /*yesnodialog*/
00185     
00186     
00187 static void threewayfilter (EventRecord *ev) {
00188     
00189     switch ((*ev).what) {
00190         
00191         case iowaInitEvent: {
00192             hdlcard context = (hdlcard) (*ev).message;
00193             
00194             setObjectValue (context, "\pmessage", dialogstring1);
00195             
00196             setObjectValue (context, "\pleftButton", dialogstring2);
00197             
00198             setObjectValue (context, "\pmidButton", dialogstring3);
00199             
00200             setObjectValue (context, "\prightButton", dialogstring4);
00201             
00202             break;
00203             }
00204             
00205         case iowaButtonHitEvent: {
00206             hdlobject h = (hdlobject) (*ev).message;
00207             bigstring bs;
00208             
00209             getobjectnamestring (h, bs);
00210             
00211             if (equalstrings (bs, "\pleftButton"))
00212                 threewayvalue = 3;
00213             
00214             if (equalstrings (bs, "\pmidButton"))
00215                 threewayvalue = 2;
00216             
00217             if (equalstrings (bs, "\prightButton"))
00218                 threewayvalue = 1;
00219             
00220             currentcard = (hdlcard) (**h).owningcard;
00221                 
00222             appsavedialoginfo (threewaycardid); /*remember window position*/
00223             
00224             (*ev).what = iowaCloseEvent; /*either button closes the dialog*/
00225             
00226             break;
00227             }
00228             
00229         default:
00230             appcarddefaulteventhandler (ev);
00231             
00232             break;
00233         } /*switch*/
00234     } /*threewayfilter*/
00235     
00236     
00237 short threewaydialog (bigstring bsprompt, bigstring leftbutton, bigstring midbutton, bigstring rightbutton) {
00238     
00239     copystring (bsprompt, bsalertstring);
00240     
00241     if (!fldialogsenabled)
00242         return (true);
00243         
00244     newtexthandle (bsprompt, &dialogstring1);
00245             
00246     newtexthandle (leftbutton, &dialogstring2);
00247             
00248     newtexthandle (midbutton, &dialogstring3);
00249             
00250     newtexthandle (rightbutton, &dialogstring4);
00251             
00252     apprunmodalresource (threewaycardid, &threewayfilter);
00253     
00254     return (threewayvalue);
00255     } /*threewaydialog*/
00256     
00257     
00258 static void askfilter (EventRecord *ev) {
00259     
00260     switch ((*ev).what) {
00261         
00262         case iowaInitEvent: 
00263             setObjectValue ((hdlcard) (*ev).message, "\pmessage", dialogstring1);
00264             
00265             setObjectValue ((hdlcard) (*ev).message, "\panswer", dialogstring2);
00266             
00267             break;
00268             
00269         case iowaButtonHitEvent: {
00270             hdlobject hobject = (hdlobject) (*ev).message;
00271             bigstring bs;
00272             
00273             getobjectnamestring (hobject, bs);
00274             
00275             if (equalstrings (bs, "\pokButton")) {
00276                 
00277                 Handle hvalue;
00278                 
00279                 flconfirmed = true;
00280                 
00281                 getObjectValue ((hdlcard) (**hobject).owningcard, "\panswer", &hvalue);
00282                 
00283                 copyhandle (hvalue, &dialogstring2);
00284                 }
00285             else {
00286                 flconfirmed = false;
00287                 
00288                 dialogstring2 = nil;
00289                 }
00290             
00291             currentcard = (hdlcard) (**hobject).owningcard;
00292                 
00293             appsavedialoginfo (askcardid); /*remember window position*/
00294             
00295             (*ev).what = iowaCloseEvent; /*either button closes the dialog*/
00296             
00297             break;
00298             }
00299             
00300         default:
00301             appcarddefaulteventhandler (ev);
00302             
00303             break;
00304         } /*switch*/
00305     } /*askfilter*/
00306     
00307     
00308 static boolean onestringdialog (short id, bigstring prompt, bigstring answer) {
00309     
00310     copystring (prompt, bsalertstring);
00311     
00312     if (!fldialogsenabled)
00313         return (true);
00314         
00315     newtexthandle (prompt, &dialogstring1);
00316             
00317     newtexthandle (answer, &dialogstring2);
00318             
00319     apprunmodalresource (id, &askfilter);
00320     
00321     texthandletostring (dialogstring2, answer);
00322     
00323     disposehandle (dialogstring2);
00324     
00325     return (flconfirmed);
00326     } /*onestringdialog*/
00327 
00328 
00329 boolean askdialog (bigstring prompt, bigstring answer) {
00330     
00331     return (onestringdialog (askcardid, prompt, answer));
00332     } /*askdialog*/
00333 
00334 
00335 boolean passworddialog (bigstring prompt, bigstring answer) {
00336     
00337     return (onestringdialog (passwordcardid, prompt, answer));
00338     } /*passworddialog*/
00339 
00340 
00341 static void replaceexistingfilter (EventRecord *ev) {
00342     
00343     switch ((*ev).what) {
00344         
00345         case iowaInitEvent: 
00346             setObjectValue ((hdlcard) (*ev).message, "\pprompt", dialogstring1);
00347             
00348             break;
00349             
00350         case iowaButtonHitEvent: {
00351             hdlobject h = (hdlobject) (*ev).message;
00352             bigstring bs;
00353             
00354             getobjectnamestring (h, bs);
00355             
00356             flconfirmed = equalstrings (bs, "\preplace");
00357             
00358             currentcard = (hdlcard) (**h).owningcard;
00359                 
00360             appsavedialoginfo (150); /*remember window position*/
00361             
00362             (*ev).what = iowaCloseEvent; /*either button closes the dialog*/
00363             
00364             break;
00365             }
00366             
00367         default:
00368             appcarddefaulteventhandler (ev);
00369             
00370             break;
00371         } /*switch*/
00372     } /*replaceexistingfilter*/
00373     
00374     
00375 boolean replaceexistingdialog (bigstring fname) {
00376     
00377     bigstring bs;
00378     short top, left;
00379     
00380     if (!fldialogsenabled)
00381         return (true);
00382     
00383     copystring ("\pReplace existing ", bs);
00384     
00385     pushstring (fname, bs);
00386     
00387     pushstring ("\p?", bs);
00388     
00389     newtexthandle (bs, &dialogstring1);
00390     
00391     /*position of this dialog is relative to the position of the front window*/ {
00392     
00393         WindowPtr w = FrontWindow ();
00394         Rect r;
00395         
00396         r = (*w).portRect;
00397         
00398         pushmacport (w);
00399                 
00400         localtoglobalrect (&r);
00401                 
00402         popmacport ();
00403         
00404         top = r.top + 32;
00405         
00406         left = r.left + 32;
00407         }
00408             
00409     apprunmodalresource (150, &replaceexistingfilter);
00410     
00411     return (flconfirmed);
00412     } /*replaceexistingdialog*/
00413     
00414     
00415     

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