pictverbs.c

Go to the documentation of this file.
00001 
00002 /*  $Id: pictverbs.c 1209 2006-04-05 23:59:59Z karstenw $    */
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 "memory.h"
00032 #include "ops.h"
00033 #include "quickdraw.h"
00034 #include "resources.h"
00035 #include "scrap.h"
00036 #include "search.h"
00037 #include "strings.h"
00038 #include "shell.h"
00039 #include "shellprint.h"
00040 #include "shellundo.h"
00041 #include "shell.rsrc.h"
00042 #include "lang.h"
00043 #include "langexternal.h"
00044 #include "tablestructure.h"
00045 #include "cancoon.h"
00046 #include "pict.h"
00047 #include "pictverbs.h"
00048 #include "kernelverbdefs.h"
00049 
00050 
00051 
00052 
00053 #define picterrorlist 267
00054 #define nopicterror 1
00055 #define namenotpicterror 2
00056 
00057 
00058 
00059 typedef enum typicttoken { /*verbs that are processed by pict.c*/
00060     
00061     scheduleupdatefunc,
00062     
00063     evalfunc,
00064     
00065     getpicturefunc,
00066     
00067     setpicturefunc,
00068     
00069     /*
00070     getboundsfunc,
00071     */
00072     
00073     ctpictverbs
00074     } typicttoken;
00075 
00076 #if langexternalfind_optimization
00077 
00078     typedef tyexternalvariable typictvariable, *ptrpictvariable, **hdlpictvariable;
00079 
00080 #else
00081     
00082     typedef struct typictvariable {
00083         
00084         unsigned short id; /*tyexternalid: managed by langexternal.c*/
00085         
00086         unsigned short flinmemory: 1; /*if true, variabledata is an hdlwprecord, else a dbaddress*/
00087         
00088         unsigned short flmayaffectdisplay: 1; /*not in memory, but being displayed in a table window*/
00089         
00090         long variabledata; /*either a hdlpictrecord or a dbaddress*/
00091         
00092         hdldatabaserecord hdatabase; // 5.0a18 dmb
00093 
00094         dbaddress oldaddress; /*last place this pict was stored in db*/
00095         } typictvariable, *ptrpictvariable, **hdlpictvariable;
00096 
00097 #endif
00098 
00099 static short errornum = 0;
00100 
00101 
00102 
00103 static boolean newpictvariable (boolean flinmemory, long variabledata, hdlpictvariable *h) {
00104 
00105     return (langnewexternalvariable (flinmemory, variabledata, (hdlexternalvariable *) h));
00106     } /*newpictvariable*/
00107     
00108 
00109 boolean pictverbgettypestring (hdlexternalvariable hvariable, bigstring bs) {
00110 #pragma unused (hvariable)
00111     getstringlist (pictstringlist, picttypestring, bs);
00112     
00113     return (true);
00114     } /*pictverbgettypestring*/
00115 
00116 
00117 static boolean pictdisposevariable (hdlexternalvariable hvariable, boolean fldisk) {
00118 #pragma unused (fldisk)
00119 
00120     return (pictdisposerecord ((hdlpictrecord) (**hvariable).variabledata));
00121     } /*pictdisposevariable*/
00122 
00123 
00124 boolean pictverbdispose (hdlexternalvariable hvariable, boolean fldisk) {
00125     
00126     return (langexternaldisposevariable (hvariable, fldisk, &pictdisposevariable));
00127     } /*pictverbdispose*/
00128 
00129 
00130 boolean pictverbnew (Handle hdata, hdlexternalvariable *hvariable) {
00131     
00132     /*
00133     9/6/91: now takes hdata parameter, but it isn't used yet.  it is 
00134     intended to potentially contain a picture from which to create the 
00135     new variable
00136     */
00137     
00138     register hdlpictrecord hp;
00139     register hdlpictvariable hv;
00140     
00141     if (!pictnewrecord ())
00142         return (false);
00143     
00144     hp = pictdata; /*copy into register*/
00145     
00146     if (!newpictvariable (true, (long) hp, (hdlpictvariable *) hvariable)) {
00147         
00148         pictdisposerecord (hp);
00149         
00150         return (false);
00151         }
00152     
00153     hv = (hdlpictvariable) *hvariable; /*copy into register*/
00154     
00155     if (hdata != nil) { /*we've been given a picture to copy as initial data*/
00156         
00157         if (!copyhandle (hdata, &hdata)) {
00158             
00159             pictdisposerecord (hp);
00160             
00161             disposehandle ((Handle) hv);
00162             
00163             return (false);
00164             }
00165         
00166         (**hp).macpicture = (PicHandle) hdata;
00167         }
00168     
00169     (**hv).variabledata = (long) hp; /*link the pict rec into the variable rec*/
00170     
00171     (**hp).pictrefcon = (long) hv; /*the pointing is mutual*/
00172     
00173     return (true);
00174     } /*pictverbnew*/
00175 
00176 
00177 #if !flruntime
00178 
00179 static void pictverbcheckwindowrect (hdlpictrecord hpict) {
00180     
00181     register hdlpictrecord hp = hpict;
00182     hdlwindowinfo hinfo;
00183         
00184     if ((**hp).flwindowopen) { /*make windowrect reflect current window size & position*/
00185         
00186         if (shellfinddatawindow ((Handle) hp, &hinfo)) {
00187             
00188             Rect r;
00189             
00190             shellgetglobalwindowrect (hinfo, &r);
00191             
00192             if (!equalrects (r, (**hp).windowrect)) {
00193             
00194                 (**hp).windowrect = r;
00195                 
00196                 (**hp).fldirty = true;
00197                 }
00198             }
00199         }
00200     } /*pictverbcheckwindowrect*/
00201     
00202 #else
00203 
00204     #define pictverbcheckwindowrect(hpict)  ((void *) 0)
00205     
00206     #define fldatabasesaveas 0
00207 
00208 #endif
00209 
00210 
00211 static boolean pictverbinmemory (hdlpictvariable hv) {
00212 
00213     /*
00214     5.0a18 dmb: support database linking
00215     */
00216     
00217     register boolean fl;
00218     dbaddress adr;
00219     Handle hpackedpict;
00220     long ix = 0;
00221     hdlpictrecord hpict;
00222     
00223     if ((**hv).flinmemory) /*nothing to do, it's already in memory*/
00224         return (true);
00225     
00226     dbpushdatabase ((**hv).hdatabase);
00227 
00228     adr = (dbaddress) (**hv).variabledata;
00229     
00230     fl = dbrefhandle (adr, &hpackedpict);
00231     
00232     if (fl) {
00233         
00234         fl = pictunpack (hpackedpict, &ix, &hpict);
00235         
00236         disposehandle (hpackedpict);
00237         }
00238 
00239     dbpopdatabase ();
00240     
00241     if (!fl) 
00242         return (false);
00243     
00244     (**hv).flinmemory = true;
00245     
00246     (**hv).variabledata = (long) hpict; /*link into variable structure*/
00247     
00248     (**hv).oldaddress = adr; /*last place this pict was stored*/
00249     
00250     (**hpict).pictrefcon = (long) hv; /*we can get from pict rec to variable rec*/
00251     
00252     return (true);
00253     } /*pictverbinmemory*/
00254 
00255 
00256 boolean pictverbmemorypack (hdlexternalvariable h, Handle *hpacked) {
00257     
00258     /*
00259     a special entrypoint for the language's pack and upack verbs.
00260     */
00261     
00262     register hdlpictvariable hv = (hdlpictvariable) h;
00263     register hdlpictrecord hp;
00264     register boolean fl;
00265     Handle hpush = nil;
00266     
00267     if (!(**hv).flinmemory) {
00268     
00269         if (!langexternalrefdata ((hdlexternalvariable) hv, &hpush))
00270             return (false);
00271         
00272         goto pushandexit;
00273         }
00274     
00275     hp = (hdlpictrecord) (**hv).variabledata;
00276     
00277     pictverbcheckwindowrect (hp);
00278     
00279     if (!pictpack (hp, &hpush))
00280         return (false);
00281     
00282     pushandexit:
00283     
00284     if (hpush == nil)
00285         return (false);
00286     
00287     fl = pushhandle (hpush, *hpacked);
00288     
00289     disposehandle (hpush);
00290     
00291     return (fl);
00292     } /*pictverbmemorypack*/
00293 
00294 
00295 boolean pictverbmemoryunpack (Handle hpacked, long *ixload, hdlexternalvariable *h) {
00296     
00297     /*
00298     this is a special entrypoint for the pack and unpack verbs.
00299     
00300     12/14/90 dmb: must create verb in memory -- see comment in opverbmemoryunpack
00301     */
00302     
00303     Handle hpackedpict;
00304     hdlpictrecord hpict;
00305     register boolean fl;
00306     long ix = 0;
00307     
00308     if (!loadhandleremains (*ixload, hpacked, &hpackedpict))
00309         return (false);
00310     
00311     /*
00312     fl = dballochandle (hpackedpict, &adr);
00313     */
00314     
00315     fl = pictunpack (hpackedpict, &ix, &hpict);
00316     
00317     disposehandle (hpackedpict);
00318     
00319     if (!fl)
00320         return (false);
00321     
00322     if (!newpictvariable (true, (long) hpict, (hdlpictvariable *) h)) {
00323         
00324         pictdisposerecord (hpict);
00325         
00326         return (false);
00327         }
00328     
00329     (**hpict).pictrefcon = (long) *h; /*we can get from pict rec to variable rec*/
00330     
00331     (**hpict).fldirty = true;
00332     
00333     return (true);
00334     } /*pictverbmemoryunpack*/
00335     
00336 
00337 boolean pictverbpack (hdlexternalvariable h, Handle *hpacked, boolean *flnewdbaddress) {
00338 
00339     /*
00340     6.2a15 AR: added flnewdbaddress parameter
00341     */
00342 
00343     register hdlpictvariable hv = (hdlpictvariable) h;
00344     register hdlpictrecord hp;
00345     register boolean fl;
00346     Handle hpackedpict;
00347     dbaddress adr;
00348     hdlwindowinfo hinfo;
00349     boolean fltempload = false;
00350     
00351     if (!(**hv).flinmemory) { /*simple case, pict is resident in the db*/
00352         
00353         if (flconvertingolddatabase) {
00354             
00355             if (!pictverbinmemory (hv))
00356                 return (false);
00357             
00358             fltempload = true;
00359             }
00360         else {
00361         
00362             adr = (dbaddress) (**hv).variabledata;
00363             
00364             if (fldatabasesaveas)
00365                 if (!dbcopy (adr, &adr))
00366                     return (false);
00367             
00368             goto pushaddress;
00369             }
00370         }
00371     
00372     hp = (hdlpictrecord) (**hv).variabledata;
00373     
00374     pictverbcheckwindowrect (hp);
00375     
00376     adr = (**hv).oldaddress; /*place where this pict used to be stored*/
00377     
00378     if (!fldatabasesaveas && !(**hp).fldirty) /*don't need to update the db version of the pict*/
00379         goto pushaddress;
00380         
00381     hpackedpict = nil; /*force a new handle to be allocated*/
00382     
00383     if (!pictpack (hp, &hpackedpict))
00384         return (false);
00385     
00386     fl = dbassignhandle (hpackedpict, &adr);
00387     
00388     disposehandle (hpackedpict);
00389     
00390     if (!fl)
00391         return (false);
00392     
00393     if (fldatabasesaveas && !fltempload)
00394         goto pushaddress;
00395     
00396     if (!pictwindowopen ((hdlexternalvariable) hv, &hinfo)) { /*it's been saved, we can reclaim some memory*/
00397         
00398         (**hv).flinmemory = false;
00399         
00400         (**hv).variabledata = adr;
00401         
00402         pictdisposerecord (hp); /*reclaim memory used by pict*/
00403         }
00404     else {
00405         
00406         (**hp).fldirty = false; /*we just saved off a new db version*/
00407         
00408         shellsetwindowchanges (hinfo, false);
00409         }
00410     
00411     pushaddress:
00412     
00413     if (!fldatabasesaveas) {
00414     
00415         *flnewdbaddress = ((**hv).oldaddress != adr);
00416             
00417         (**hv).oldaddress = adr;
00418         }
00419     else
00420         *flnewdbaddress = true; 
00421     
00422     return (pushlongondiskhandle (adr, *hpacked));
00423     } /*pictverbpack*/
00424 
00425 
00426 boolean pictverbunpack (Handle hpacked, long *ixload, hdlexternalvariable *hvariable) {
00427 
00428     dbaddress adr;
00429     
00430     if (!loadlongfromdiskhandle (hpacked, ixload, &adr)) 
00431         return (false);
00432         
00433     return (newpictvariable (false, adr, (hdlpictvariable *) hvariable));
00434     } /*pictverbunpack*/
00435 
00436 
00437 boolean pictverbpacktotext (hdlexternalvariable h, Handle htext) {
00438 #pragma unused(h)
00439 
00440     bigstring bs;
00441     
00442     getstringlist (pictstringlist, picttextstring, bs);
00443     
00444     pushchar (chreturn, bs);
00445     
00446     return (pushtexthandle (bs, htext));
00447     } /*pictverbpacktotext*/
00448 
00449 
00450 #if !flruntime
00451 
00452 boolean pictverbgetsize (hdlexternalvariable hvariable, long *size) {
00453     
00454     register hdlpictvariable hv = (hdlpictvariable) hvariable;
00455     register PicHandle macpicture;
00456     
00457     if (!pictverbinmemory (hv))
00458         return (false);
00459     
00460     macpicture = (**(hdlpictrecord) (**hv).variabledata).macpicture;
00461     
00462     *size = gethandlesize ((Handle) macpicture);
00463     
00464     return (true);
00465     } /*pictverbgetsize*/
00466 
00467 
00468 boolean pictverbgetdisplaystring (hdlexternalvariable h, bigstring bs) {
00469 #pragma unused(h)
00470 
00471     /*
00472     get string for table display.  variable is in memory
00473     */
00474     
00475     long ctbytes;
00476     
00477     if (!pictverbgetsize (h, &ctbytes))
00478         return (false);
00479     
00480     parsenumberstring (pictstringlist, pictsizestring, ctbytes, bs);
00481     
00482     /*
00483     numbertostring (ctbytes, bs);
00484     
00485     pushstring ("\p bytes", bs);
00486     */
00487     
00488     return (true);
00489     } /*pictverbgetdisplaystring*/
00490 
00491 
00492 boolean pictverbisdirty (hdlexternalvariable hvariable) {
00493     
00494     /*
00495     8/11/92 dmb: check windowrect now to ensure consistent results
00496     */
00497     
00498     register hdlpictvariable hv = (hdlpictvariable) hvariable;
00499     register hdlpictrecord hp;
00500     
00501     if (!(**hv).flinmemory)
00502         return (false);
00503     
00504     hp = (hdlpictrecord) (**hv).variabledata;
00505     
00506     pictverbcheckwindowrect (hp);
00507     
00508     return ((**hp).fldirty);
00509     } /*pictverbisdirty*/
00510 
00511 
00512 boolean pictverbsetdirty (hdlexternalvariable hvariable, boolean fldirty) {
00513     
00514     /*
00515     4/15/92 dmb: see comments in langexternalsetdirty
00516     */
00517     
00518     register hdlpictvariable hv = (hdlpictvariable) hvariable;
00519     
00520     if (!pictverbinmemory (hv))
00521         return (false);
00522     
00523     (**(hdlpictrecord) (**hv).variabledata).fldirty = fldirty;
00524     
00525     return (true);
00526     } /*pictverbsetdirty*/
00527 
00528 
00529 boolean pictverbgettimes (hdlexternalvariable h, long *timecreated, long *timemodified) {
00530     
00531     register hdlpictvariable hv = (hdlpictvariable) h;
00532     register hdlpictrecord hp;
00533     
00534     if (!pictverbinmemory (hv)) /*couldn't swap it into memory*/
00535         return (false);
00536     
00537     hp = (hdlpictrecord) (**hv).variabledata; /*assume it's in memory*/
00538     
00539     *timecreated = (**hp).timecreated;
00540     
00541     *timemodified = (**hp).timelastsave;
00542     
00543     return (true);
00544     } /*pictverbgettimes*/
00545 
00546 
00547 boolean pictverbsettimes (hdlexternalvariable h, long timecreated, long timemodified) {
00548     
00549     register hdlpictvariable hv = (hdlpictvariable) h;
00550     register hdlpictrecord hp;
00551     
00552     if (!pictverbinmemory (hv)) /*couldn't swap it into memory*/
00553         return (false);
00554     
00555     hp = (hdlpictrecord) (**hv).variabledata; /*assume it's in memory*/
00556     
00557     (**hp).timecreated = timecreated;
00558     
00559     (**hp).timelastsave = timemodified;
00560     
00561     return (true);
00562     } /*pictverbsettimes*/
00563 
00564 
00565 boolean pictwindowopen (hdlexternalvariable hvariable, hdlwindowinfo *hinfo) {
00566 
00567     register hdlpictvariable hv = (hdlpictvariable) hvariable;
00568     register hdlpictrecord hp;
00569     
00570     if (!(**hv).flinmemory)
00571         return (false);
00572     
00573     hp = (hdlpictrecord) (**hv).variabledata;
00574     
00575     shellfinddatawindow ((Handle) hp, hinfo); /*3/19/91 DW*/
00576     
00577     return ((**hp).flwindowopen);
00578     } /*pictwindowopen*/
00579 
00580 
00581 boolean pictedit (hdlexternalvariable hvariable, hdlwindowinfo hparent, ptrfilespec fs, bigstring bstitle, rectparam rzoom) {
00582     
00583     /*
00584     5.0.2b6 dmb: added flwindowopen loop to handle Windows async overlap
00585     */
00586 
00587     register hdlpictvariable hv = (hdlpictvariable) hvariable;
00588     register hdlpictrecord hp;
00589     Rect rwindow;
00590     WindowPtr w;
00591     hdlwindowinfo hi;
00592 
00593     if (!pictverbinmemory (hv)) /*couldn't swap it into memory*/
00594         return (false);
00595     
00596     hp = (hdlpictrecord) (**hv).variabledata; /*assume it's in memory*/
00597     
00598     while ((**hp).flwindowopen) { /*bring to front, return true*/
00599         
00600         hdlwindowinfo hinfo;
00601         
00602         if (shellfinddatawindow ((Handle) hp, &hinfo)) {
00603             
00604             if ((*rzoom).top > -2)
00605                 shellbringtofront (hinfo);
00606             
00607             return (true);
00608             }
00609 
00610         #ifdef MACVERSION
00611             break;
00612         #else
00613             if (!shellyield (false))
00614                 return (false);
00615         #endif
00616         }
00617     
00618     pictgetnewwindowrect (hp, &rwindow);
00619     
00620     if (!newchildwindow (idpictconfig, hparent, &rwindow, rzoom, bstitle, &w))
00621         return (false);
00622         
00623     getwindowinfo (w, &hi);
00624     
00625     (**hi).hdata = (Handle) hp;
00626     
00627     if (fs != nil)
00628         (**hi).fspec = *fs;
00629     
00630     (**hp).windowrect = (**hi).contentrect;
00631     
00632     (**hp).flwindowopen = true;
00633     
00634     if ((**hp).fldirty)
00635         shellsetwindowchanges (hi, true);
00636     
00637     windowzoom (w);
00638     
00639     return (true);
00640     } /*pictedit*/
00641 
00642 
00643 #if 0
00644 
00645 static boolean getpictparam (hdltreenode hfirst, short pnum, hdlpictvariable *hv) {
00646     
00647     short id;
00648     
00649     if (!langexternalgetexternalparam (hfirst, pnum, &id, (hdlexternalvariable *) hv)) {
00650         
00651         errornum = namenotpicterror;
00652         
00653         return (false);
00654         }
00655     
00656     if (id != idpictprocessor) {
00657         
00658         errornum = namenotpicterror;
00659         
00660         return (false);
00661         }
00662     
00663     return (true);
00664     } /*getpictparam*/
00665 
00666 #endif
00667 
00668 
00669 static boolean pictverbscheduleupdate (hdltreenode hparam1, tyvaluerecord *v) {
00670     
00671     short period;
00672     
00673     flnextparamislast = true;
00674     
00675     if (!getintvalue (hparam1, 1, &period))
00676         return (false);
00677     
00678     pictscheduleupdate (period);
00679     
00680     (*v).data.flvalue = true;
00681     
00682     return (true);
00683     } /*pictverbscheduleupdate*/
00684             
00685 
00686 #if 0
00687 
00688 static boolean pictverbbitmapupdate (hdltreenode hparam1, tyvaluerecord *v) {
00689     
00690     boolean flbitmap;
00691     
00692     flnextparamislast = true;
00693     
00694     if (!getbooleanvalue (hparam1, 1, &flbitmap))
00695         return (false);
00696     
00697     pictsetbitmapupdate (flbitmap);
00698     
00699     (*v).data.flvalue = true;
00700     
00701     return (true);
00702     } /*pictverbbitmapupdate*/
00703 
00704 #endif
00705     
00706             
00707 static boolean pictverbevaluator (hdltreenode hparam1, tyvaluerecord *v) {
00708     
00709     boolean flevaluate;
00710     
00711     flnextparamislast = true;
00712     
00713     if (!getbooleanvalue (hparam1, 1, &flevaluate))
00714         return (false);
00715     
00716     pictsetevaluate (flevaluate);
00717     
00718     (*v).data.flvalue = true;
00719     
00720     return (true);
00721     } /*pictverbevaluator*/
00722 
00723 
00724 #if 0
00725 
00726 static boolean pictverbgetbounds (hdltreenode hparam1, tyvaluerecord *v) {
00727     
00728     Rect r;
00729     
00730     if (!langcheckparamcount (hparam1, 0)) /*shouldn't have any parameters*/
00731         return (false);
00732     
00733     if (!pictgetframerect (pictdata, &r))
00734         clearbytes (&r, sizeof (r));
00735     
00736     return (!newheapvalue (&r, sizeof (r), rectvaluetype, v));
00737     } /*pictverbgetbounds*/
00738 
00739 #endif
00740 
00741 
00742 static boolean pictverbgetpicture (hdltreenode hparam1, tyvaluerecord *v) {
00743     
00744     bigstring bsname;
00745     Handle hpict;
00746     hdlhashtable htable;
00747     tyvaluerecord pictval;
00748     
00749     flnextparamislast = true;
00750     
00751     if (!getvarparam (hparam1, 1, &htable, bsname))
00752         return (false);
00753     
00754     if (!copyhandle ((Handle) (**pictdata).macpicture, &hpict))
00755         return (false);
00756     
00757     if (hpict == nil) /*picture was empty -- not an error, but return false to caller*/
00758         return (true);
00759     
00760     if (!setbinaryvalue (hpict, 'PICT', &pictval))
00761         return (false);
00762     
00763     if (!hashtableassign (htable, bsname, pictval))
00764         return (false);
00765     
00766     exemptfromtmpstack (&pictval);
00767     
00768     (*v).data.flvalue = true;
00769     
00770     return (true);
00771     } /*pictverbgetpicture*/
00772 
00773     
00774 static void pictresetpicture (void) {
00775     
00776     windowsetchanges (pictwindow, true);
00777     
00778     shellinvalcontent (pictwindowinfo);
00779     
00780     pictresetscrollbars ();
00781     
00782     pictdirty ();
00783     } /*pictresetpicture*/
00784 
00785 
00786 static boolean pictverbsetpicture (hdltreenode hparam1, tyvaluerecord *v) {
00787     
00788     register hdlpictrecord hp = pictdata;
00789     Handle hpict;
00790     OSType typeid;
00791     
00792     flnextparamislast = true;
00793     
00794     setbooleanvalue (false, v); /*assume the worst*/
00795     
00796     if (!getbinaryvalue (hparam1, 1, false, &hpict))
00797         return (false);
00798     
00799     pullfromhandle (hpict, 0L, sizeof (typeid), &typeid);
00800     
00801     /***should enforce typeid == 'PICT'*/
00802     
00803     if ((**hp).macpicture == nil) {
00804         
00805         if (!copyhandle (hpict, &hpict))
00806             return (false);
00807         
00808         (**hp).macpicture = (PicHandle) hpict;
00809         }
00810     else {
00811         
00812         if (!copyhandlecontents (hpict, (Handle) (**hp).macpicture))
00813             return (false);
00814         }
00815     
00816     pictresetpicture ();
00817     
00818     (*v).data.flvalue = true;
00819     
00820     return (true);
00821     } /*pictverbsetpicture*/
00822 
00823 
00824 static boolean pictfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
00825     
00826     /*
00827     bridges pict.c with the language.  the name of the verb is bs, its first parameter
00828     is hparam1, and we return a value in vreturned.
00829     
00830     we use a limited number of support routines from lang.c to get parameters and
00831     to return values. 
00832     
00833     return false only if the error is serious enough to halt the running of the script
00834     that called us, otherwise error values are returned through the valuerecord, which
00835     is available to the script.
00836     
00837     if we return false, we try to provide a descriptive error message in the 
00838     returned string bserror.
00839     
00840     8/25/92 dmb: commented-out getboundsfunc; undocumented
00841     
00842     6/1/93 dmb: when vreturned is nil, return whether or not verb token must 
00843     be run in the Frontier process
00844     */
00845     
00846     register tyvaluerecord *v = vreturned;
00847     register boolean fl;
00848     WindowPtr targetwindow;
00849     
00850     if (v == nil) /*need Frontier process?*/
00851         return (true);
00852     
00853     errornum = 0;
00854     
00855     setbooleanvalue (false, v); /*by default, pict functions return false*/
00856     
00857     /*be sure there's a pict window in front -- set globals*/
00858     
00859     if (!langfindtargetwindow (idpictprocessor, &targetwindow)) {
00860         
00861         errornum = nopicterror;
00862         
00863         goto error;
00864         }
00865     
00866     shellpushglobals (targetwindow);
00867     
00868     (*shellglobals.gettargetdataroutine) (idpictprocessor); /*set pict globals*/
00869     
00870     fl = false; /*default return value*/
00871     
00872     switch (token) { /*verbs that require that a pict window be open*/
00873         
00874         case scheduleupdatefunc:
00875             fl = pictverbscheduleupdate (hparam1, v);
00876             
00877             break;
00878         
00879         /*
00880         case bitmapupdatefunc:
00881             fl = pictverbbitmapupdate (hparam1, v);
00882             
00883             break;
00884         */
00885         
00886         case evalfunc:
00887             fl = pictverbevaluator (hparam1, v);
00888             
00889             break;
00890         
00891         case getpicturefunc:
00892             fl = pictverbgetpicture (hparam1, v);
00893             
00894             break;
00895         
00896         case setpicturefunc:
00897             fl = pictverbsetpicture (hparam1, v);
00898             
00899             break;
00900         
00901         /*
00902         case getboundsfunc:
00903             fl = pictverbgetbounds (hparam1, v);
00904             
00905             break;
00906         */
00907         } /*switch*/
00908     
00909     shellupdatescrollbars (pictwindowinfo);
00910     
00911     shellpopglobals ();
00912     
00913     return (fl);
00914     
00915     error:
00916     
00917     if (errornum != 0) /*get error string, insert verb name if called for*/
00918         getstringlist (picterrorlist, errornum, bserror);
00919     
00920     return (false);
00921     } /*pictfunctionvalue*/
00922 
00923 
00924 static boolean pictinitverbs (void) {
00925     
00926     return (loadfunctionprocessor (idpictverbs, &pictfunctionvalue));
00927     } /*pictinitverbs*/
00928 
00929 
00930 static boolean pictgetcontentsize (long *width, long *height) {
00931     
00932     /*
00933     our ideal content size is the size of the picture with a 10 
00934     pixel border all around
00935     */
00936     
00937     Rect r;
00938     
00939     if (!pictgetframerect (pictdata, &r))
00940         return (false);
00941     
00942     *width = (long) r.right - r.left + 20;
00943     
00944     *height = (long) r.bottom - r.top + 20;
00945     
00946     return (true);
00947     } /*pictgetcontentsize*/
00948 
00949 
00950 static void pictresize (void) {
00951     
00952     } /*pictresize*/
00953 
00954 
00955 static boolean pictundosetpict (Handle hpict, boolean flundo) {
00956     
00957     if (flundo) {
00958         
00959         pushundostep (pictundosetpict, (Handle) (**pictdata).macpicture);
00960         
00961         (**pictdata).macpicture = (PicHandle) hpict;
00962         
00963         pictresetpicture ();
00964         }
00965     else
00966         disposehandle (hpict);
00967     
00968     return (true);
00969     } /*pictundosetpict*/
00970 
00971 
00972 static boolean pictclear (void) {
00973     
00974     pushundoaction (undoclearstring);
00975     
00976     pictundosetpict (nil, true);
00977     
00978     return (true);
00979     } /*pictclear*/
00980 
00981 
00982 static boolean pictcopy (void) {
00983     
00984     Handle hpicture;
00985     
00986     if (!copyhandle ((Handle) (**pictdata).macpicture, &hpicture))
00987         return (false);
00988     
00989     if (hpicture == nil)
00990         return (false);
00991     
00992     return (shellsetscrap (hpicture, pictscraptype, (shelldisposescrapcallback) &disposehandle, nil));
00993     } /*pictcopy*/
00994 
00995 
00996 static boolean pictcut (void) {
00997     
00998     pushundoaction (undocutstring);
00999     
01000     return (pictcopy () && pictundosetpict (nil, true));
01001     } /*pictcut*/
01002 
01003 
01004 static boolean pictpaste (void) {
01005     
01006     Handle hpict;
01007     boolean fltempscrap;
01008     
01009     pushundoaction (undopastestring);
01010     
01011     if (!shellconvertscrap (pictscraptype, &hpict, &fltempscrap))
01012         return (false);
01013     
01014     if (!fltempscrap) { /*we need our own copy*/
01015         
01016         if (!copyhandle (hpict, &hpict))
01017             return (false);
01018         }
01019     
01020     pictundosetpict (hpict, true);
01021     
01022     return (true);
01023     } /*pictpaste*/
01024 
01025 
01026 boolean pictverbfind (hdlexternalvariable hvariable, boolean *flzoom) {
01027 #pragma unused(flzoom, hvariable)
01028 
01029     return (false);
01030     } /*pictverbfind*/
01031 
01032 
01033 static boolean pictsearch (void) {
01034     
01035     long pictrefcon = (**pictdata).pictrefcon;
01036     
01037     startingtosearch (pictrefcon);
01038     
01039     if (!searchshouldcontinue (pictrefcon))
01040         return (false);
01041     
01042     return (langexternalcontinuesearch ((hdlexternalvariable) pictrefcon));
01043     } /*pictsearch*/
01044 
01045 
01046 static boolean pictgetvariable (void *refcon) {
01047     
01048     hdlexternalvariable *hvariable = (hdlexternalvariable *) refcon;
01049     
01050     if (pictdata == nil)
01051         return (false);
01052     
01053     *hvariable = (hdlexternalvariable) (**pictdata).pictrefcon;
01054     
01055     return (true);
01056     } /*pictgetvariable*/
01057 
01058 
01059 static boolean pictpagesetup (void) {
01060     
01061     return (true);
01062     } /*pictpagesetup*/
01063 
01064 
01065 static boolean pictsetprintinfo (void) {
01066     
01067     shellprintinfo.ctpages = 1;
01068     
01069     return (true);
01070     } /*pictsetprintinfo*/
01071 
01072 
01073 static boolean pictprint (short pagenumber) {
01074 #pragma unused (pagenumber)
01075 
01076     register hdlpictrecord hp = pictdata;
01077     register PicHandle macpicture = (**hp).macpicture;
01078     register boolean fleval;
01079     Rect rframe;
01080     
01081     pictgetframerect (hp, &rframe);
01082     
01083     offsetrect (&rframe,
01084         shellprintinfo.paperrect.left - rframe.left,
01085         shellprintinfo.paperrect.top - rframe.top);
01086     
01087     fleval = (**hp).flevalexpressions;
01088     
01089     if (fleval) 
01090         pictupdatepatcher (); /*install our quickdraw patches*/
01091     
01092     DrawPicture (macpicture, &rframe);
01093     
01094     if (fleval) 
01095         pictdepatcher (); /*de-install 'em*/
01096     
01097     return (true);
01098     } /*pictprint*/
01099 
01100 
01101 static boolean pictclose (void) {
01102     
01103     register hdlpictrecord hp = pictdata;
01104     register hdlpictvariable hv = (hdlpictvariable) (**hp).pictrefcon;
01105     
01106     assert (hv != nil); /*defensive driving*/
01107     
01108     langexternalwindowclosed ((hdlexternalvariable) hv);
01109     
01110     killundo (); /*must toss undos before they're stranded*/
01111     
01112     pictverbcheckwindowrect (hp);
01113     
01114     if ((**hp).fldirty) { /*we have to keep the in-memory version around*/
01115         
01116         (**hp).flwindowopen = false;
01117         }
01118     
01119     else { /*the db version is identical to memory version, save memory*/
01120         
01121         assert ((**hv).oldaddress != nildbaddress);
01122         
01123         (**hv).flinmemory = false;
01124         
01125         (**hv).variabledata = (long) (**hv).oldaddress;
01126         
01127         pictdisposerecord (hp); /*reclaim memory*/
01128         }
01129         
01130     return (true);
01131     } /*pictclose*/
01132     
01133     
01134 static boolean pictkeystroke (void) {
01135     
01136     if (langexternalsurfacekey ((hdlexternalvariable) (**pictdata).pictrefcon))
01137         return (true);
01138     
01139     return (true);
01140     } /*pictkeystroke*/
01141 
01142 
01143 static boolean picttitleclick (Point pt) {
01144     
01145     return (langexternaltitleclick (pt, (hdlexternalvariable) (**pictdata).pictrefcon));
01146     } /*picttitleclick*/
01147 
01148 
01149 static boolean pictgettargetdata (short id) {
01150     
01151     /*
01152     a verb is about to be executed that acts on the indicated external type, or 
01153     on any shell window if id == -1.
01154     
01155     return true if we can handle verbs of that type and are able to set the 
01156     relevant globals
01157     */
01158     
01159     switch (id) {
01160         
01161         case -1:
01162             return (true);
01163         
01164         case idpictprocessor: /*don't need to do anything -- our pict globals are pushed*/
01165             return (true);
01166         
01167         default:
01168             return (false);
01169         }
01170     } /*pictgettargetdata*/
01171 
01172 
01173 boolean pictstart (void) {
01174     
01175     /*
01176     set up callback routines record, and link our data into the shell's 
01177     data structure.
01178     */
01179     
01180     ptrcallbacks pictcallbacks;
01181     register ptrcallbacks cb;
01182     
01183     assert (sizeof (tyexternalvariable) == sizeof (typictvariable));
01184     
01185     pictinitverbs ();
01186     
01187     shellnewcallbacks (&pictcallbacks);
01188     
01189     cb = pictcallbacks; /*copy into register*/
01190     
01191     loadconfigresource (idpictconfig, &(*cb).config);
01192         
01193     (*cb).configresnum = idpictconfig;
01194         
01195     (*cb).windowholder = &pictwindow;
01196     
01197     (*cb).dataholder = (Handle *) &pictdata;
01198     
01199     (*cb).infoholder = &pictwindowinfo; 
01200     
01201 #ifdef version42orgreater
01202     
01203     (*cb).disposerecordroutine = ccdisposefilerecord;
01204     
01205     (*cb).saveroutine = ccsavespecialfile;
01206 
01207 #endif
01208     
01209     (*cb).updateroutine = &pictupdate;
01210     
01211     (*cb).getcontentsizeroutine = &pictgetcontentsize;
01212     
01213     (*cb).resizeroutine = &pictresize;
01214     
01215     (*cb).scrollroutine = &pictscroll;
01216     
01217     (*cb).setscrollbarroutine = &pictresetscrollbars;
01218     
01219     (*cb).cutroutine = &pictcut;
01220     
01221     (*cb).copyroutine = &pictcopy;
01222     
01223     (*cb).pasteroutine = &pictpaste;
01224     
01225     (*cb).clearroutine = &pictclear;
01226     
01227     (*cb).searchroutine = &pictsearch;
01228     
01229     (*cb).getvariableroutine = &pictgetvariable;
01230     
01231     (*cb).closeroutine = &pictclose;
01232     
01233     (*cb).pagesetuproutine = &pictpagesetup;
01234     
01235     (*cb).printroutine = &pictprint;
01236     
01237     (*cb).setprintinfoproutine = &pictsetprintinfo;
01238     
01239     (*cb).idleroutine = &pictidle;
01240     
01241     (*cb).keystrokeroutine = &pictkeystroke;
01242     
01243     (*cb).titleclickroutine = &picttitleclick;
01244     
01245     (*cb).gettargetdataroutine = &pictgettargetdata;
01246     
01247     return (true);
01248     } /*pictstart*/
01249 
01250 #endif // !flruntime
01251 
01252 
01253 
01254 

Generated on Wed May 31 18:20:00 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6