windoidWDEF.c

Go to the documentation of this file.
00001 
00002 /*  $Id: windoidWDEF.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 /*
00029 
00030 wdef.c  
00031 
00032 Windoids wdef for PowWow
00033 
00034 Variants for this wdef:
00035     
00036      0:    Has a grow zone (and drawgrowicon is implemented).  Does not have rotating states.
00037      1:    (not used)
00038      2:    Has no grow zone.  Has rotating states.
00039     
00040 
00041 Copyright 1989 Peter Winer
00042 
00043 Peter Winer
00044 894 Parma Way
00045 Los Altos, CA 94024
00046 (415) 948 7142
00047 
00048 Revision History:
00049 
00050 05-16-89        PWW     Creation
00051 
00052 */
00053 
00054 #include <Quickdraw.h>
00055 #include <Windows.h>
00056 #include <Fonts.h>
00057 #include <Memory.h>
00058 #include <ToolUtils.h>
00059 
00060 #include <Types.h>
00061 #include <OSUtils.h>
00062 #include <Events.h>
00063 #include <Windows.h>
00064 #include <StdLib.h>
00065 #include <SANE.h>
00066 
00067 /*
00068 constants
00069 */
00070     #define kDragHeight     15
00071 
00072 /*
00073 types
00074 */
00075 
00076     typedef struct tywindrects {
00077         Rect dragrect;
00078         Rect closerect;
00079     } tywindrects, *typtrwindrects, **tyhdlwindrects;
00080         
00081     typedef Rect *typtrrect;
00082         
00083 
00084 /*
00085 prototypes
00086 */
00087 
00088     void drawtitle (
00089         WindowPtr w,
00090         Rect r);
00091     
00092     void filltitlebar (
00093         WindowPeek peekptr,
00094         short varcode,
00095         short flhilited);
00096     
00097     void tracestrucrgn (
00098         WindowPeek peekptr,
00099         Rect r);
00100     
00101     void docalc (
00102         WindowPeek peekptr);
00103         
00104     void dodraw (
00105         WindowPeek peekptr,
00106         short varcode,
00107         long param);
00108     
00109     void calcgrow (
00110         WindowPtr w,
00111         Rect *r);
00112     
00113     long dohit (
00114         WindowPeek peekptr, 
00115         short varcode,
00116         long param);
00117     
00118     void dogrow (
00119         short varcode,
00120         long param);
00121     
00122     void dodrawgrowicon (
00123         WindowPeek peekptr,
00124         short varcode);
00125     
00126     void donew (
00127         WindowPeek peekptr);    
00128     
00129     void dodispose (
00130         WindowPeek peekptr);
00131     
00132     pascal long winddef (
00133         short varcode,
00134         WindowPeek peekptr,
00135         short message,
00136         long param);
00137 
00138 
00139 pascal long main (
00140     short varcode,
00141     WindowPeek peekptr,
00142     short message,
00143     long param) {
00144 
00145     switch (message) {
00146             
00147         case wDraw:
00148             dodraw (peekptr, varcode, param);
00149 
00150             break;
00151         
00152         case wHit: 
00153             return (dohit (peekptr, varcode, param));
00154             
00155             break;
00156             
00157         case wCalcRgns: 
00158             docalc (peekptr);
00159             
00160             break;
00161             
00162         case wNew: 
00163             donew (peekptr);
00164             
00165             break;
00166             
00167         case wDispose: 
00168             dodispose (peekptr);
00169             
00170             break;
00171             
00172         case wGrow:
00173             dogrow (varcode, param);
00174             
00175             break;
00176             
00177         case wDrawGIcon:
00178             dodrawgrowicon (peekptr, varcode);
00179             
00180             break;
00181             
00182         } /* switch */
00183 
00184     return (0);
00185     } /* main */
00186 
00187 
00188 static short odd (i)
00189     short i; {
00190     
00191     return (i % 2);
00192     } /* odd */
00193 
00194 
00195 static void localtoglobalrect (r)
00196     Rect *r; {
00197     
00198     LocalToGlobal ((Point *) r);
00199     
00200     LocalToGlobal ((Point *) r + 1);
00201     
00202     /*
00203     Point pttemp;
00204     
00205     pttemp.h = (*r).left;
00206     
00207     pttemp.v = (*r).top;
00208     
00209     LocalToGlobal (&pttemp);
00210     
00211     (*r).left = pttemp.h;
00212     
00213     (*r).top = pttemp.v;
00214     
00215     pttemp.h = (*r).right;
00216     
00217     pttemp.v = (*r).bottom;
00218     
00219     LocalToGlobal (&pttemp);
00220     
00221     (*r).right = pttemp.h;
00222     
00223     (*r).bottom = pttemp.v;
00224     */
00225     } /* localtoglobalrect */
00226     
00227     
00228 static void globaltolocalrect (r)
00229     Rect *r; {
00230     
00231     GlobalToLocal ((Point *) r);
00232     
00233     GlobalToLocal ((Point *) r + 1);
00234     
00235     /*
00236     Point pttemp;
00237     
00238     pttemp.h = (*r).left;
00239     
00240     pttemp.v = (*r).top;
00241     
00242     GlobalToLocal (&pttemp);
00243     
00244     (*r).left = pttemp.h;
00245     
00246     (*r).top = pttemp.v;
00247     
00248     pttemp.h = (*r).right;
00249     
00250     pttemp.v = (*r).bottom;
00251     
00252     GlobalToLocal (&pttemp);
00253     
00254     (*r).right = pttemp.h;
00255     
00256     (*r).bottom = pttemp.v;
00257     */
00258     } /* globaltolocalrect */
00259     
00260     
00261 static void drawtitle (
00262     WindowPtr w,
00263     Rect r) {
00264     
00265     /*
00266     Str255 bstitle;
00267     */
00268     StringHandle htitle;
00269     FontInfo charset;
00270     short hcoord;
00271     short vcoord;
00272     short savefont;
00273     short savesize;
00274     short saveface;
00275     WindowPtr currentport;
00276     
00277     /*
00278     GetWTitle (w, bstitle);
00279     */
00280     
00281     htitle = (*(WindowPeek) htitle).titleHandle;
00282     
00283     GetPort (&currentport);
00284     
00285     savefont = (*currentport).txFont;
00286     
00287     savesize = (*currentport).txSize;
00288     
00289     saveface = (*currentport).txFace;
00290         
00291     TextFont (geneva);
00292     
00293     TextSize (9);
00294     
00295     TextFace (0);
00296     
00297     GetFontInfo (&charset);
00298     
00299     HLock ((Handle) htitle);
00300     
00301     hcoord = r.right - r.left - StringWidth (*htitle);
00302     
00303     
00304     hcoord = hcoord >> 1;
00305     
00306     hcoord += r.left;
00307     
00308     vcoord = r.bottom - r.top - charset.ascent - charset.descent;
00309     
00310     vcoord = vcoord >> 1;
00311     
00312     vcoord += r.top + charset.ascent;
00313     
00314     r.top = vcoord - charset.ascent;
00315     
00316     r.bottom = vcoord + charset.descent;
00317     
00318     r.left = hcoord;
00319     
00320     r.right = hcoord + StringWidth (*htitle);
00321         
00322     InsetRect (&r, -2, 0);
00323     
00324     EraseRect (&r);
00325     
00326     MoveTo (hcoord, vcoord);
00327     
00328     DrawString (*htitle);
00329     
00330     HUnlock ((Handle) htitle);
00331     
00332     (*currentport).txFont = savefont;
00333     
00334     (*currentport).txSize = savesize;
00335     
00336     (*currentport).txFace = saveface;
00337     } /* drawtitle */
00338     
00339     
00340 static void filltitlebar (
00341     WindowPeek peekptr,
00342     short varcode,
00343     short flhilited) {
00344 
00345     #pragma unused (varcode)
00346     
00347     Pattern pat;
00348     tyhdlwindrects hdlwindrects;
00349     Rect r;
00350         
00351     hdlwindrects = (tyhdlwindrects) (*peekptr).dataHandle;
00352     
00353     HLock ((*peekptr).dataHandle);
00354     
00355     r = (**hdlwindrects).dragrect;
00356         
00357     if (!flhilited) {
00358         FrameRect (&r);
00359         
00360         InsetRect (&r, 1, 1);
00361         
00362         EraseRect (&r);
00363         
00364         HUnlock ((*peekptr).dataHandle);
00365 
00366         return;
00367         }
00368         
00369     if (odd (r.top)) {
00370         if (odd (r.left))
00371             StuffHex (&pat, "\p0055005500550055");
00372         else 
00373             StuffHex (&pat, "\p00AA00AA00AA00AA");
00374         }
00375     else {
00376         if (odd (r.left))
00377             StuffHex (&pat, "\p5500550055005500");
00378         else 
00379             StuffHex (&pat, "\pAA00AA00AA00AA00");
00380         }
00381         
00382     InsetRect (&r, 1, 1);
00383 
00384     FillRect (&r, pat);
00385 
00386     FrameRect (&(**hdlwindrects).dragrect);
00387                         
00388     EraseRect (&(**hdlwindrects).closerect);
00389 
00390     FrameRect (&(**hdlwindrects).closerect);
00391     
00392     HUnlock ((*peekptr).dataHandle);
00393     } /*filltitlebar*/
00394     
00395 
00396 static void tracestrucrgn (
00397     WindowPeek peekptr,
00398     Rect r) {
00399     
00400     /*
00401     12/10/91 dmb: rewrote using rect/union rgn instead of open/close rgn
00402     */
00403     
00404     register RgnHandle strucrgn = (*peekptr).strucRgn;
00405     register RgnHandle temprgn = NewRgn ();
00406     
00407     RectRgn (strucrgn, &r);
00408     
00409     OffsetRect (&r, 1, 1);
00410     
00411     RectRgn (temprgn, &r);
00412     
00413     UnionRgn (temprgn, strucrgn, strucrgn);
00414     
00415     DisposeRgn (temprgn);
00416     
00417     /*
00418     OpenRgn ();
00419     
00420     MoveTo (r.left, r.top);
00421     
00422     LineTo (r.right - 1, r.top);
00423     
00424     LineTo (r.right - 1, r.top + 2);
00425     
00426     LineTo (r.right, r.top + 2);
00427     
00428     LineTo (r.right, r.bottom);
00429     
00430     LineTo (r.left + 2, r.bottom);
00431     
00432     LineTo (r.left + 2, r.bottom - 1);
00433     
00434     LineTo (r.left, r.bottom - 1);
00435     
00436     LineTo (r.left, r.top);
00437     
00438     CloseRgn ((*peekptr).strucRgn);
00439     */
00440     } /* tracestrucrgn */
00441 
00442 
00443 static void docalc (
00444     WindowPeek peekptr) {
00445     
00446     Rect r;
00447     Rect rbounds;
00448     
00449     tyhdlwindrects hdlwindrects;
00450 
00451     HLock ((*peekptr).dataHandle);
00452     
00453     hdlwindrects = (tyhdlwindrects) (*peekptr).dataHandle;
00454     
00455     r = (*peekptr).port.portRect;
00456     
00457     if ((*peekptr).port.portBits.rowBytes > 0)
00458         rbounds = (*peekptr).port.portBits.bounds;
00459     else
00460         rbounds = (**(*(CGrafPtr) (peekptr)).portPixMap).bounds;
00461     
00462     OffsetRect (&r, - rbounds.left, - rbounds.top);
00463     
00464     RectRgn ((*peekptr).contRgn, &r);
00465     
00466     r.left = r.left - 1;
00467     
00468     r.top = r.top - kDragHeight;
00469     
00470     r.right = r.right + 1;
00471     
00472     r.bottom = r.bottom + 1;
00473     
00474     tracestrucrgn (peekptr, r);
00475     
00476     r.bottom = r.top + kDragHeight;
00477     
00478     (**hdlwindrects).dragrect = r;
00479     
00480     InsetRect (&r, 6, 2);
00481     
00482     r.right = r.left + kDragHeight - 4;
00483     
00484     (**hdlwindrects).closerect = r;
00485     
00486     HUnlock ((*peekptr).dataHandle);
00487     } /* docalc */
00488 
00489 
00490 static void dodraw (
00491     WindowPeek peekptr,
00492     short varcode,
00493     long param) {
00494     
00495     tyhdlwindrects hwindrects;
00496     Rect r;
00497     Pattern pat;
00498     
00499     if (!(*peekptr).visible)
00500         return;
00501     
00502     hwindrects = (tyhdlwindrects) (*peekptr).dataHandle;
00503     
00504     param = LoWord (param); /*TN #290*/
00505     
00506     if (param == 4) {
00507         HLock ((*peekptr).dataHandle);
00508         
00509         InvertRect (&(**hwindrects).closerect);
00510         
00511         HUnlock ((*peekptr).dataHandle);
00512         
00513         return;
00514         }
00515     
00516     if (param != 0)
00517         return;
00518         
00519     docalc (peekptr);
00520     
00521     filltitlebar (peekptr, varcode, (*peekptr).hilited);
00522     
00523     StuffHex ((Ptr) &pat, "\pFFFFFFFFFFFFFFFF");
00524     
00525     PenPat (pat);
00526         
00527     FrameRgn ((*peekptr).strucRgn);
00528     
00529     r = (**(*peekptr).strucRgn).rgnBBox;
00530     
00531     MoveTo (r.left, r.bottom - 2);
00532     
00533     LineTo (r.right - 2, r.bottom - 2);
00534     
00535     LineTo (r.right - 2, r.top);
00536     
00537     drawtitle ((WindowPtr) peekptr, (**hwindrects).dragrect);
00538     } /* dodraw */
00539 
00540 
00541 static void calcgrow (
00542     WindowPtr w,
00543     Rect *r) {
00544     
00545     WindowPtr currentport;  
00546     
00547     *r = (*w).portRect;
00548     
00549     (*r).top = (*r).bottom - 12;
00550     
00551     (*r).left = (*r).right - 12;
00552     
00553     (*r).bottom = (*r).bottom + 1;
00554     
00555     (*r).right = (*r).right + 1;
00556         
00557     GetPort (&currentport);
00558     
00559     SetPort (w);
00560     
00561     localtoglobalrect (r);
00562     
00563     SetPort (currentport);
00564     } /* calcgrow */
00565     
00566     
00567 static long dohit (
00568     WindowPeek peekptr, 
00569     short varcode,
00570     long param) {
00571 
00572     Point pt;
00573     tyhdlwindrects hwindrects;
00574     Rect r;
00575     
00576     docalc (peekptr);
00577 
00578     pt.h = LoWord (param);
00579     
00580     pt.v = HiWord (param);
00581 
00582     hwindrects = (tyhdlwindrects) (*peekptr).dataHandle;
00583 
00584     if (PtInRect (pt, &(**hwindrects).closerect))
00585         return (wInGoAway);
00586     
00587     if (PtInRect (pt, &(**hwindrects).dragrect)) 
00588         return (wInDrag);
00589         
00590     if (varcode != 2) {
00591         calcgrow ((WindowPtr) peekptr, &r);
00592         
00593         if (PtInRect (pt, &r))
00594             return (wInGrow);
00595         }
00596         
00597     if (PtInRgn (pt, (*peekptr).contRgn))
00598         return (wInContent);
00599 
00600     return (wNoHit);
00601     } /* dohit */
00602     
00603     
00604 static void dogrow (
00605     short varcode,
00606     long param) {
00607     
00608     typtrrect ptrrect;
00609     Rect r;
00610     
00611     if (varcode == 2)
00612         return;
00613         
00614     ptrrect = (typtrrect) param;
00615     
00616     r = *ptrrect;
00617     
00618     r.left = r.left - 1;
00619     
00620     r.top = r.top - kDragHeight;
00621     
00622     r.right = r.right + 2;
00623     
00624     r.bottom = r.bottom + 2;
00625             
00626     FrameRect (&r);
00627     
00628     MoveTo ((*ptrrect).right - 12, r.top + 1);
00629     
00630     LineTo ((*ptrrect).right - 12, r.bottom - 1);
00631     } /* dogrow */
00632 
00633 
00634 static void dodrawgrowicon (
00635     WindowPeek peekptr,
00636     short varcode) {
00637     
00638     Rect r;
00639     
00640     if (varcode == 2)
00641         return;
00642         
00643     calcgrow ((WindowPtr) peekptr, &r);
00644     
00645     SetPort ((WindowPtr) peekptr);
00646     
00647     globaltolocalrect (&r);
00648     
00649     PenNormal ();
00650     
00651     EraseRect (&r);
00652     
00653     FrameRect (&r);
00654     
00655     InsetRect (&r, 2, 2);
00656     
00657     r.top = r.top + 2;
00658     
00659     r.left = r.left + 2;
00660     
00661     FrameRect (&r);
00662     
00663     OffsetRect (&r, -2, -2);
00664     
00665     r.bottom = r.bottom - 1;
00666     
00667     r.right = r.right - 1;
00668     
00669     EraseRect (&r);
00670     
00671     FrameRect (&r);
00672     } /* dodrawgrowicon */
00673 
00674 
00675 static void donew (
00676     WindowPeek peekptr) {
00677     
00678     tyhdlwindrects hdlwindrects;
00679 
00680     (*peekptr).dataHandle = NewHandle (sizeof (tywindrects));
00681     
00682     hdlwindrects = (tyhdlwindrects) (*peekptr).dataHandle;
00683     
00684     docalc (peekptr);
00685     } /* donew */
00686     
00687 
00688 static void dodispose (
00689     WindowPeek peekptr) {
00690     
00691     tyhdlwindrects hdlwindrects;
00692 
00693     hdlwindrects = (tyhdlwindrects) (*peekptr).dataHandle;
00694     
00695     DisposHandle ((*peekptr).dataHandle);
00696     } /* dodispose */
00697 
00698 

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