appletfilelabel.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletfilelabel.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 #include "appletbits.h"
00009 #include "appletfilesinternal.h"
00010 #include "appletfilelabel.h"
00011 #include <Icons.h>
00012 
00013 
00014 
00015 
00016 typedef struct tylabelinfo {
00017     
00018     hdlstring hstring;
00019     
00020     RGBColor rgb;
00021     } tylabelinfo;
00022     
00023 #define ctlabels 8
00024     
00025 static tylabelinfo labelcache [ctlabels];
00026 
00027 static boolean needinit = true;
00028 
00029 
00030 boolean filegetlabelinfo (short ixlabel, RGBColor *rgb, bigstring bslabel) {
00031     
00032     if (needinit) {
00033         
00034         short i;
00035         
00036         needinit = false;
00037         
00038         clearbytes (&labelcache, longsizeof (labelcache));
00039         
00040         for (i = 0; i < ctlabels; i++) {
00041             
00042             OSErr ec;
00043             RGBColor rgb;
00044             bigstring bs;
00045             
00046             ec = GetLabel (i, &rgb, bs);
00047             
00048             if (ec == noErr) {
00049                 
00050                 newheapstring (bs, &labelcache [i].hstring);
00051                 
00052                 labelcache [i].rgb = rgb;
00053                 }
00054             } /*for*/
00055         }
00056     
00057     /*get the string and rgb from the label cache*/ {
00058         
00059         hdlstring hstring = labelcache [ixlabel].hstring;
00060         
00061         if (hstring == nil)
00062             return (false);
00063             
00064         *rgb = labelcache [ixlabel].rgb;
00065         
00066         copyheapstring (hstring, bslabel);
00067         
00068         return (true);
00069         }
00070     } /*filegetlabelinfo*/
00071     
00072     
00073 static boolean label2index (bigstring bslabel, short *ixlabel) {
00074     
00075     short i;
00076     bigstring bs;
00077     RGBColor rgb;
00078     
00079     for (i = 0; i < 8; i++) {
00080         
00081         filegetlabelinfo (i, &rgb, bs);
00082         
00083         if (equalstrings (bs, bslabel)) {
00084             
00085             *ixlabel = i;
00086             
00087             return (true);
00088             }
00089         } /*for*/
00090         
00091     return (false);
00092     } /*label2index*/
00093 
00094 
00095 boolean filesetlabel (ptrfilespec pfs, short ixlabel) {
00096     
00097     CInfoPBRec pb;
00098     
00099     if (!getmacfileinfo (pfs, &pb))
00100         return (false);
00101         
00102     pb.hFileInfo.ioFlFndrInfo.fdFlags &= 0xFFF1; /*clear out old index*/
00103     
00104     pb.hFileInfo.ioFlFndrInfo.fdFlags |= ixlabel << 1; /*slam in new index*/
00105     
00106     return (setmacfileinfo (pfs, &pb));
00107     } /*filesetlabel*/
00108 
00109 
00110 
00111 

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