zoom.c

Go to the documentation of this file.
00001 
00002 /*  $Id: zoom.c 1208 2006-04-05 23:51:45Z 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 "quickdraw.h"
00032 #include "cursor.h"
00033 #include "ops.h"
00034 #include "dialogs.h"
00035 #include "zoom.h"
00036 #include "shell.h"
00037 #include "shellprivate.h"
00038 
00039 
00040 
00041 static long ctzoomdelayloops = 0;
00042 
00043 static Rect rdefaultzoomfrom = {0, 0, 0, 0};
00044 
00045 #define zoomfixer 65536L
00046 
00047 static short zoomsteps = 14; /*decrease this number for faster zooming*/
00048 
00049 static Point zoomratio = {5, 6}; /*must adjust to work with zoomsteps*/
00050 
00051 Fixed zoomfract;
00052 
00053 
00054 
00055 
00056 void zoomsetdefaultrect (WindowPtr w, Rect r) {
00057     
00058     rdefaultzoomfrom = r;
00059     
00060     localtoglobalrect (w, &rdefaultzoomfrom);
00061     } /*zoomsetdefaultrect*/
00062 
00063 
00064 /*
00065 void middlerect (Rect rorig, Rect *rmiddle) {
00066     
00067     /%
00068     compute a rectangle which is at or near the center of rorig of 
00069     minimum dimensions.
00070     %/
00071     
00072     Rect r;
00073     
00074     r.left = r.right = rorig.left + ((rorig.right - rorig.left) / 2);
00075     
00076     r.top = r.bottom = rorig.top + ((rorig.bottom - rorig.top) / 2);
00077     
00078     *rmiddle = r; /%return value%/
00079     } /%middlerect%/
00080 */
00081 
00082 
00083 static short zoomblend (short i1, short i2) {
00084 
00085     Fixed smallfix, bigfix, tempfix;
00086 
00087     smallfix = zoomfixer * i1;
00088     
00089     bigfix = zoomfixer * i2;
00090     
00091     tempfix = FixMul (zoomfract, bigfix) + FixMul (zoomfixer - zoomfract, smallfix);
00092     
00093     return (FixRound (tempfix));
00094     } /*zoomblend*/
00095     
00096 
00097 void zoomrect (Rect *rfrom, Rect *rto, boolean flzoomup) {
00098     
00099     /*
00100     11/16/90 DW: try to smooth out performance even on the fastest machines.
00101     
00102     9/16/91 dmb: compare rfrom.top to -1, not < 0; negative numbers can 
00103     be ligitimate when mutliple monitors are in use. 
00104     
00105     also, don't constrain rects to desktop, since we might want to zoom to the 
00106     menubar.
00107     
00108     12/27/91 dmb: don't do zoomrect if frontier isn't the frontmost app
00109     */
00110     register short i;
00111     Fixed factor;
00112     Rect rect1, rect2, rect3, rect4;
00113     //Code change by Timothy Paustian Friday, May 5, 2000 10:27:35 PM
00114     //Changed to Opaque call for Carbon
00115     //can't use GrafPorts, have to use the ptrs
00116     //This stuff isn't called in the PPC OT version
00117     CGrafPtr deskport;
00118 
00119 
00120     return;     // kw - 2005-12-20 - killing zoomrects
00121 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00122     deskport = CreateNewPort();
00123 #else
00124     deskport = NewPtr(sizeof(CGrafPort));
00125 #endif
00126     
00127     
00128     if (!shellisactive ()) /*we're not front app*/
00129         return;
00130     
00131     if (!pushdesktopport (deskport)) /*failed to open up a port on the whole desktop*/
00132         return;
00133     
00134     if ((*rfrom).top == -1) /*caller wants us to use the default rect*/
00135         rfrom = &rdefaultzoomfrom;
00136     
00137     /*
00138     constraintodesktop (rfrom); 
00139     
00140     constraintodesktop (rto);
00141     */
00142     
00143     pushpen ();
00144     
00145     setgraypen ();
00146     
00147     PenMode (patCopy);// (patXor);
00148     
00149     if (flzoomup) {
00150     
00151         rect1 = *rfrom;
00152         
00153         factor = FixRatio (zoomratio.h, zoomratio.v);
00154         
00155         zoomfract = FixRatio (541, 10000);
00156         }
00157     else {
00158         rect1 = *rto;
00159         
00160         factor = FixRatio (zoomratio.v, zoomratio.h);
00161         
00162         zoomfract = zoomfixer;
00163         }
00164         
00165     rect2 = rect1;
00166     
00167     rect3 = rect1;
00168     
00169     framerect (rect1);
00170     
00171     for (i = 1; i <= zoomsteps; i++) {
00172         
00173         burntickloops (ctzoomdelayloops);
00174         
00175         rect4.left = zoomblend ((*rfrom).left, (*rto).left);
00176         
00177         rect4.right = zoomblend ((*rfrom).right, (*rto).right);
00178         
00179         rect4.top = zoomblend ((*rfrom).top, (*rto).top);
00180         
00181         rect4.bottom = zoomblend ((*rfrom).bottom, (*rto).bottom);
00182         
00183         framerect (rect4);
00184         
00185         framerect (rect1);
00186         
00187         rect1 = rect2;
00188         
00189         rect2 = rect3;
00190         
00191         rect3 = rect4;
00192          
00193         zoomfract = FixMul (zoomfract,factor);
00194         } /*for*/
00195         
00196     framerect (rect1);
00197     
00198     framerect (rect2);
00199     
00200     framerect (rect3);
00201     
00202     poppen ();
00203     
00204     popdesktopport (deskport); //July 4, 2000 AR: was a pointer to deskport
00205     //Code change by Timothy Paustian Sunday, May 21, 2000 9:33:21 PM
00206     //Not called in the PPC OT version.
00207     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00208     //DisposePort(deskport); /*popdesktopport disposes deskport -- site of crashing bug.*/
00209     #else
00210     DisposePtr(deskport);
00211     #endif
00212     } /*zoomrect*/
00213     
00214     
00215 /*
00216 void zoomfrommiddle (Rect r) {
00217     
00218     Rect rmiddle;
00219     
00220     middlerect (r, &rmiddle);
00221     
00222     zoomrect (&rmiddle, &r, true);
00223     } /%zoomfrommiddle%/
00224 */  
00225 
00226 void zoomport (Rect rsource, WindowPtr w, boolean flzoomup) {
00227 #if TARGET_API_MAC_CARBON == 1
00228 #   pragma unused(rsource)
00229 #   pragma unused(w)
00230 #   pragma unused(flzoomup)
00231 #endif
00232 
00233     /*
00234     zooms the window from an invisible state to a visible 
00235     state (flzoomup == true) or vice versa (flzoomup == false).
00236     
00237     rsource is the place where the window "came from" -- ie
00238     if you're opening an about box, the source is a position
00239     just below the Apple menu.
00240     
00241     7.0b41 PBS: don't zoom in Carbon version.
00242     
00243     8.0fc3 PBS: Again, don't zoom in Carbon version.
00244     */
00245     
00246     #if TARGET_API_MAC_CARBON == 1 /*8.0fc3 PBS: don't zoom in Carbon.*/
00247     
00248         return;
00249         
00250     #else
00251 
00252     Rect rsmall, rbig;
00253     //Code change by Timothy Paustian Sunday, May 21, 2000 9:34:22 PM
00254     //Changed to Opaque call for Carbon
00255     //Not called in the PPC OT Version.
00256     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00257     GetWindowBounds(w, kWindowContentRgn, &rbig);
00258     #else
00259     rbig = w->portRect;
00260     #endif
00261     rsmall = rbig;
00262     
00263     insetrect (&rsmall, (rbig.right - rbig.left + 20) / 2, (rbig.bottom - rbig.top + 20) / 2);
00264     
00265     localtoglobalrect (w, &rsmall);
00266     
00267     localtoglobalrect (w, &rbig);
00268     
00269     if (flzoomup) {
00270     
00271         zoomrect (&rsource, &rsmall, true);
00272         
00273         zoomrect (&rsmall, &rbig, true);
00274         }
00275     else {
00276         zoomrect (&rsmall, &rbig, false);
00277         
00278         zoomrect (&rsource, &rsmall, false);
00279         }
00280     
00281     #endif
00282     } /*zoomport*/
00283 
00284 
00285 void zoomwindowfrom (Rect rsource, WindowPtr w) {
00286 
00287     /*
00288     animate the opening of a window.
00289     
00290     you tell us where you want the window to appear to be coming from.
00291     */
00292     
00293     //Code change by Timothy Paustian Monday, August 21, 2000 4:31:49 PM
00294     //Must pass a CGrafPtr to pushport on OS X to avoid a crash
00295     {
00296     CGrafPtr    thePort;
00297     #if TARGET_API_MAC_CARBON == 1
00298     thePort = GetWindowPort(w);
00299     #else
00300     thePort = (CGrafPtr)w;
00301     #endif
00302         
00303     pushport (thePort);
00304     }
00305     
00306     zoomport (rsource, w, true);
00307     
00308     ShowWindow (w);
00309     
00310     popport ();
00311     } /*zoomwindowfrom*/
00312     
00313     
00314 void zoomwindowto (Rect rsource, WindowPtr w) {
00315 
00316     /*
00317     animate the closing of a window.
00318     
00319     you tell us where you want the window to appear to be going to.
00320     */
00321     
00322     //Code change by Timothy Paustian Monday, August 21, 2000 4:31:49 PM
00323     //Must pass a CGrafPtr to pushport on OS X to avoid a crash
00324     {
00325     CGrafPtr    thePort;
00326     #if TARGET_API_MAC_CARBON == 1
00327     thePort = GetWindowPort(w);
00328     #else
00329     thePort = (CGrafPtr)w;
00330     #endif
00331         
00332     pushport (thePort);
00333     }
00334     
00335     HideWindow (w);
00336     
00337     zoomport (rsource, w, false);
00338     
00339     popport ();
00340     } /*zoomwindowto*/
00341     
00342 
00343 void zoomcenterrect (Rect *rcenter) {
00344     
00345     Rect r;
00346     
00347     r = *rcenter;
00348     
00349     r.left += (r.right - r.left) / 2;
00350     
00351     r.right = r.left;
00352     
00353     r.top += (r.bottom - r.top) / 2;
00354     
00355     r.bottom = r.top;
00356     
00357     *rcenter = r;
00358     } /*zoomcenterrect*/
00359     
00360 
00361 void zoomwindowtocenter (Rect r, WindowPtr w) {
00362     
00363     /*
00364     shrink the rectangle down to the point at its center and zoom the window
00365     down to that point.
00366     */
00367     
00368     if (r.top > 0) /*don't smash it if it's the default rect*/
00369         zoomcenterrect (&r);
00370     
00371     zoomwindowto (r, w);
00372     } /*zoomwindowtocenter*/
00373     
00374 
00375 void zoomwindowfromcenter (Rect r, WindowPtr w) {
00376     
00377     /*
00378     shrink the rectangle down to the point at its center and zoom the window
00379     up from that point.
00380     */
00381     
00382     if (r.top > 0) /*don't smash it if it's the default rect*/
00383         zoomcenterrect (&r);
00384     
00385     zoomwindowfrom (r, w);
00386     } /*zoomwindowfromcenter*/
00387     
00388 
00389 void zoomfromorigin (WindowPtr w) {
00390     
00391     Rect r;
00392     
00393     r.top = r.left = r.bottom = r.right = 0;
00394     
00395     zoomwindowfrom (r, w);
00396     } /*zoomfromorigin*/
00397     
00398 
00399 void zoomtoorigin (WindowPtr w) {
00400     
00401     Rect r;
00402     
00403     r.top = r.left = r.bottom = r.right = 0;
00404     
00405     zoomwindowto (r, w);
00406     } /*zoomtoorigin*/
00407     
00408 /*
00409 boolean zoomtempwindow (boolean flzoom, short height, short width, WindowPtr *w) {
00410     
00411     /%
00412     a temp window is like the one used in the About... command.
00413     
00414     10/18/91 DW: color!
00415     %/
00416     
00417     register WindowPtr x;
00418     Rect r, rsource;
00419     
00420     /%
00421     SetRect (&r, 0, 0, width, height);
00422     
00423     x = NewWindow (nil, &r, zerostring, false, altDBoxProc, (WindowPtr) -1L, false, 0);
00424     
00425     if (x == nil) {
00426         
00427         sysbeep (); 
00428         
00429         return;
00430         }
00431     %/
00432     
00433     if (!newcolorwindow (height, width, w)) {
00434     
00435         sysbeep (); /%instead of showing window%/
00436         
00437         return (false);
00438         }
00439     
00440     x = *w; /%copy into register%/
00441     
00442     pushport (x);
00443     
00444     positiondialogwindow (x);
00445     
00446     if (flzoom) {
00447     
00448         getsystemoriginrect (&rsource);
00449     
00450         zoomwindowfrom (rsource, x);
00451         }
00452     else
00453         ShowWindow (x);
00454     
00455     *w = x; /%return pointer to window record%/
00456     
00457     return (true);
00458     } /%zoomtempwindow%/
00459     
00460     
00461 void closetempwindow (boolean flzoom, WindowPtr w) {
00462 
00463     register WindowPtr x = w;
00464     Rect rsource;
00465     
00466     if (x != nil) {
00467         
00468         getsystemoriginrect (&rsource);
00469         
00470         if (flzoom) 
00471             zoomwindowto (rsource, x);
00472         else
00473             HideWindow (x);
00474         
00475         DisposeWindow (x);
00476         
00477         popport ();
00478         }
00479     } /%closetempwindow%/
00480 
00481 
00482 void modaltempwindow (WindowPtr w, void (*updateproc) ()) {
00483     
00484     register WindowPtr x = w; 
00485     EventRecord ev;
00486     
00487     setcursortype (cursorisarrow);
00488     
00489     while (true) {
00490         
00491         SystemTask ();
00492         
00493         if (!GetNextEvent (everyEvent, &ev))
00494             continue;
00495             
00496         switch (ev.what) {
00497         
00498             case keyDown: case autoKey: case mouseDown:     
00499                 return;
00500                 
00501             case updateEvt: /%handle updates, he might be using Pyro!%/
00502                 if ((WindowPtr) (ev.message) == x) {
00503                 
00504                     pushport (x);
00505                     
00506                     BeginUpdate (x);
00507                     
00508                     (*updateproc) (x);
00509                     
00510                     EndUpdate (x);
00511                     
00512                     popport ();
00513                     }
00514                                     
00515                 break;
00516 
00517             } /%switch%/
00518         } /%while%/
00519     } /%modaltempwindow%/
00520 */
00521     
00522 
00523 void zoominit (void) {
00524     
00525     counttickloops (&ctzoomdelayloops);
00526     
00527     ctzoomdelayloops /= 6; /*burn a sixth of a tick each iteration of the loop*/
00528     
00529     if (ctzoomdelayloops < 60) { /*we're on a slow machine*/
00530         
00531         ctzoomdelayloops = 0;
00532         
00533         zoomsteps = 7;
00534         
00535         zoomratio.h = 32;
00536         
00537         zoomratio.v = 21;
00538         }
00539     } /*zoominit*/

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