appletcolorpopup.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletcolorpopup.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 /*
00008 written by Dave Shaver, Quark, 303-849-3311, adapted by DW 2/9/93.
00009 */
00010 
00011 #include "appletdefs.h"
00012 #include "appletquickdraw.h"
00013 #include "appletcursor.h"
00014 #include "appletmemory.h"
00015 #include "appletcolorpopup.h"
00016 
00017 
00018 #define mPopupMsg 3
00019 #define PATCHSIZE 8
00020 #define OUTSETSIZE 1
00021 #define ITEMSIZE (PATCHSIZE+OUTSETSIZE+1)
00022 CSpecArray *ctable;
00023 MenuHandle colormenu;
00024 
00025 
00026 static void getitemrect (short item, Rect *ritem) {
00027 
00028     short x, y;
00029     Rect r;
00030     
00031     item--;
00032     
00033     x = item % 32;
00034     
00035     y = item / 32;
00036     
00037     r.top = 1 + y * ITEMSIZE;
00038     
00039     r.left = 1 + x * ITEMSIZE;
00040     
00041     r.bottom = r.top + ITEMSIZE;
00042     
00043     r.right = r.left + ITEMSIZE;
00044     
00045     *ritem = r;
00046     } /*getitemrect*/
00047     
00048     
00049 static void frameitem (short item, Rect menurect) {
00050 
00051     Rect r;
00052     
00053     if (item <= 0)
00054         return;
00055         
00056     pushforecolor (&blackcolor);
00057     
00058     pushpen ();
00059         
00060     PenMode (patXor);
00061     
00062     getitemrect (item, &r);
00063     
00064     OffsetRect (&r, menurect.left, menurect.top);
00065     
00066     FrameRect (&r);
00067     
00068     poppen ();
00069     
00070     popforecolor ();
00071     } /*frameitem*/
00072     
00073     
00074 static void drawcolorpopup (Rect menurect) {
00075 
00076     short i, j;
00077     Rect r; 
00078     
00079     pushforecolor (&lightbluecolor);
00080     
00081     PaintRect (&menurect);
00082     
00083     for (i = 0; i < 8; i++) {
00084     
00085         for (j = 0; j < 32; j++) {
00086         
00087             getitemrect (i * 32 + j + 1, &r);
00088             
00089             OffsetRect (&r, menurect.left, menurect.top);
00090             
00091             RGBForeColor (&blackcolor);
00092             
00093             InsetRect (&r, 1, 1);
00094             
00095             PaintRect (&r);
00096             
00097             InsetRect (&r, 1, 1);
00098             
00099             RGBForeColor (&(*ctable) [i * 32 + j].rgb);
00100             
00101             PaintRect (&r);
00102             } /*for*/
00103         } /*for*/
00104     
00105     popforecolor ();
00106     } /*drawcolorpopup*/
00107 
00108 
00109 static pascal void colormenuhandler (short msg, MenuHandle hmenu, Rect *menurect, Point pt, short *item) {
00110     
00111     switch (msg) {
00112     
00113         case mDrawMsg: 
00114             drawcolorpopup (*menurect);
00115             
00116             break;
00117             
00118         case mChooseMsg: {
00119             short x;
00120             Rect rinset;
00121             
00122             rinset = *menurect;
00123             
00124             InsetRect (&rinset, OUTSETSIZE, OUTSETSIZE);
00125             
00126             if (!PtInRect (pt, &rinset)) 
00127                 x = 0;
00128             else {
00129                 x = 
00130                     32L * ((pt.v - (*menurect).top - OUTSETSIZE) / ITEMSIZE) +
00131                     (pt.h - (*menurect).left - OUTSETSIZE) / ITEMSIZE + 1;
00132                 
00133                 if (x < 0) 
00134                     x = 0;
00135                 }
00136                 
00137             if (*item == x) /*already highlighted*/
00138                 break;
00139                 
00140             frameitem (*item, *menurect); /*unhighlight the original item*/
00141         
00142             frameitem (x, *menurect); /*highlight the newly selected item*/
00143                 
00144             *item = x;
00145             
00146             break;
00147             }
00148             
00149         case mSizeMsg:
00150             (**hmenu).menuHeight = 8L * ITEMSIZE + 2;
00151             
00152             (**hmenu).menuWidth = 32L * ITEMSIZE + 2;
00153             
00154             break;
00155             
00156         case mPopupMsg:
00157             (*menurect).top = pt.h;
00158             
00159             (*menurect).right = pt.v;
00160             
00161             (*menurect).bottom = (*menurect).top + (**hmenu).menuHeight;
00162             
00163             (*menurect).left = (*menurect).right - (**hmenu).menuWidth;
00164             
00165             break;
00166         } /*switch*/
00167     } /*colormenuhandler*/
00168 
00169 
00170 static boolean flpopupinit = false;
00171 
00172 
00173 static boolean initcolorpopup (void) {
00174     
00175     CTabHandle syspal;
00176     Handle mdefh;
00177     
00178     if (!systemhascolor ()) 
00179         return (false);
00180         
00181     syspal = GetCTable (8);
00182     
00183     HLock ((Handle) syspal);
00184     
00185     ctable = &(**syspal).ctTable;
00186     
00187     mdefh = appnewhandle (6);
00188     
00189     *(short *)*mdefh = 0x4EF9;
00190     
00191     *(long *)(*mdefh + sizeof (short)) = (long) &colormenuhandler;
00192     
00193     colormenu = GetMenu (256); /*256 blank entries in this menu*/
00194     
00195     (**colormenu).menuProc = mdefh;
00196     
00197     CalcMenuSize (colormenu);
00198     
00199     /*create a picture, didn't make it faster, commented*/ {
00200     
00201         /*
00202         WindowPtr w;
00203         Rect r;
00204         
00205         w = GetNewCWindow (128, nil, (WindowPtr) -1);
00206         
00207         pushmacport (w);
00208         
00209         r.top = r.left = 0;
00210         
00211         r.bottom = (**colormenu).menuHeight;
00212         
00213         r.right = (**colormenu).menuWidth;
00214         
00215         ClipRect (&r);
00216         
00217         colorpopuppict = OpenPicture (&r);
00218         
00219         drawcolorpopup (r);
00220         
00221         ClosePicture ();
00222         
00223         popmacport ();
00224         
00225         DisposeWindow (w);
00226         */
00227         }
00228     
00229     return (true);
00230     } /*initcolorpopup*/
00231 
00232 
00233 boolean clickcolorpopup (Point pt, RGBColor *rgb) {
00234     
00235     long result;
00236     short lo, hi;
00237     
00238     if (!flpopupinit)
00239         flpopupinit = initcolorpopup ();
00240     
00241     setcursortype (cursorisarrow);
00242     
00243     CalcMenuSize (colormenu);
00244     
00245     InsertMenu (colormenu, hierMenu);
00246 
00247     LocalToGlobal (&pt);
00248     
00249     result = PopUpMenuSelect (colormenu, pt.v, pt.h, -1);
00250 
00251     DeleteMenu ((**colormenu).menuID);
00252     
00253     lo = LoWord (result);
00254     
00255     hi = HiWord (result);
00256     
00257     if (hi > 0) { /*something was selected*/
00258     
00259         *rgb = (*ctable) [lo - 1].rgb;
00260         
00261         return (true);
00262         }
00263     
00264     return (false);
00265     } /*clickcolorpopup*/
00266     
00267 

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