landwindow.c

Go to the documentation of this file.
00001 
00002 /*  $Id: landwindow.c 355 2005-01-11 22:48:55Z andreradke $    */
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 "landinternal.h"
00029 
00030 
00031 
00032 
00033 
00034 typedef struct tystatsrecord {
00035 
00036     long watchforthis; /*see comment in landopenstatswindow*/
00037     
00038     short lineheight;
00039     
00040     short h, v;
00041     
00042     short ctlines;
00043     
00044     byte bstitle [32];
00045     
00046     tydirection dirflush;
00047     
00048     boolean flactive: 1; /*if true the window is active, false if not*/
00049     
00050     boolean flincoming: 1; /*if true, stats shows verb being received, otherwise being sent*/
00051     
00052     tyverbclass verbclass; /*4-byte class, often same as receiver id*/
00053     
00054     tyverbtoken verbtoken; /*4-byte token, e.g. 'save', 'go  '*/
00055     
00056     tyapplicationid idother; /*signature of the sender or receiver*/
00057     
00058     short ctparams; /*number of items in the params array*/
00059     
00060     long ctverbsin; /*total number of verbs received by this app*/
00061     
00062     long ctverbsout; /*total number of verbs sent by this app*/
00063     
00064     /*remaining fields are for offscreen bitmaps*/
00065     
00066     BitMap offscreenbitmap, savedbitmap;
00067 
00068     Handle bitmapbasehandle;
00069 
00070     boolean flbitmapsenabled: 1;
00071 
00072     boolean flbitmapopen: 1;
00073     } tystatsrecord, *ptrstatsrecord, **hdlstatsrecord;
00074     
00075 
00076 static boolean landopenbitmap (void) {
00077 
00078     register hdllandglobals hg = landgetglobals ();
00079     register WindowPtr w = (**hg).statswindow;
00080     register hdlstatsrecord hstats;
00081     register short nrowbytes;
00082     register long nboxbytes;
00083     register long sizehandle;   
00084     Rect r;
00085     
00086     if (w == nil) /*defensive driving*/
00087         return (false);
00088     
00089     r = (*w).portRect;
00090     
00091     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00092     
00093     (**hstats).flbitmapopen = false;
00094     
00095     if (!(**hstats).flbitmapsenabled) /*application doesn't want any bitmaps*/
00096         return (false);
00097     
00098     nrowbytes = (r.right - r.left + 7) / 8;
00099     
00100     if ((nrowbytes % 2) == 1) /*odd number*/
00101         nrowbytes++;
00102     
00103     nboxbytes = (r.bottom - r.top) * nrowbytes;
00104     
00105     SetHandleSize ((**hstats).bitmapbasehandle, nboxbytes);
00106 
00107     sizehandle = GetHandleSize ((**hstats).bitmapbasehandle);
00108 
00109     if (sizehandle < nboxbytes) {
00110     
00111         SetHandleSize ((**hstats).bitmapbasehandle, 10L);
00112 
00113         return (false);
00114         }
00115 
00116     HLock ((**hstats).bitmapbasehandle);
00117 
00118     (**hstats).offscreenbitmap.baseAddr = *(**hstats).bitmapbasehandle;
00119 
00120     (**hstats).offscreenbitmap.rowBytes = nrowbytes;
00121 
00122     (**hstats).offscreenbitmap.bounds = r;
00123 
00124     (**hstats).savedbitmap = (*w).portBits;
00125 
00126     CopyBits (&(**hstats).savedbitmap, &(**hstats).offscreenbitmap, &r, &r, srcCopy, nil);
00127     
00128     SetPortBits (&(**hstats).offscreenbitmap);
00129     
00130     (**hstats).flbitmapopen = true; /*remember in our own local global*/
00131 
00132     return (true);
00133     } /*landopenbitmap*/
00134 
00135 
00136 static landclosebitmap (void) {
00137 
00138     register hdllandglobals hg = landgetglobals ();
00139     register WindowPtr w = (**hg).statswindow;
00140     register hdlstatsrecord hstats;
00141     
00142     if (w == nil) /*defensive driving*/
00143         return (false);
00144     
00145     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00146     
00147     if ((**hstats).flbitmapsenabled && (**hstats).flbitmapopen) {
00148         
00149         (**hstats).flbitmapopen = false;
00150         
00151         SetPortBits (&(**hstats).savedbitmap);
00152     
00153         CopyBits (
00154             &(**hstats).offscreenbitmap, &((*w).portBits), &(**hstats).offscreenbitmap.bounds, 
00155             
00156             &(**hstats).offscreenbitmap.bounds, srcCopy, nil);
00157         
00158         HUnlock ((**hstats).bitmapbasehandle);
00159         
00160         (**hstats).offscreenbitmap.baseAddr = 0;
00161         
00162         SetHandleSize ((**hstats).bitmapbasehandle, 10L);
00163         }
00164     } /*landclosebitmap*/
00165 
00166 
00167 static landinitbitmaps (void) {
00168 
00169     register hdllandglobals hg = landgetglobals ();
00170     register WindowPtr w = (**hg).statswindow;
00171     register hdlstatsrecord hstats;
00172     
00173     if (w == nil) /*defensive driving*/
00174         return (false);
00175     
00176     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00177     
00178     (**hstats).flbitmapsenabled = true;
00179     
00180     if ((**hstats).flbitmapsenabled) {
00181     
00182         (**hstats).bitmapbasehandle = NewHandle (10L); 
00183         
00184         (**hstats).offscreenbitmap.baseAddr = 0;
00185         
00186         (**hstats).offscreenbitmap.rowBytes = 2;
00187         
00188         SetRect (&(**hstats).offscreenbitmap.bounds, 0, 0, 0, 0);
00189         }
00190     } /*landinitbitmaps*/
00191 
00192 
00193 static boolean landsetstyle (fnum, fsize, fstyle, ascent, descent) short fnum, fsize, fstyle, *ascent, *descent; {
00194     
00195     FontInfo info;
00196     
00197     TextFont (fnum);
00198     
00199     TextSize (fsize);
00200     
00201     TextFace (fstyle);
00202     
00203     GetFontInfo (&info);
00204     
00205     *ascent = info.ascent;
00206     
00207     *descent = info.descent;
00208     
00209     return (true);
00210     } /*landsetstyle*/
00211 
00212 
00213 static boolean landinitstatswindow (void) {
00214     
00215     /*
00216     preserves the port, does not preserve the font/size/style of the stats
00217     window port.  doesn't preserve the pen style.
00218     */
00219 
00220     register hdllandglobals hg = landgetglobals ();
00221     register WindowPtr w = (**hg).statswindow;
00222     register hdlstatsrecord hstats;
00223     GrafPtr savedport;
00224     short ascent, descent;
00225     register short lh;
00226     register short ctvertpixels;
00227     Rect r;
00228     
00229     if (w == nil) /*defensive driving*/
00230         return (false);
00231     
00232     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00233     
00234     savedport = quickdrawglobal (thePort); /*we preserve the port*/
00235     
00236     SetPort (w);
00237     
00238     landsetstyle (geneva, 9, 0, &ascent, &descent);
00239     
00240     lh = ascent + descent + 3;
00241     
00242     (**hstats).lineheight = lh;
00243     
00244     ctvertpixels = lh * (**hstats).ctlines + (lh / 2) + 2;
00245     
00246     r = (*w).portRect;
00247     
00248     r.top += lh / 2;
00249     
00250     r.bottom -= lh / 2;
00251     
00252     r.left += 5;
00253     
00254     r.right -= 5;
00255     
00256     switch ((**hstats).dirflush) {
00257         
00258         case up: /*flush with the top of the window*/
00259             r.bottom = r.top + ctvertpixels;
00260             
00261             break;
00262         
00263         case down: /*flush with the bottom of the window*/
00264             r.top = r.bottom - ctvertpixels;
00265             
00266             break;
00267             
00268         } /*switch*/
00269     
00270     EraseRect (&r);
00271     
00272     if ((**hstats).flactive)
00273         PenPat (quickdrawglobal (gray));
00274     else
00275         PenPat (quickdrawglobal (white));
00276     
00277     MoveTo (r.left, r.top);
00278     
00279     LineTo (r.left + 8, r.top);
00280     
00281     MoveTo (r.left + 8, r.top + 3);
00282         
00283     landsetstyle (geneva, 9, bold, &ascent, &descent);
00284     
00285     DrawString ((**hstats).bstitle);
00286     
00287     MoveTo (r.left + 8 + StringWidth ((**hstats).bstitle), r.top);
00288     
00289     LineTo (r.right, r.top);
00290     
00291     LineTo (r.right, r.bottom);
00292     
00293     LineTo (r.left, r.bottom);
00294     
00295     LineTo (r.left, r.top);
00296     
00297     (**hstats).v = r.top + ascent + (lh / 2) + 2;
00298     
00299     (**hstats).h = r.left + 8;
00300     
00301     SetPort (savedport); /*restore the quickdraw port*/
00302     } /*landinitstatswindow*/
00303 
00304 
00305 pascal boolean landopenstatswindow (void) {
00306     
00307     /*
00308     after calling this guy, the Toolkit stats window is open and ready
00309     to display status information about the Toolkit layer.  the refcon
00310     of this window points to a statsrecord.
00311     
00312     if you're running thru your window list and come across a refcon whose
00313     first four bytes are 'LAND' -- it's our window, not one of yours.
00314     */
00315     
00316     register hdllandglobals hg = landgetglobals ();
00317     register WindowPtr w = (**hg).statswindow;
00318     hdlstatsrecord hstats;
00319     bigstring bs;
00320     Rect r;
00321     
00322     if (w != nil) { /*window is already open*/
00323         
00324         SelectWindow (w);
00325         
00326         return (true);
00327         }
00328     
00329     if (!landnewclearhandle (longsizeof (tystatsrecord), (Handle *) &hstats))
00330         return (false);
00331     
00332     SetRect (&r, 100, 100, 425, 210);
00333     
00334     landcopystring ("\pUserLand IAC Toolkit", bs);
00335     
00336     w = NewWindow (nil, &r, bs, false, noGrowDocProc, (WindowPtr) -1, true, 0);
00337     
00338     if (w == nil) { /*failed to allocate window*/
00339         
00340         landdisposehandle ((Handle) hstats);
00341         
00342         return (false);
00343         }
00344         
00345     (**hg).statswindow = w;
00346     
00347     (*(WindowPeek) w).refCon = (long) hstats; /*window points at stats record*/
00348     
00349     (**hstats).watchforthis = 'LAND';
00350     
00351     (**hstats).flactive = true;
00352     
00353     landinitbitmaps ();
00354     
00355     ShowWindow (w);
00356     
00357     return (true);
00358     } /*landopenstatswindow*/
00359 
00360 
00361 pascal boolean landclosestatswindow (void) {
00362 
00363     register hdllandglobals hg = landgetglobals ();
00364     register WindowPtr w = (**hg).statswindow;
00365 
00366     if (w == nil) /*it's already closed*/
00367         return (true);
00368     
00369     landdisposehandle ((Handle) (*(WindowPeek) w).refCon);
00370     
00371     DisposeWindow (w);
00372     
00373     (**hg).statswindow = nil;
00374     
00375     return (true);
00376     } /*landclosestatswindow*/
00377 
00378 
00379 pascal boolean landisstatswindow (WindowPtr w) {
00380     
00381     /*
00382     return true if it's the stats window.  this is part of the Toolkit API because
00383     applications will encounter our window in a traversal of its window list.  if we
00384     return true it definitely is the stats window, and the application should make
00385     no assumptions about the handle hanging off the refcon field of the window.
00386     */
00387     
00388     register hdllandglobals hg = landgetglobals ();
00389     register WindowPtr statswindow = (**hg).statswindow;
00390 
00391     if (statswindow == nil) /*the stats window isn't open*/
00392         return (false);
00393     
00394     return (w == statswindow);
00395     } /*landisstatswindow*/
00396 
00397 
00398 boolean landstatswindowisopen (void) {
00399 
00400     register hdllandglobals hg = landgetglobals ();
00401     
00402     return ((**hg).statswindow != nil);
00403     } /*landstatswindowisopen*/
00404 
00405 
00406 static boolean landstatswindowline (bigstring bs) {
00407 
00408     register hdllandglobals hg = landgetglobals ();
00409     register WindowPtr w = (**hg).statswindow;
00410     register hdlstatsrecord hstats;
00411     GrafPtr savedport;
00412     short ascent, descent;
00413 
00414     if (w == nil) /*defensive driving*/
00415         return (false);
00416     
00417     savedport = quickdrawglobal (thePort); /*we preserve the port*/
00418     
00419     SetPort (w);
00420     
00421     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00422 
00423     landsetstyle (geneva, 9, 0, &ascent, &descent);
00424     
00425     MoveTo ((**hstats).h, (**hstats).v);
00426     
00427     DrawString (bs);
00428     
00429     (**hstats).v += (**hstats).lineheight;
00430     
00431     SetPort (savedport);
00432     
00433     return (true);
00434     } /*landstatswindowline*/
00435 
00436 
00437 static boolean landupdatestatswindow (void) {
00438 
00439     register hdllandglobals hg = landgetglobals ();
00440     register WindowPtr w = (**hg).statswindow;
00441     register hdlstatsrecord hstats;
00442     bigstring bs, bsid;
00443     
00444     if (w == nil) /*defensive driving*/
00445         return (false);
00446     
00447     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00448     
00449     /*top half of window*/ {
00450     
00451         (**hstats).dirflush = up;
00452         
00453         (**hstats).ctlines = 2;
00454         
00455         landcopystring ("\pIAC Messages:", (**hstats).bstitle);
00456             
00457         landinitstatswindow ();
00458         
00459         /*line #1*/ {
00460         
00461             landcopystring ("\pLast message was '", bs);
00462             
00463             land4bytestostring ((**hstats).verbclass, bsid);
00464             
00465             landpushstring (bsid, bs);
00466             
00467             landpushstring ("\p.", bs);
00468             
00469             land4bytestostring ((**hstats).verbtoken, bsid);
00470             
00471             landpushstring (bsid, bs);
00472             
00473             landpushstring ("\p' ", bs);
00474             
00475             if ((**hstats).flincoming)
00476                 landpushstring ("\p received", bs);
00477             else
00478                 landpushstring ("\p sent", bs);
00479         
00480             landpushstring ("\p with ", bs);
00481             
00482             landpushlong ((long) (**hstats).ctparams, bs);
00483             
00484             landpushstring ("\p params.", bs);
00485         
00486             landstatswindowline (bs);
00487             } /*line #1*/
00488             
00489         /*line #2*/ {
00490         
00491             setemptystring (bs);
00492             
00493             landpushlong ((**hstats).ctverbsout, bs);
00494             
00495             landpushstring ("\p verbs sent; ", bs);
00496             
00497             landpushlong ((**hstats).ctverbsin, bs);
00498             
00499             landpushstring ("\p verbs received.", bs);
00500             
00501             landstatswindowline (bs);
00502             } /*line #2*/
00503         } /*top half of stats window*/
00504 
00505     /*bottom half of stats window*/ {
00506     
00507         (**hstats).dirflush = down;
00508         
00509         (**hstats).ctlines = 2;
00510         
00511         landcopystring ("\pSystem Info:", (**hstats).bstitle);
00512         
00513         landinitstatswindow ();
00514         
00515         /*line #1*/ {
00516             register long freemem = FreeMem ();
00517             
00518             setemptystring (bs);
00519             
00520             landpushlong (freemem / 1024, bs);
00521             
00522             landpushstring ("\pK free; ", bs);
00523             
00524             landpushlong ((**hg).initialfreemem - freemem, bs);
00525             
00526             landpushstring ("\p bytes difference since LandInit.", bs);
00527             
00528             landstatswindowline (bs);
00529             }
00530             
00531         /*line #2*/ {
00532 
00533             setemptystring (bs);
00534             
00535             landpushstring ("\pIAC name = '", bs);
00536             
00537             land4bytestostring ((**hg).applicationid, bsid);
00538             
00539             landpushstring (bsid, bs);
00540             
00541             if ((**hg).transport == macsystem6) {
00542             
00543                 landpushstring ("\p'; max queue depth = ", bs);
00544             
00545                 landpushlong ((long) (**hg).maxqueuedepth, bs);
00546             
00547                 landpushstring ("\p.", bs);
00548                 }
00549             
00550             landstatswindowline (bs);
00551             }
00552         } /*bottom half of window*/
00553     
00554     return (true);  
00555     } /*landupdatestatswindow*/
00556 
00557 
00558 static boolean landbitmapupdate (void) {
00559     
00560     register hdllandglobals hg = landgetglobals ();
00561     register WindowPtr w = (**hg).statswindow;
00562     GrafPtr savedport;
00563 
00564     savedport = quickdrawglobal (thePort); /*we preserve the port*/
00565     
00566     SetPort (w);
00567     
00568     landopenbitmap ();
00569     
00570     landupdatestatswindow ();
00571     
00572     landclosebitmap ();
00573     
00574     SetPort (savedport);
00575     
00576     return (true);
00577     } /*landbitmapupdate*/
00578 
00579 
00580 boolean landsetstatsinfo (hdlverbrecord hverb, boolean flincoming) {
00581 
00582     register hdllandglobals hg = landgetglobals ();
00583     register WindowPtr w = (**hg).statswindow;
00584     register hdlstatsrecord hstats;
00585     register hdlverbrecord hv = hverb;
00586     
00587     if (w == nil) /*defensive driving*/
00588         return (false);
00589     
00590     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00591     
00592     (**hstats).verbclass = (**hv).verbclass;
00593     
00594     (**hstats).verbtoken = (**hv).verbtoken;
00595     
00596     (**hstats).flincoming = flincoming;
00597     
00598     if (flincoming) {
00599     
00600         (**hstats).idother = (**hv).idsender;
00601         
00602         (**hstats).ctverbsin++;
00603         }
00604     else {
00605     
00606         (**hstats).idother = (**hv).idreceiver;     
00607         
00608         (**hstats).ctverbsout++;
00609         }
00610 
00611     (**hstats).ctparams = (**hv).ctparams;
00612         
00613     landbitmapupdate ();
00614     
00615     return (true);
00616     } /*landsetstatsinfo*/
00617 
00618 
00619 landsetmemstats (void) {
00620 
00621     register hdllandglobals hg = landgetglobals ();
00622 
00623     (**hg).initialfreemem = FreeMem (); /*after everything alloc'd, for stats window*/
00624     } /*landsetmemstats*/
00625 
00626 
00627 static landwindowmousedown (EventRecord *ev) {
00628 
00629     register short part;
00630     WindowPtr w;
00631     
00632     part = FindWindow ((*ev).where, &w);
00633     
00634     if (w != nil) {
00635     
00636         if (w != FrontWindow ()) { /*just like all other Mac programs*/
00637             
00638             SelectWindow (w);
00639                             
00640             return (true); 
00641             }
00642         }
00643     
00644     switch (part) {
00645     
00646         case inGoAway:
00647             if (TrackGoAway (w, (*ev).where)) 
00648                 landclosestatswindow ();
00649                                 
00650             break;
00651             
00652         case inDrag: {
00653             Rect r;
00654 
00655             r = quickdrawglobal (screenBits).bounds; 
00656             
00657             r.top += GetMBarHeight (); 
00658             
00659             r.left += 4;
00660             
00661             r.right -= 4;
00662             
00663             r.bottom -= 4;
00664             
00665             DragWindow (w, (*ev).where, &r);
00666             }
00667         } /*switch*/
00668         
00669     return (true);
00670     } /*landwindowmousedown*/
00671 
00672 
00673 static boolean landactivatestatswindow (boolean flactive) {
00674 
00675     register hdllandglobals hg = landgetglobals ();
00676     register WindowPtr w = (**hg).statswindow;
00677     register hdlstatsrecord hstats;
00678     
00679     if (w == nil) /*defensive driving*/
00680         return (false);
00681     
00682     hstats = (hdlstatsrecord) (*(WindowPeek) w).refCon;
00683     
00684     (**hstats).flactive = flactive;
00685     
00686     landbitmapupdate ();
00687     
00688     return (true);
00689     } /*landactivatestatswindow*/
00690 
00691 
00692 boolean landwindoweventfilter (EventRecord *ev) {
00693     
00694     /*
00695     return true if we consume the event.
00696     */
00697 
00698     register hdllandglobals hg = landgetglobals ();
00699     register WindowPtr w = (**hg).statswindow;
00700     register WindowPtr eventwindow = (WindowPtr) (*ev).message;
00701     
00702     if (w == nil) /*there is no stats window, event can't be for us*/
00703         return (false);
00704         
00705     if (eventwindow == nil) { /*it's nil if it's a mousedown in closebox, at least*/
00706         
00707         WindowPtr x;
00708         
00709         FindWindow ((*ev).where, &x);
00710         
00711         eventwindow = x;
00712         }
00713         
00714     if (eventwindow != w) /*the event is for another window*/
00715         return (false);
00716         
00717     if (w == FrontWindow ()) /*we always have an arrow cursor*/
00718         landsetcursortype (0);
00719     
00720     switch ((*ev).what) {
00721     
00722         case mouseDown:
00723             landwindowmousedown (ev);
00724             
00725             return (true); 
00726             
00727         case updateEvt:
00728             BeginUpdate (w);
00729             
00730             landupdatestatswindow ();
00731             
00732             EndUpdate (w);
00733             
00734             return (true); 
00735             
00736         case activateEvt:
00737             landactivatestatswindow ((*ev).modifiers & activeFlag);
00738             
00739             return (true);
00740         } /*switch*/
00741     
00742     return (false); /*don't consume the event*/
00743     } /*landwindoweventfilter*/
00744 
00745 
00746 

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