appletpalette.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletpalette.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "applet.h"
00008 
00009 
00010 #define drawinset 3
00011 #define ctperline 2
00012 #define heightpaletteicon (heightsmallicon + 6)
00013 #define widthpaletteicon (widthsmallicon + 6)
00014 #define breakpixels 4
00015 
00016 
00017 
00018 static void geticonrect (hdlpaletterecord hpal, short iconnum, Rect *ricon) {
00019     
00020     /*
00021     iconnum is 0-based.
00022     */
00023     
00024     Rect rpal = (**hpal).r;
00025     short extrapixels = 0;
00026     Rect r;
00027     short lnum, ixline;
00028     short i;
00029     
00030     lnum = 0;
00031     
00032     ixline = 0;
00033     
00034     for (i = 0; i < iconnum; i++) {
00035     
00036         if ((**hpal).item [i].breakafter) {
00037         
00038             extrapixels += breakpixels;
00039             
00040             ixline = 0;
00041             
00042             lnum++;
00043             }
00044         else {
00045             ixline++;
00046             
00047             if (ixline > (ctperline - 1)) {
00048                 
00049                 ixline = 0;
00050                 
00051                 lnum++;
00052                 }
00053             }
00054         } /*for*/
00055     
00056     r.top = rpal.top + drawinset + (lnum * (heightpaletteicon - 1)) + extrapixels;
00057     
00058     r.bottom = r.top + heightpaletteicon;
00059     
00060     r.left = rpal.left + drawinset;
00061     
00062     if (ixline % 2)
00063         r.left += widthpaletteicon - 1;
00064     
00065     r.right = r.left + widthpaletteicon;
00066     
00067     *ricon = r;
00068     } /*geticonrect*/
00069     
00070     
00071 void getpalettesize (hdlpaletterecord hpal, short *height, short *width) {
00072     
00073     /*
00074     called when zooming windows that contain palettes.
00075     */
00076     
00077     Rect rpal = (**hpal).r;
00078     Rect r;
00079     
00080     geticonrect (hpal, (**hpal).cticons, &r);
00081     
00082     *height = r.bottom - rpal.top + (4 * drawinset);
00083     
00084     *width = r.right - drawinset;
00085     } /*getpalettesize*/
00086     
00087 
00088 static void oldgeticonrect (hdlpaletterecord hpal, short iconnum, Rect *ricon) {
00089     
00090     /*
00091     iconnum is 0-based.
00092     */
00093     
00094     Rect rpal = (**hpal).r;
00095     short extrapixels = 0;
00096     Rect r;
00097     short lnum;
00098     short i;
00099     
00100     for (i = 0; i < iconnum; i++) {
00101     
00102         if ((**hpal).item [i].breakafter)
00103             extrapixels += breakpixels;
00104         } /*for*/
00105     
00106     lnum = (iconnum / ctperline);
00107     
00108     r.top = rpal.top + drawinset + (lnum * (heightpaletteicon - 1)) + extrapixels;
00109     
00110     r.bottom = r.top + heightpaletteicon;
00111     
00112     r.left = rpal.left + drawinset;
00113     
00114     if (iconnum % 2)
00115         r.left += widthpaletteicon - 1;
00116     
00117     r.right = r.left + widthpaletteicon;
00118     
00119     *ricon = r;
00120     } /*geticonrect*/
00121     
00122     
00123 hdlpaletterecord newpalette (WindowPtr macwindow, short cticons) {
00124 
00125     hdlpaletterecord hpal;
00126     
00127     if (!newclearhandle (longsizeof (typaletterecord), (Handle *) &hpal))
00128         return (nil);
00129     
00130     (**hpal).macwindow = macwindow;
00131     
00132     (**hpal).cticons = cticons;
00133     
00134     (**hpal).palettewidth = (2 * drawinset) + (2 * widthpaletteicon);
00135     
00136     return (hpal);
00137     } /*newpalette*/
00138     
00139     
00140 void disposepalette (hdlpaletterecord hpal) {
00141     
00142     disposehandle ((Handle) hpal);
00143     } /*disposepalette*/
00144     
00145     
00146 static void centersmallicon (Rect r, short iconlist, short iconnum, boolean flinvert) {
00147     
00148     r.top += (r.bottom - r.top - heightsmallicon) / 2;
00149     
00150     r.left += (r.right - r.left - widthsmallicon) / 2;
00151     
00152     plotsmallicon (r, iconlist, iconnum, flinvert);
00153     } /*centersmallicon*/
00154     
00155     
00156 void paletteupdate (hdlpaletterecord hpal) {
00157 
00158     boolean flbitmap = false;
00159     Rect r = (**hpal).r;
00160     short i;
00161     
00162     /*flbitmap = openbitmap (r, (**hpal).macwindow);*/
00163     
00164     pushbackcolor (&lightbluecolor);
00165         
00166     EraseRect (&r);
00167     
00168     MoveTo (r.right - 1, r.top);
00169     
00170     LineTo (r.right - 1, r.bottom);
00171     
00172     for (i = 0; i < (**hpal).cticons; i++) {
00173         
00174         geticonrect (hpal, i, &r);
00175         
00176         pushbackcolor (&whitecolor);
00177         
00178         EraseRect (&r);
00179         
00180         centersmallicon (r, (**hpal).sicnresource, i, false);
00181         
00182         popbackcolor ();
00183         
00184         FrameRect (&r);
00185         
00186         if ((**hpal).item [i].selected) {
00187             
00188             InsetRect (&r, 2, 2);
00189             
00190             InvertRect (&r);
00191             }
00192         } /*for*/
00193     
00194     popbackcolor ();
00195         
00196     if (flbitmap)
00197         closebitmap ((**hpal).macwindow);
00198     } /*updatepalette*/
00199     
00200     
00201 void invalpalette (hdlpaletterecord hpal) {
00202     
00203     InvalRect (&(**hpal).r);
00204     } /*invalpalette*/
00205     
00206     
00207 void invalpaletteitem (hdlpaletterecord hpal, short itemnum) {
00208     
00209     Rect r;
00210     
00211     geticonrect (hpal, itemnum, &r);
00212         
00213     InvalRect (&r);
00214     } /*invalpaletteitem*/
00215     
00216     
00217 void palettemousedown (hdlpaletterecord hpal) {
00218     
00219     Rect rpalette = (**hpal).r;
00220     short i;
00221     
00222     for (i = 0; i < (**hpal).cticons; i++) {
00223     
00224         Rect r;
00225         
00226         geticonrect (hpal, i, &r);
00227         
00228         if (PtInRect (mousestatus.localpt, &r)) {
00229             
00230             (**hpal).itemselected = i;
00231             
00232             (*(**hpal).itemhitcallback) ();
00233             }
00234         } /*for*/
00235     
00236     /*invalpalette (hpal);*/
00237     } /*palettemousedown*/
00238     
00239     
00240 void paletteactivate (hdlpaletterecord hpal, boolean flactivate) {
00241     } /*paletteactivate*/
00242     
00243 
00244 void paletteselectitem (hdlpaletterecord hpal, short itemnum) {
00245     
00246     short i;
00247     
00248     for (i = 0; i < maxpaletteitems; i++) {
00249         
00250         if ((**hpal).item [i].selected)
00251             invalpaletteitem (hpal, i);
00252             
00253         (**hpal).item [i].selected = false;
00254         } /*for*/
00255         
00256     if (!(**hpal).item [itemnum].selected)
00257         invalpaletteitem (hpal, itemnum);
00258         
00259     (**hpal).item [itemnum].selected = true;
00260     
00261     /*invalpalette (hpal);*/
00262     } /*paletteselectitem*/
00263     
00264     
00265     

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