pict.c

Go to the documentation of this file.
00001 
00002 /*  $Id: pict.c 1366 2006-05-06 00:23:35Z creecode $    */
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 "bitmaps.h"
00032 #include "file.h"
00033 #include "quickdraw.h"
00034 #include "memory.h"
00035 #include "mouse.h"
00036 #include "ops.h"
00037 #include "resources.h"
00038 #include "scrollbar.h"
00039 #include "strings.h"
00040 #include "frontierwindows.h"
00041 #include "zoom.h"
00042 #include "shell.h"
00043 #include "process.h"
00044 #include "pict.h"
00045 #include "timedate.h"
00046 #include "byteorder.h"  /* 2006-04-08 aradke: endianness conversion macros */
00047 
00048 
00049 
00050 #define pictstartrealdata 512L /*this is where the PICT is stored in a PICT file*/
00051 
00052 
00053 typedef struct tydiskpictrecord {
00054     
00055     short versionnumber; /*this structure is stored on disk*/
00056     
00057     diskrect windowrect; 
00058     
00059     long timecreated, timelastsave; /*maybe we'll use these at some later date?*/
00060     
00061     long ctsaves; /*the number of times this structure has been saved*/
00062     
00063     long pictbytes; /*number of bytes allocated for PICT*/
00064     
00065     short updateticks; /*how many ticks between updates when window is in front*/
00066     
00067     short flags;
00068     
00069     byte waste [20]; /*room for growth*/
00070     
00071     /*remaining bytes hold the PICT data*/
00072     } tydiskpictrecord, *ptrdiskpictrecord, **hdldiskpictrecord;
00073 
00074 #ifdef MACVERSION
00075     #define flbitmapupdate_mask 0x8000 /*if set, use offscreen bitmaps when updating*/
00076     #define flevalexpressions_mask 0x4000 /*if set, parse all text that begins with an = sign*/
00077     #define flscaletofitwindow_mask 0x2000 /*if set, scale window down to fit inside window*/
00078 #endif
00079 
00080 #ifdef WIN95VERSION
00081     #define flbitmapupdate_mask 0x0080 /*if set, use offscreen bitmaps when updating*/
00082     #define flevalexpressions_mask 0x0040 /*if set, parse all text that begins with an = sign*/
00083     #define flscaletofitwindow_mask 0x0020 /*if set, scale window down to fit inside window*/
00084 #endif
00085 
00086 
00087 typedef struct tyOLD42diskpictrecord {
00088     
00089     short versionnumber; /*this structure is stored on disk*/
00090     
00091     diskrect windowrect; 
00092     
00093     long timecreated, timelastsave; /*maybe we'll use these at some later date?*/
00094     
00095     long ctsaves; /*the number of times this structure has been saved*/
00096     
00097     long pictbytes; /*number of bytes allocated for PICT*/
00098     
00099     short updateticks; /*how many ticks between updates when window is in front*/
00100     
00101     boolean flbitmapupdate: 1; /*if true, use offscreen bitmaps when updating*/
00102     
00103     boolean flevalexpressions: 1; /*if true, parse all text that begins with an = sign*/
00104     
00105     boolean flscaletofitwindow: 1; /*if true, scale window down to fit inside window*/
00106     
00107     char waste [21]; /*room for growth*/
00108     
00109     /*remaining bytes hold the PICT data*/
00110     } tyOLD42diskpictrecord, *ptrOLD42diskpictrecord, **hdlOLD42diskpictrecord;
00111 
00112 
00113 WindowPtr pictwindow = nil;
00114 
00115 hdlwindowinfo pictwindowinfo = nil;
00116 
00117 hdlpictrecord pictdata = nil;
00118 
00119 
00120 #ifdef MACVERSION
00121     static CQDProcs procs; /*must be statically allocated & have room for color procs*/
00122 
00123     static CQDProcs *porigprocs; /*need to save, call & restore*/
00124 #endif
00125 
00126 
00127 
00128 boolean pictgetframerect (hdlpictrecord hpict, Rect *rframe) {
00129     
00130 #ifdef MACVERSION
00131     PicHandle macpicture = (**hpict).macpicture;
00132     
00133     if (macpicture == nil)
00134         return (false);
00135     
00136     *rframe = (**macpicture).picFrame;
00137 #endif
00138 
00139 #ifdef WIN95VERSION
00140     #pragma message ("Win95: pictgetframerect not implemented")
00141 #endif
00142 
00143     return (true);
00144     } /*pictgetframerect*/
00145 
00146 
00147 boolean pictpack (hdlpictrecord hpict, Handle *hpacked) {
00148     
00149     /*
00150     create a packed, contiguous version of the indicated pict record.
00151     
00152     if hpacked comes in non-nil, we just append our stuff to the end of the handle, 
00153     we don't allocate a new one.
00154     */
00155     
00156     register hdlpictrecord hp = hpict;
00157     tydiskpictrecord header;
00158     
00159     clearbytes (&header, longsizeof (header));
00160     
00161     header.versionnumber = conditionalshortswap (1);
00162     
00163     recttodiskrect (&(**hpict).windowrect, &header.windowrect);
00164     
00165     header.timecreated = conditionallongswap ((**hp).timecreated);
00166     
00167     header.timelastsave = conditionallongswap ((**hp).timelastsave);
00168     
00169     /*timestamp (&header.timelastsave);*/ /*dmb 4.1b13: don't stamp it; pictdirty sets it as true mode date*/
00170     ++((**hp).ctsaves);
00171 
00172     header.ctsaves = conditionallongswap((**hp).ctsaves);
00173     
00174     header.updateticks = conditionalshortswap((**hp).updateticks);
00175     
00176     if ((**hp).flbitmapupdate)
00177         header.flags |= flbitmapupdate_mask;
00178     
00179     if ((**hp).flevalexpressions)
00180         header.flags |= flevalexpressions_mask;
00181     
00182     if ((**hp).flscaletofitwindow)
00183         header.flags |= flscaletofitwindow_mask;
00184     
00185     header.pictbytes = gethandlesize ((Handle) (**hp).macpicture);
00186 
00187     memtodisklong (header.pictbytes);
00188     
00189     if (*hpacked == nil) { /*must allocate a new one*/
00190         
00191         if (!newfilledhandle (&header, longsizeof (header), hpacked))
00192             return (false);
00193         }
00194     else {
00195         
00196         if (!enlargehandle (*hpacked, longsizeof (header), &header))
00197             return (false);
00198         }
00199     
00200     return (pushhandle ((Handle) (**hpict).macpicture, *hpacked));
00201     } /*pictverbpack*/
00202     
00203     
00204 boolean pictunpack (Handle hpacked, long *ixload, hdlpictrecord *hpict) {
00205     
00206     /*
00207     unpack the pict record from the handle at the indicated index.  bump the index
00208     to point past the pict record.  return true if it worked.
00209     */
00210     
00211     tydiskpictrecord header;
00212     PicHandle macpicture;
00213     register hdlpictrecord hp;
00214 
00215     assert (sizeof (tyOLD42diskpictrecord) == sizeof (tydiskpictrecord));
00216     
00217 #if 0 // def MACVERSION
00218     short version;
00219     long ix;
00220     tyOLD42diskpictrecord oldheader;
00221 
00222     ix = *ixload;
00223 
00224     if (!loadfromhandle (hpacked, &ix, longsizeof(version), &version))
00225         return (false);
00226 
00227     if (version == 1) {
00228         if (!loadfromhandle (hpacked, ixload, longsizeof (oldheader), &oldheader))
00229             return (false);
00230         
00231         if (!loadfromhandletohandle (hpacked, ixload, oldheader.pictbytes, false, (Handle *) &macpicture))
00232             return (false);
00233         
00234         if (!newclearhandle (longsizeof (typictrecord), (Handle *) hpict)) {
00235             
00236             disposehandle ((Handle) macpicture);
00237             
00238             return (false);
00239             }
00240         
00241         hp = *hpict; /*copy into register*/
00242         
00243         recttodiskrect (&(**hp).windowrect, &oldheader.windowrect);
00244         
00245         (**hp).timecreated = oldheader.timecreated;
00246         
00247         (**hp).timelastsave = oldheader.timelastsave;
00248         
00249         (**hp).ctsaves = oldheader.ctsaves;
00250         
00251         (**hp).updateticks = oldheader.updateticks;
00252         
00253         (**hp).flbitmapupdate = oldheader.flbitmapupdate;
00254         
00255         (**hp).flevalexpressions = oldheader.flevalexpressions;
00256         
00257         (**hp).flscaletofitwindow = oldheader.flscaletofitwindow;
00258         
00259         (**hp).macpicture = macpicture;
00260         
00261         return (true);
00262         }
00263 #endif
00264 
00265     if (!loadfromhandle (hpacked, ixload, longsizeof (header), &header)) {
00266     
00267         shellerrormessage (BIGSTRING ("\x3d" "Can't unpack picture because unexpected data was encountered."));
00268         
00269         return (false);
00270         }
00271     
00272     disktomemlong (header.pictbytes);
00273     
00274     if (!loadfromhandletohandle (hpacked, ixload, header.pictbytes, false, (Handle *) &macpicture))
00275         return (false);
00276     
00277     if (!newclearhandle (longsizeof (typictrecord), (Handle *) hpict)) {
00278         
00279         disposehandle ((Handle) macpicture);
00280         
00281         return (false);
00282         }
00283     
00284     hp = *hpict; /*copy into register*/
00285     
00286     diskrecttorect (&header.windowrect, &(**hp).windowrect);
00287     
00288     (**hp).timecreated = conditionallongswap (header.timecreated);
00289     
00290     (**hp).timelastsave = conditionallongswap (header.timelastsave);
00291     
00292     (**hp).ctsaves = conditionallongswap (header.ctsaves);
00293     
00294     (**hp).updateticks = conditionalshortswap (header.updateticks);
00295     
00296     (**hp).flbitmapupdate = (header.flags & flbitmapupdate_mask) != 0;
00297     
00298     (**hp).flevalexpressions = (header.flags & flevalexpressions_mask) != 0;
00299     
00300     (**hp).flscaletofitwindow = (header.flags & flscaletofitwindow_mask) != 0;
00301     
00302     (**hp).macpicture = macpicture;
00303     
00304     return (true);
00305     } /*pictunpack*/
00306     
00307     
00308 boolean pictnewrecord (void) {
00309     
00310     /*
00311     4.0b7 dmb: initialize timelastsave to creation time; it's really a modification date.
00312     */
00313     
00314     register hdlpictrecord hp;
00315     
00316     if (!newclearhandle (longsizeof (typictrecord), (Handle *) &pictdata)) 
00317         return (false);
00318         
00319     hp = pictdata; /*copy into register*/
00320     
00321     (**hp).timecreated = (**hp).timelastsave = timenow ();
00322     
00323     (**hp).windowrect.top = -1; /*accept default, unless someone resets this*/
00324     
00325     return (true);
00326     } /*pictnewrecord*/
00327     
00328     
00329 boolean pictdisposerecord (hdlpictrecord hpict) {
00330     
00331     disposehandle ((Handle) (**hpict).macpicture);
00332     
00333     disposehandle ((Handle) hpict);
00334     
00335     return (true);
00336     } /*pictdisposerecord*/
00337 
00338 
00339 #if 0
00340 
00341 static boolean pictdebug (PicHandle macpicture) { 
00342 
00343     Rect r, rbounds;
00344     WindowPtr w;
00345     
00346     r = (**macpicture).picFrame;
00347     
00348     if (!zoomtempwindow (true, r.bottom - r.top, r.right - r.left, &w))
00349         return (false);
00350     
00351     DrawPicture (macpicture, &r);
00352     
00353     waitmousebutton (true);
00354     
00355     closetempwindow (true, w);
00356     
00357     return (true);
00358     } /*pictdebug*/
00359     
00360 
00361 boolean pictreadfile (bigstring fname, PicHandle *macpicture) {
00362     
00363     register PicHandle hp = nil;
00364     register long ctbytes;
00365     short fnum;
00366     register boolean fl;
00367     
00368     if (!openfile (fname, 0, &fnum))
00369         return (false);
00370     
00371     ctbytes = filegetsize (fnum) - pictstartrealdata;
00372     
00373     if (ctbytes <= 0) /*error, this can't be a PICT file*/
00374         goto error;
00375     
00376     if (!filesetposition (fnum, pictstartrealdata))
00377         goto error;
00378         
00379     if (!newhandle (ctbytes, (Handle *) macpicture))
00380         goto error;
00381     
00382     hp = *macpicture; /*copy into register*/
00383     
00384     lockhandle ((Handle) hp);
00385     
00386     fl = fileread (fnum, ctbytes, *hp);
00387     
00388     unlockhandle ((Handle) hp);
00389     
00390     if (!fl)
00391         goto error;
00392     
00393     closefile (fnum);
00394     
00395     /*pictdebug (*macpicture);*/
00396     
00397     return (true);
00398         
00399     error:
00400     
00401     disposehandle ((Handle) hp); 
00402     
00403     closefile (fnum);
00404     
00405     *macpicture = nil;
00406     
00407     return (false);
00408     } /*pictreadfile*/
00409     
00410 #endif
00411 
00412 
00413 void pictresetscrollbars (void) {
00414     
00415     register hdlpictrecord hp = pictdata;
00416     register hdlwindowinfo hw = pictwindowinfo;
00417     tyscrollinfo vertinfo, horizinfo;
00418     Rect rcontent, rpict;
00419     
00420     rcontent = (**hw).contentrect;
00421     
00422     if (!pictgetframerect (hp, &rpict))
00423         rpict = rcontent;
00424     
00425     vertinfo.min = 0;
00426     
00427     vertinfo.max = (rpict.bottom - rpict.top) - (rcontent.bottom - rcontent.top);
00428     
00429     horizinfo.min = 0;
00430     
00431     horizinfo.max = (rpict.right - rpict.left) - (rcontent.right - rcontent.left);
00432     
00433     vertinfo.cur = (**hw).vertscrollinfo.cur;
00434     
00435     horizinfo.cur = (**hw).horizscrollinfo.cur;
00436     
00437     vertinfo.max = max (vertinfo.min, vertinfo.max);
00438     
00439     horizinfo.max = max (horizinfo.min, horizinfo.max);
00440     
00441     vertinfo.cur = max (vertinfo.min, vertinfo.cur);
00442     
00443     vertinfo.cur = min (vertinfo.max, vertinfo.cur);
00444     
00445     horizinfo.cur = max (horizinfo.min, horizinfo.cur);
00446     
00447     horizinfo.cur = min (horizinfo.max, horizinfo.cur);
00448     
00449     horizinfo.pag = rcontent.right - rcontent.left;
00450 
00451     vertinfo.pag = rcontent.bottom - rcontent.top;
00452 
00453     (**hw).vertscrollinfo = vertinfo;
00454     
00455     (**hw).horizscrollinfo = horizinfo;
00456     
00457     (**hw).fldirtyscrollbars = true; /*force an update*/
00458     } /*pictresetscrollbars*/
00459 
00460 
00461 boolean pictscroll (tydirection dir, boolean flpage, long ctscroll) {
00462     
00463     /*
00464     from DW to anyone -- don't factor this shit down, I like it this way.  if you
00465     factor it, you may save one or two bytes, but you make it unreadable.  if you
00466     don't believe me, have a look at wpscroll.
00467     
00468     9/22/92 dmb: don't ctscroll parameter -- it's important!
00469     */
00470     
00471     register hdlwindowinfo hw = pictwindowinfo;
00472     register long dh = 0, dv = 0;
00473     Rect r;
00474     
00475     r = (**hw).contentrect;
00476     
00477     if (!flpage)
00478         ctscroll = max (ctscroll, 4);
00479     
00480     switch (dir) {
00481         
00482         case down:
00483             if (flpage)
00484                 dv = -(r.bottom - r.top);
00485             else
00486                 dv = -ctscroll;
00487             
00488             break;
00489             
00490         case up:
00491             if (flpage)
00492                 dv = r.bottom - r.top;
00493             else
00494                 dv = ctscroll;
00495             
00496             break;
00497         
00498         case right:
00499             if (flpage)
00500                 dh = -(r.right - r.left);
00501             else
00502                 dh = -ctscroll;
00503                 
00504             break;
00505             
00506         case left:
00507             if (flpage)
00508                 dh = r.right - r.left;
00509             else
00510                 dh = ctscroll;
00511                 
00512             break;
00513             
00514         default:
00515             return (false);
00516         } /*switch*/
00517     
00518     if (dv != 0) {
00519         
00520         register long x;
00521         
00522         x = (**hw).vertscrollinfo.cur + dv;
00523     
00524         x = max (x, (**hw).vertscrollinfo.min);
00525     
00526         x = min (x, (**hw).vertscrollinfo.max);
00527         
00528         dv = (**hw).vertscrollinfo.cur - x;
00529         
00530         (**hw).vertscrollinfo.cur = x;
00531         }
00532     
00533     if (dh != 0) {
00534         
00535         register long x;
00536         
00537         x = (**hw).horizscrollinfo.cur + dh;
00538     
00539         x = max (x, (**hw).horizscrollinfo.min);
00540     
00541         x = min (x, (**hw).horizscrollinfo.max);
00542         
00543         dh = (**hw).horizscrollinfo.cur - x;
00544         
00545         (**hw).horizscrollinfo.cur = x;
00546         }
00547     
00548     if ((dh != 0) || (dv != 0)) {
00549     
00550         scrollrect (r, dh, dv);
00551     
00552         shellupdatenow (pictwindow);
00553         }
00554         
00555     return (true);
00556     } /*pictscroll*/
00557 
00558 
00559 static boolean picttextparse (Ptr textbuf, short ctbytes, bigstring bs) {
00560     
00561     /*
00562     6/1/93 dmb: agentsdisable is defunct.
00563     */
00564     
00565     bigstring bsresult;
00566     boolean fl;
00567     
00568     setstringlength (bs, ctbytes);
00569     
00570     if (ctbytes == 0)
00571         return (true);
00572         
00573     moveleft (textbuf, &bs [1], (long) ctbytes);
00574     
00575     if (bs [1] != '=') /*no computation desired*/
00576         return (true);
00577         
00578     deletestring (bs, 1, 1); /*pop off the = sign*/
00579     
00580     if (stringlength (bs) == 0) /*nothing but an = sign*/
00581         return (true);
00582     
00583     /*
00584     agentsdisable (true);
00585     */
00586     
00587     fl = langrunstringnoerror (bs, bsresult);
00588     
00589     /*
00590     agentsdisable (false);
00591     */
00592     
00593     if (fl) {
00594     
00595         copystring (bsresult, bs);
00596         
00597         return (true);
00598         }
00599     
00600     getstringlist (pictstringlist, picterrorstring, bs);
00601     
00602     return (false);
00603     } /*picttextparse*/
00604 
00605 #ifdef MACVERSION
00606 
00607     static pascal void update_stdtext (short ctbytes, Ptr textbuf, Point numer, Point denom)  {
00608     
00609         bigstring bs;
00610         
00611         picttextparse (textbuf, ctbytes, bs);
00612         
00613         if (porigprocs == nil)
00614             StdText (stringlength (bs), &bs [1], numer, denom);
00615         else
00616         
00617             #if TARGET_API_MAC_CARBON == 1
00618             
00619                 InvokeQDTextUPP ((short) stringlength (bs), (Ptr) &bs [1], numer, denom, (*porigprocs).textProc);
00620             
00621             #else
00622         
00623                 CallQDTextProc ((*porigprocs).textProc, (short) stringlength (bs), (Ptr) &bs [1], numer, denom);
00624             
00625             #endif
00626         } /*update_stdtext*/
00627     
00628     
00629     static pascal short update_stdtxmeas (short ctbytes, Ptr textbuf, Point *numer, Point *denom, FontInfo *info) {
00630         
00631         bigstring bs;
00632         
00633         picttextparse (textbuf, ctbytes, bs);
00634         
00635         if (porigprocs == nil)
00636             return (StdTxMeas (stringlength (bs), &bs [1], numer, denom, info));
00637     
00638         #if TARGET_API_MAC_CARBON == 1
00639 
00640             return (InvokeQDTxMeasUPP ((short) stringlength (bs), (Ptr) &bs [1], numer, denom, info, (*porigprocs).txMeasProc));
00641             
00642         #else
00643             
00644             return (CallQDTxMeasProc ((*porigprocs).txMeasProc, (short) stringlength (bs), (Ptr) &bs [1], numer, denom, info));
00645         
00646         #endif
00647         } /*update_stdtxmeas*/
00648     
00649     #if TARGET_API_MAC_CARBON == 1
00650     #define update_stdtextUPP ((QDTextUPP) update_stdtext)
00651         
00652     #define update_stdtxmeasUPP ((QDTxMeasUPP) update_stdtxmeas)
00653     #else
00654     #if GENERATINGCFM
00655         
00656         static RoutineDescriptor update_stdtextDesc = BUILD_ROUTINE_DESCRIPTOR (uppQDTextProcInfo, update_stdtext);
00657         
00658         static RoutineDescriptor update_stdtxmeasDesc = BUILD_ROUTINE_DESCRIPTOR (uppQDTxMeasProcInfo, update_stdtxmeas);
00659         
00660         #define update_stdtextUPP (&update_stdtextDesc)
00661         
00662         #define update_stdtxmeasUPP (&update_stdtxmeasDesc)
00663         
00664     #else
00665         
00666         #define update_stdtextUPP ((QDTextUPP) update_stdtext)
00667         
00668         #define update_stdtxmeasUPP ((QDTxMeasUPP) update_stdtxmeas)
00669         
00670     #endif
00671 #endif//TARGET_API_MAC_CARBON
00672         
00673     
00674 #endif
00675 
00676 
00677 void pictupdatepatcher (void) {
00678     
00679     /*
00680     2.1b5 dmb: use CProcs to handle color windows
00681     */
00682     
00683 #ifdef MACVERSION
00684     //Code change by Timothy Paustian Sunday, April 30, 2000 9:24:15 PM
00685     //Changed to Opaque call for Carbon
00686     //I think we can just use a CGrafPort instead of casting to a WindowPtr
00687     //as in the old code
00688     //This needs to be tested.
00689     register CGrafPtr   thePort;
00690     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00691     thePort = GetQDGlobalsThePort();
00692     porigprocs = (CQDProcsPtr)GetPortGrafProcs(thePort);
00693     #else
00694     //old code
00695     register WindowPtr w = getport ();
00696     thePort = (CGrafPtr) w;
00697     porigprocs = (CQDProcs *) (*w).grafProcs; /*must chain if not nil*/
00698     #endif
00699     if (porigprocs == nil) {
00700         
00701         if (iscolorport (thePort))
00702             SetStdCProcs (&procs); /*QD fills in the record*/
00703         else
00704             SetStdProcs ((QDProcs *) &procs);
00705         }
00706     else
00707         procs = *porigprocs; /*start with current state*/
00708     
00709     #if 0 //def THINK_C
00710     
00711         procs.textProc = (QDPtr) update_stdtext; /*patch in our own procs*/
00712         
00713         procs.txMeasProc = (QDPtr) update_stdtxmeas;
00714         
00715     #else
00716     
00717         procs.textProc = update_stdtextUPP; /*patch in our own procs*/
00718         
00719         procs.txMeasProc = update_stdtxmeasUPP;
00720     
00721     #endif
00722     //Code change by Timothy Paustian Sunday, April 30, 2000 9:28:13 PM
00723     //Changed to Opaque call for Carbon
00724     //This needs to be tested.
00725     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00726     SetPortGrafProcs(thePort, &procs);
00727     #else
00728     //old code
00729     (*w).grafProcs = (QDProcs *) &procs;
00730     #endif
00731 #endif
00732     } /*pictupdatepatcher*/
00733 
00734 
00735 void pictdepatcher (void) {
00736     
00737 #ifdef MACVERSION
00738     //Code change by Timothy Paustian Sunday, April 30, 2000 9:32:15 PM
00739     //Changed to Opaque call for Carbon
00740     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00741     CGrafPtr thePort = GetQDGlobalsThePort();
00742     SetPortGrafProcs(thePort, porigprocs);
00743     #else
00744     //old code
00745     (*getport ()).grafProcs = (QDProcs *) porigprocs;
00746     #endif
00747 #endif
00748     } /*pictdepatcher*/
00749 
00750 
00751 void pictupdate (void) {
00752     
00753     register hdlpictrecord hp = pictdata;
00754     register PicHandle macpicture = (**hp).macpicture;
00755     register hdlwindowinfo hw = pictwindowinfo;
00756     register boolean flbitmap = false;
00757     register boolean fleval;
00758     Rect rcontent;
00759     Rect rframe;
00760     Rect rintersection;
00761     boolean flintersect;
00762     short extrawidth;
00763     short extraheight;
00764     
00765     rcontent = (**hw).contentrect;
00766     
00767     if (macpicture == nil) {
00768     
00769         eraserect (rcontent);
00770         
00771         return;
00772         }
00773     
00774     pictgetframerect (hp, &rframe);
00775     
00776     offsetrect (&rframe, -rframe.left, -rframe.top); /*make zero-based*/
00777     
00778     extrawidth = max (0, (rcontent.right - rcontent.left) - rframe.right);
00779     
00780     extraheight = max (0, (rcontent.bottom - rcontent.top) - rframe.bottom);
00781     
00782     offsetrect (&rframe, extrawidth / 2, extraheight / 2);
00783     
00784     offsetrect (&rframe, -(**hw).horizscrollinfo.cur, -(**hw).vertscrollinfo.cur);
00785     
00786     flintersect = intersectrect (rcontent, rframe, &rintersection);
00787     
00788     if ((**hp).flbitmapupdate) {
00789         
00790         if (flintersect) 
00791             flbitmap = openbitmap (rintersection, pictwindow);
00792         }
00793     
00794     if (!flbitmap)
00795         pushclip (rintersection);
00796     
00797     fleval = (**hp).flevalexpressions;
00798     
00799     if (fleval) 
00800         pictupdatepatcher (); /*install our quickdraw patches*/
00801     
00802     DrawPicture (macpicture, &rframe);
00803     
00804     if (fleval) 
00805         pictdepatcher (); /*de-install 'em*/
00806     
00807     if (flbitmap)
00808         closebitmap (pictwindow);
00809     else
00810         popclip ();
00811     
00812     (**hp).timelastupdate = gettickcount ();
00813     } /*pictupdate*/
00814     
00815     
00816 void pictidle (void) {
00817     
00818     register hdlpictrecord hp = pictdata;
00819     register short updateticks;
00820     
00821     updateticks = (**hp).updateticks;
00822     
00823     if (updateticks == 0) /*feature disabled for this pict*/
00824         return;
00825     
00826     if (gettickcount () > ((**hp).timelastupdate + updateticks)) 
00827         pictupdate ();
00828     } /*pictidle*/
00829 
00830 
00831 void pictdirty (void) {
00832     
00833     /*
00834     2.1b4 dmb: update timelastsave on each change
00835     */
00836     
00837     register hdlpictrecord hp = pictdata;
00838     
00839     (**hp).fldirty = true;
00840     
00841     (**hp).timelastsave = timenow (); /*modification time until saved*/
00842     } /*pictdirty*/
00843 
00844 
00845 void pictscheduleupdate (short updateseconds) {
00846     
00847     (**pictdata).updateticks = updateseconds * 60;
00848     
00849     pictdirty ();
00850     } /*pictscheduleupdate*/
00851     
00852     
00853 void pictsetbitmapupdate (boolean flbitmap) {
00854     
00855     (**pictdata).flbitmapupdate = flbitmap;
00856     
00857     pictdirty ();
00858     } /*pictsetbitmapupdate*/
00859 
00860 
00861 void pictsetevaluate (boolean flevaluate) {
00862     
00863     (**pictdata).flevalexpressions = flevaluate;
00864     
00865     pictdirty ();
00866     
00867     windowsetchanges (pictwindow, true);
00868     
00869     windowinval (pictwindow);
00870     } /*pictsetevaluate*/
00871 
00872 
00873 void pictgetnewwindowrect (hdlpictrecord hpict, Rect *rwindow) {
00874     
00875     /*
00876     a little bit of semi-dirty code that makes things nice for the user.
00877     
00878     if the pict hasn't been opened before, we custom-fit the window so that
00879     the picture fits perfectly inside it.
00880     
00881     it isn't really dirty because we follow all the rules of the shell, and
00882     it can handle any style scrollbars.
00883     */
00884     
00885     Rect r;
00886     tyconfigrecord origconfig;
00887     register short scrollbarwidth;
00888     
00889     r = (**hpict).windowrect; 
00890     
00891     if (r.top != -1) { /*it's been opened before*/
00892         
00893         *rwindow = r;
00894         
00895         return;
00896         }
00897     
00898     if (!pictgetframerect (hpict, &r)) { /*nil picture*/
00899         
00900         *rwindow = r;
00901         
00902         return;
00903         }
00904     
00905     /*it's never been opened, fit window to picture*/
00906     
00907     origconfig = config; /*we preserve this*/
00908     
00909     shellgetconfig (idpictconfig, &config);
00910     
00911     scrollbarwidth = getscrollbarwidth ();
00912     
00913     config = origconfig; /*restore*/
00914     
00915     r.right += scrollbarwidth;
00916     
00917     r.bottom += scrollbarwidth;
00918     
00919     centerrectondesktop (&r);
00920     
00921     *rwindow = r;
00922     } /*pictgetnewwindowrect*/
00923     
00924     
00925 
00926 
00927     

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